--- Begin Message ---
Hello,

Im still trying to make part1 of day2 working at a way I can also test things. the tests are working but when I call on the class side the method which should reed the masses which are on the instanc side , the masses cannnot be found.

So question 1 is why is masses not found.

and question 2  is how can I use the changed array at the process method so I can calculate the outcome.

Regards,

Roelof

'From Pharo8.0.0 of 26 December 2019 [Build information: 
Pharo-8.0.0+build.1095.sha.a3829b06f0bc488adf52053b1dd7a5f0a2c6c499 (64 Bit)] 
on 31 December 2019 at 11:56:11.318362 am'!
Object subclass: #IntComputer
        instanceVariableNames: 'ram in'
        classVariableNames: ''
        package: 'AOC 2019'!

!IntComputer methodsFor: 'accessing' stamp: 'RoelofWobben 12/28/2019 08:36'!
in
        ^ in! !

!IntComputer methodsFor: 'accessing' stamp: 'RoelofWobben 12/28/2019 08:36'!
ram: anObject
        ram := anObject! !

!IntComputer methodsFor: 'accessing' stamp: 'RoelofWobben 12/28/2019 08:38'!
in: anObject
        in := anObject! !

!IntComputer methodsFor: 'accessing' stamp: 'RoelofWobben 12/28/2019 08:36'!
ram
        ^ ram! !


!IntComputer methodsFor: 'calculations' stamp: 'RoelofWobben 12/29/2019 18:18'!
masses
   ^  
'1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,6,19,1,19,5,23,2,13,23,27,1,10,27,31,2,6,31,35,1,9,35,39,2,10,39,43,1,43,9,47,1,47,9,51,2,10,51,55,1,55,9,59,1,59,5,63,1,63,6,67,2,6,67,71,2,10,71,75,1,75,5,79,1,9,79,83,2,83,10,87,1,87,6,91,1,13,91,95,2,10,95,99,1,99,6,103,2,13,103,107,1,107,2,111,1,111,9,0,99,2,14,0,0
 '! !


!IntComputer methodsFor: 'processing' stamp: 'RoelofWobben 12/29/2019 13:23'!
processData: anArray
        | op |
        in := ReadStream on: ram.
        [ (op := in next) = 99 ] whileFalse: [ self processOpcode: op ].
        ^ self at: 0! !

!IntComputer methodsFor: 'processing' stamp: 'RoelofWobben 12/29/2019 13:24'!
processData
        | op |
        in := ReadStream on: ram.
        [ (op := in next) = 99 ] whileFalse: [ self processOpcode: op ].
        ^ self at: 0! !

!IntComputer methodsFor: 'processing' stamp: 'RoelofWobben 12/29/2019 13:25'!
readRam: anArray
  ram := (anArray splitOn: ',') collect: [ :ea | ea asInteger ].! !

!IntComputer methodsFor: 'processing' stamp: 'RoelofWobben 12/29/2019 18:15'!
patchRam: position value: value
        self at: position put: value 
        ! !


!IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:33'!
at: idx
        ^ram at: idx + 1! !

!IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:35'!
at: idx put: value 
   ^  ram at: idx +1  put: value! !

!IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:31'!
processMultiply
        | a b c |
        a := self at: in next.
        b := self at: in next.
        self at: in next put: a*b! !

!IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:32'!
processAdd
        | a b|
        a := self at: in next.
        b := self at: in next.
        self at: in next put: a + b! !

!IntComputer methodsFor: 'running' stamp: 'RoelofWobben 12/28/2019 08:31'!
processOpcode: op 

        op = 1 ifTrue: [ ^self processAdd ].
        op = 2 ifTrue: [ ^self processMultiply ].! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

IntComputer class
        instanceVariableNames: 'masses'!

!IntComputer class methodsFor: 'as yet unclassified' stamp: 'RoelofWobben 
12/29/2019 19:39'!
solution
        | computer ram |
        computer := self new.
        computer readRam: masses.
        computer patchRam: 1 value: 12.
        computer patchRam: 2 value: 2.
        computer processData: ram. 
        computer at: 0! !

--- End Message ---

Reply via email to