Quiz! Was: Re: New functions: input() and reverse() -Reply

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

>>> "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> 10/20/98 07:50am
>>>
i) Give the semantic difference between the following two subroutines.

One is self-referential (?) not sure what you want here...

ii) Give the contents of X and Y at the end of the program.

X: {4,6,2,6,{3,2,{3,8},4},9,7,9,{1,5,9,2,{6,5},3,5,8},4,1,3}
Y: {4,6,2,6,4,8,3,2,3,9,7,9,8,5,3,5,6,2,9,5,1,4,1,3}
(excuse any typos)

iii) Which function is more correct? (In your opinion) Discuss.
     [I hate "Discuss" questions >:^> ]

This reminds me of one of Hofstadter's essays in GEB.  Given that we
tend to think (aside from Eu's data structures) of a sequence as a list
of single depth (i.e. not containing other sequences), I feel that
intuitively, the first subroutine is more "correct".  This subroutine simply
reverses the order of items in a list, without regards to the type of item it
is.  The second however, as it recursively descends into its argument,
effectively reverses everything.  I can imagine the sequence
{"one","two","three"} being turned into {"eerht","owt","eno"} using an
algorithm of this sort - Not (at least to me) what someone would want if
calling reverse on that sequence...
Additionally, the recursive function flattens the sequence, which I
assume is NOT what you were originally intending blink

iv) BONUS question. Where have I got the "Start" numbers from? :)

pi

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

Search



Quick Links

User menu

Not signed in.

Misc Menu