> > 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 = $(`. I have thought of something but I found it wierd that you do steps when you > have already the answer. That is indeed true, personally I would decide based on how often the method is called and how large the input is. Because this cumulative change makes it much easier to debug any issues... and usually I prefer debuggability over performance (unless it is an actual bottleneck). Peter On Fri, Nov 9, 2018 at 6:38 PM Gabriel Cotelli <g.cote...@gmail.com> wrote: > It's bug in the collect: implementation used in String. I've opened > https://pharo.fogbugz.com/f/cases/22652/collect-over-Strings-is-broken > > On Fri, Nov 9, 2018 at 2:17 PM Roelof Wobben <r.wob...@home.nl> wrote: > >> hmm. >> >> When I try this on P7 >> >> |input stepChanges floor| >> input := '((('. >> floor := 0. >> 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. >> >> Roelof >> >> >> Op 9-11-2018 om 17:39 schreef Roelof Wobben: >> >> stepChanges := input collect: [ :c | >> floor := floor + (c = '(' ifTrue: [ 1 ] ifFalse: [ -1 ]). >> floor >> ]. >> >> stepChanges detectIndex: [ :each | each = -1 ] ifNone: [ 'invalid input >> yo' ]. >> >> >>