Re: A Puzzle in Eu -- what would you do?

new topic     » goto parent     » topic index » view thread      » older message » newer message

OK, I'll bite since I don't mind being ridiculed if it comes to that :)

I had to do this for a program already and here's what I did only I've 
modified it cosmetically to remove the swear word I had in the comments. :)

function munch(sequence delimiter, object string)

	integer delimiterpos
	sequence result
	result = {}

	delimiterpos = match(delimiter,string)
	while delimiterpos != 0 do

		result = append(result,string[1..delimiterpos - 1])
		string = string[delimiterpos + length(delimiter)..length(string)]
	        delimiterpos = match(delimiter,string)
		if equal(delimiterpos,0) then

			result = append(result,string) --last field
		end if
	end while

	return result
end function

So, I would take your line and do something like this with it:

sequence whatitis

whatitis = line
whatitis = munch(whatitis)
for i = 1 to length(whatitis) do
--do something really fancy to figure what the chunks you got back 
--really are relying on some kind of logic that's bound to fail :)
end for

So I hope I read the puzzle right.  You're not asking me to figure out
one is the real comment, just to make sure it gets picked up.  And the
routine is generic because the programmer supplies the delimiter.  The
only code I added for this puzzle it the part about adding the length of
the delimiter.  I used to assume a length of 1, but this way it's even 
more generic.

If that's the right word.

And if it isn't who cares? :)

So let the ridicule begin :) :D

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu