Shlomi Fish wrote: > > [ 0 ] = 0 > > [ 1 ] = 1 > > [ 0, 1 ] = 1 > > [ 1, 1 ] = 2 > > [ 1, [ 1, 2 ] ] = -2 > > [ 1, 2, [ 8 ] ] = -5 > > [ 1, [ 2 ], [ 3 ] ] = -4 > > [ 9, [ 3, 4, [ [ 2 ] ] ] ] = 0 > > ... > > > > I know how to implement arrays that contain array references (in case that's > what you want) but I don't understand the logic behind this puzzle. Please > detail its inner logic.
>From what I can tell it's quite simple - the outer most brackets do nothing (or implies addition of the numbers within, unless we take the coma as the '+' sign), every inner set of brackets adds '-' before the number (well, negative actually) so it looks like this: ... [ 1, [ 1, 2 ] ] = -2 is ( 1 + - ( 1 + 2 ) = 1 - 3 = -2 ... [ 9, [ 3, 4 [ [ 2 ] ] ] ] is ( 9 + - ( 3 + 4 - (- 2))) = 9 - ( 7 + 2) = 9 - 9 = 0 and so on and so forth. Cheers, Raf -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/