String manipulation etc
https://paste.mod.gg/qiqfbdvjrwru/0
I have this task:
Print to the file ManoKnyga.txt a merged text, composed according to the following rules:
Text from the first file is copied until the first non-copied word from the second file is encountered, or the end of the file is reached;
Text from the second file is copied until the first non-copied word from the first file is encountered, or the end of the file is reached;
This is repeated until the end of both files is reached.
The issue I'm facing with the code I have is that the method does not output the correct results. It has to check each word from each file simultaneously line by line to see check wether the word in one file matches another, if it does then the code has to be appended from the 2nd file and vice versa, until the end of both files is reached.
BlazeBin - qiqfbdvjrwru
A tool for sharing your source code with the world!
105 Replies
Here are the data and output files:
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
school
why?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
in a few days
thursday to be axact
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I did try that but still could't find the issue
in the logic
I'm using VS btw
these nested conditions are suspicious to me

though I could be misreading.
If you had to describe your plan / algorithm in words, what would it be?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
The thing I'm trying to do I guess is check word by word from each file, and copy everything from the first file until the word in the first file matches with the word in the second file
then it should start copying data from the second file onwards until it matches with the word from the first file
if that's understandable
a little but I don't fully understand which word "the word in the second file" refers to -- any word in the second file not yet copied? any word on the next not-yet-copied line?
Idek how to better explain it like if there is word that is not yet coppied in the 2nd file and it equals to a word that's in the first file anywhere in the text if it is not located in the first line and vice versa
you said here is data and output
your output does not match what you're describing
its literally copying file A then file B
to the output
well yeah it does that incorrectly
it should not
ok then can you provide a correct output
I wanna fix exactly that
that would help us understand it
with this code exactly I literally get no output
manually writing the output
it just keeps loading and loading nothing happens
in a sec
Basically, take the green parts, if I'm not mistaken

