Hello,
Im thinking how to solve this one : https://github.com/exercism/problem-specifications/blob/master/exercises/bowling/description.md so I thought because you throw two times for a frame to solve it like this : aCollection withIndexDo: [:index :item | (if spare) ifTrue: take 3 items out of the score collection and sum them up (if strike) ifTrue: take 4 items out of the score collection and sum them up. (if not a spare and not a strike) : ifTrue: take 2 items out of the score collection and sum them up. index := index + 2 // because a frame is always two times a throw Now I wonder if this is a valid smalltalk to do this Roelof |
You wrote: "a frame is always two times a throw"
but the specification says "A frame is composed of one or two ball throws" and later we learn that the 10th frame may have three throws. There is an issue with your Smalltalk. aCollection withIndexDo: [:index :item | "You have the arguments in the wrong order. It is :item then :index" ... index := index + 2 "this is not legal"]. The assignment is not legal because you are not allowed to assign to method parameters or block parameters. You're going to have something like this: game := BowlingGame new. ... game roll: nPins. score := game score. Since the score of a strike or a spare depends on the scores of the *next* two throws, it might be easier to process the throws backwards. On Sat, 13 Apr 2019 at 04:32, Roelof Wobben <[hidden email]> wrote: > > Hello, > > Im thinking how to solve this one : > https://github.com/exercism/problem-specifications/blob/master/exercises/bowling/description.md > > so I thought because you throw two times for a frame to solve it like > this : > > > aCollection withIndexDo: [:index :item | > (if spare) ifTrue: take 3 items out of the score collection and sum > them up > (if strike) ifTrue: take 4 items out of the score collection and sum > them up. > (if not a spare and not a strike) : ifTrue: take 2 items out of the > score collection and sum them up. > index := index + 2 // because a frame is always two times a throw > > > Now I wonder if this is a valid smalltalk to do this > > Roelof > > |
Hello Richard,
I do it afterwards the input looks like this : #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 3 7). and I solved it already like this : scoreAfterRolling: aCollection | score | score := 0. 1 to: aCollection size - 1 by: 2 do: [ :index | score := (aCollection at: index) = 10 ifTrue: [ score + 10 + (aCollection at: index + 1) + aCollection at: index + 2 ] ifFalse: [ (aCollection at: index) + (aCollection at: index + 1) = 10 ifTrue: [ score + 10 + aCollection at: index + 2 ] ifFalse: [ score + (aCollection at: index) + (aCollection at: index + 1) ] ] ]. ^ score but the problem I facing now that I see when someone throws a strike I do not need a step of 2 but a step of 1 I tried to make a custom step variable but that did not do the job. So right now thinking how to get out of this Roelof Op 13-4-2019 om 11:37 schreef Richard O'Keefe:
|
Free forum by Nabble | Edit this page |