hmm, got a idea

I could use this part :

|input floor stepChanges|
input := '))((((('.
floor := 0.
stepChanges := input asArray collect: [ :c |
floor := floor + (c = $( ifTrue: [ 1 ] ifFalse: [ -1 ]).
 ].


two times if the outcome would be a collection.
The challenge is 2 parts.

1) find out where santa stops. that would be the last number in the collection.. 2) find out when santa enters the basement. That could be the function that is mentioned here.

Time to experiment with this idea.

Roelof


Op 9-11-2018 om 19:13 schreef Alistair Grant:
Hi Peter,

On Fri, 9 Nov 2018 at 19:00, Alistair Grant <akgrant0...@gmail.com> wrote:
Hi Peter,

On Fri, 9 Nov 2018 at 18:51, Peter Uhnak <i.uh...@gmail.com> wrote:
but how do I find now the answer do I have to do something like   puzzle1  
stepChanges detectIndex ?

How do you mean? It would be the same

santaFloorOnBasement
     "calculates which step take Santa to the basement"

     stepChanges := input collect: [ :c |
floor := floor + (c = '(' ifTrue: [ 1 ] ifFalse: [ -1 ]).
floor
     ].

     stepChanges detectIndex: [ :each | each = -1 ] ifNone: [ 'invalid input 
yo' ].

then I see this error message :  Improper store to indexable object.

Because earlier you were comparing strings and not characters, I assumed your input 
was an array of strings like #('(' '(' '('). but you can fix that by changing `input 
collect:` -> `input asArray collect:` and `c = '('` -> `c = $(`.
Using '(' instead of $( is indeed an error, but it isn't the cause of
the Improper store error.
I was too quick to respond here, I didn't look at the #asArray.  Sorry!

But still suggest Roelof looks at the debugger...

Roelof, I really suggest you trigger this error again, start the
debugger and then take a look in the call stack (I'm assuming you're
familiar with at least one other programming language, so should be
able to figure out the debugger).
Cheers,
Alistair




Reply via email to