Saulė patekėjo anksti, o dangus buvo be debesų. Paukščiai čiulbėjo garsiai; oras buvo šiltas ir gaivus.
Ant kalno stovėjo sena pilis, kurios langai spindėjo ryto šviesoje. Žmonės miestelyje ruošėsi šventei – visi buvo gerai nusiteikę.
Biblioteka atsidarė anksti, ir studentai skubėjo į paskaitas. Profesorius pasakojo apie matematiką ir istoriją.
Keliautojas aplankė muziejų, kur eksponatai buvo įdomūs. Architektas projektavo naują pastatą miesto centre. Ryte dangus buvo mėlynas, o saulė švietė virš kalno. Pilis atrodė išdidžiai ir tyliai stebėjo miestelį.
Vėjas pūtė švelniai; medžių lapai šnarėjo tarsi jūra. Visi laukė šventės pradžios – oras buvo kupinas džiaugsmo.
Biblioteka buvo pilna studentų, kurie mokėsi matematiką. Profesorius dėstė apie architektūrą ir istoriją mieste.
Keliautojas fotografavo eksponatai muziejuje buvo įspūdingi. Architektas pristatė projektą komisijai vakar vakare.
like that basically
so that would be the output?
this looks about right too
that's the output I guess
I pasted it in
so you are checking file b for the first letter of file a
u found it
you start writing to output
so you wrote file a to end
Text from the first file is copied until the first non-copied word from the second file is encountered, or the end of the file is reached;
the task says this
I do not even know what does the first non copied word mean
but I believe I should copy data from the first file into the the new stringbuilder
until I find the matching word then everything switches copying starts from the 2nd file and vice versa until the end is reached
yeah this is hard to understand what is it written in your own language? first non-copied word
I believe I was trying to do that
because I understand that as copy file A until u find a word that matches
yes
that's exactly it
then everything switches
then u go to file b until the same happens
yes
that's right
if so your output is wrong again
yeah I just saw that
Saulė exists in file b so I should not copy it
and move to file b
Ryte does not exist in file a
so that would be the first word in your output
I believe the first switch should happen when it reaches "o" the first letter o in the file b
like this is coppied "Saulė patekėjo anksti,"
then it encounters letter o
and there is one exactly like that almost at the start of file b
I believe from that point on it should copy from the file b
that doesnt make sense so you're saying you dont look up file b for the word saule.
o is not aligned with o in file b
so if u're going word by word they are not in the same index to match
"o" would fall under "melynas"
maybe @ZZZZZZZZZZZZZZZZZZZZZZZZZ understood it better and could explain
@Buhalter if you can post the requirements in your language the way your teacher asked might help us translate it.
In a sec
Spausdinkite faile ManoKnyga.txt apjungtą tekstą, sudarytą pagal tokias taisykles:
• kopijuojamas pirmojo failo tekstas tol, kol sutinkamas pirmasis nenukopijuotas antrojo failo žodis
arba pasiekiama failo pabaiga;
• kopijuojamas antrojo failo tekstas tol, kol sutinkamas pirmasis nenukopijuotas pirmojo failo žodis
arba pasiekiama failo pabaiga;
• kartojama tol, kol pasiekiama abiejų failų pabaiga.
this is in my language
claude interprets this as "any not-yet-copied word from the other file", not as "the next-up word from the other file" fwiw
https://claude.ai/share/39056638-f43d-4017-9b28-001d59027d75
Lithuanian text file merging assignment
Shared via Claude, an AI assistant from Anthropic
though this "the first" business is evil in the literal translation imo lmao
Lol
I'm going to see if I can solve this, then I'll see if I can figure what's wrong with yours. I actually don't see the bug right now, and I've been staring at this for a bit
I appreciate that a lot
I hope it's gonna take a chunk out of your time
is a fun brainteaser now, don't worry :P
oh! maybe this
as far as I can tell, this'll never advance file 2 if we get a line back for file 1
because
I can't read I interpreted that as OR
&& will short-circuit (that means, when the left hand side evaluates to true, the right hand side doesn't get evaluated, because its result won't affect the result of the AND expression)Oh I see
ignore me ignore me. Everything I said was right, only if you replace "and" with "or" lmfao
ok ok I believe the issue is with the logic later on I just couldn't fathom where
for me yeah it seems ok but to someone more experienced it will definetly be visible
oh, for starters, should this be Append-ing from
line? I think that should read from words, no?
since i and j are words/words2 indexesI would like to think u want to ReadAllText and then do some removal of punctuation -,;.! and then make everything lower case and split on space, newline to get all words
otherwise u would need to add further checks
I was considering the output something like this
But honestly the translation is not being very helpful.
but it would miss out on the punctuation and things no?
Oh, if you need that, then you need a different strategy, yes
I also wanna mention that I must read line by line
to get the maximum points for this task
with your current approach (if not doing what leo said), you'd need to track the file character position separately from the word position
well that sounds complicated
so in addition to i, j for word position, you'd track a x, y for character position
if u dont @Buhalter then "matematiką." and "matematiką" wont match
hrm... a non-buffered line by line interpretation of this problem is impossible if the instructions truly meant "any non-copied word" and not "the next non-copied" word...
what if we overlooked the punctuation and just coppied the words?
would it be possible then?
still impossible for what I'm referring to
the way its asking u, if its right in the translation, it forces u to loop it multiple times
so u can do it as u read lines
Like, if the instrutions do want us to switch based on any word not yet copied from future lines, we need to be aware of those lines already
u would have to read the lines into a list
I guess that could work by reading it into a list
which might mean the translation was inaccurate
cuz technically we still are reading line by line
yeah u would sanitize and read it into a list of words from the file however u want
if this is a simple duple for
then what u want would work out of the box
but the way its being ask doesn't align
the thing with the translation this is the correct one even when I read it in my own language
ah, hm.
It could be a confused professor?
if we had a proper output to compare to
idk lol
it can lmao
then we could reverse it to understand it
I will inquire about this task on monday but right now this is all I got tbh
I would imagine 3 loops one outer loop controlling which words lists you're checking
and 2 inner loops running check what has been copied from the 2nd file vs not.
so 3 loops total
some hashes storing words from each list of what has been copied or not
and then u check the copied words and the list of words before advancing
and as need u break out of the loop/swap file being read
that is assuming my output is right
which I dont know honestly
👆
Like at the moment we can only guess
some times teachers will write requirements in a more cryptic manner to get u to thinker about it
and literal translation wont be able to pick that up
and the translation is lost
when he explained he used just numbers for instance file a: 1 2 3 4 5 6 file b: 4 7 8 9 and the output would be : 1 2 3 4(maybe idk) 7 8 9
And I had to get it from there
which doesn't make sense now
what do to with the four
My best guess is that we have to track somehow which are coppied in a hash or a list because we don't quite use hashes I don't even know how to use them and the concept of them
Isn't it just as simple as a loop, a boolean keeping track of whether we're copying from file 1 or 2, and... that's it?
Split file text on spaces to get words
Loop
If
strOne[i] is the same as strTwo[i] flip the bool
If bool is true copy from strOne, if false copy from strTwoI was trying to do that
at minimum, 2 different indexes there, if I'm understanding correctly
Why?
You're iterating through both at the same time
why do you assume that the word position is synced?
and based on the "current" word you'll pick up from the last file pointer position?
Ah
True
I mean at the very least I dont see yet how the numbers are in play here
I understand it jumping 5 and 6 and taking 7 8 9
but I dont understand how it picks up 4 and leaves 1 2 3
o is not in sync for it to swap there
but does it have to be?
I don't get it
Oh I see how that works
otherwise I dont see how what u said make sense here
file b: 4 7 8 9 Numbers are stand-ins for words
either u misunderstood something or
I could've I definetly could have
if u see the table I wrote above with numbers above the words
the first set is file a
second set is file b
file a:
cat dog parrot bread chair cucumber
file b: bread table slug window
Result: cat dog parrot bread table slug windowI was thinking like that
but I could not be sure
It copies until it sees the matching word
and then copie sfrom file b
yes that would make sense and then swaps
like in this one no?
that's why I said this
leowest
some times teachers will write requirements in a more cryptic manner to get u to thinker about it
Quoted by
<@1102729783969861782> from #String manipulation etc (click here)
React with ❌ to remove this embed.
and translation there is lost
this mostly matches what I suspect, I think we need to switch back at EOF though
(whether the matched word is supposed to be duplicated or not, I haven't the faintest clue)
(this ^ also does not make sense with a "process this line-by-line" instruction)
The matched word is duplicated, so whether we copy it from str1 or str2 doesn't matter ¯\_(ツ)_/¯
oh, I suppose so
I just wasn't sure if they wanted both pointers advanced for the matched word
you would need just something to tell when to stop matching and complete with a or b because either run out of words
usually wouldn't code-drop on an assignment, but I despise ambiguous instructions -- here's what I've been using to debug your code, if it helps -- I at least stopped the infinite loops. It still switches on "next word" not "any upcoming word" though
I also switched to StringReader because I wanted the example text in the same file, but no reason for you to do that