Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Joachim Tuchel
So I guess that floor > 0 is your condition, right? In Smalltalk, the idea is that you evaluate the condition and ask the result of it (usually true or false) to do something. Right so far? That would mean the receiver of your wanted message is either the result of the evaluation or or a Block

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Tim Mackinnon
To add to what Joachim has said, and to help you help yourself, look at what methods are implemented in BlockClosure and Boolean and see how things work (the code is there for you to understand it quite easily - there is little magic going on). You can find all kinds of interesting and helpful t

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Ben Coman
On Fri, 9 Nov 2018 at 15:25, Roelof Wobben wrote: > Hello, > > I try to solve a adventofcode challenge where I must find out when santa > is first at the basement. the floor is there -1. > So I thought I use a while loop like this : > > santaFloorOnBasement > "calculates which step take Sant

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Roelof Wobben
Thanks all. This code seems to do the job santaFloorOnBasement     "calculates which step take Santa to the basement" | index| index := 1.  [floor ~= -1 ] whileTrue:      [ floor := ((input at: index) = '(' )

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Peter Uhnak
On Fri, Nov 9, 2018 at 1:26 PM Roelof Wobben wrote: > Thanks all. > > This code seems to do the job > > santaFloorOnBasement > "calculates which step take Santa to the basement" > | index| > index := 1. > [floor ~= -1 ] whileTrue: > [ floor := ((input at: index) = '(' )

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Roelof Wobben
Op 9-11-2018 om 16:44 schreef Peter Uhnak: On Fri, Nov 9, 2018 at 1:26 PM Roelof Wobben wrote: Thanks all.

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Roelof Wobben
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 detec

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Gabriel Cotelli
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 wrote: > hmm. > > When I try this on P7 > > |input stepChanges floor| > input := '((('. > floor := 0. > stepChan

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Alistair Grant
On Fri, 9 Nov 2018 at 18:38, Gabriel Cotelli 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 Strings store characters, not integers, so change your example to: 'aa' collect: [ :a | $1 ] and

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Peter Uhnak
> > 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:

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Alistair Grant
Hi Peter, On Fri, 9 Nov 2018 at 18:51, Peter Uhnak 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" >

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Alistair Grant
Hi Peter, On Fri, 9 Nov 2018 at 19:00, Alistair Grant wrote: > > Hi Peter, > > On Fri, 9 Nov 2018 at 18:51, Peter Uhnak 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 >

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Roelof Wobben
oke, I see , I thought earlier that stepChanges was a function but its a variable Roelof Op 9-11-2018 om 18:50 schreef Peter Uhnak: but how do I find now the answer do I have to do something like  

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Roelof Wobben
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 whe

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Roelof Wobben
Given up for today I have this : calculateFloors | stepChanges floor| floor := 0. stepChanges := input asArray collect: [ :c | floor := floor+ (c = $( ifTrue: [ 1 ] ifFalse: [ -1 ]). ]. floors addFloor: floor. but now I see this error message : temp values not written or read. floors and inpu

Re: [Pharo-users] what must be instead of the ??

2018-11-09 Thread Richard O'Keefe
We are talking to a beginner here. One of the important things for a beginner to understand is the idea of hiding stuff and thinking in terms of asking objects to do things for you. For example, in Java you historically did final int n = aString.length(); for (int i = 0; i < n; i++) {