--- Begin Message ---
Oke
Maybe it is better to give the whole challenge
On the way to your gravity assist around the Moon, your ship computer beeps angrily about a "1202 program alarm". On the radio, an Elf is already explaining how to handle the situation: "Don't worry, that's perfectly norma--" The ship computer bursts into flames.
You notify the Elves that the computer's magic smoke seems to have escaped. "That computer ran Intcode programs like the gravity assist program it was working on; surely there are enough spare parts up there to build a new Intcode computer!"
An Intcode program is a list of integers separated by commas (like
1,0,0,3,99
). To run one, start by looking at the first integer (called position0
). Here, you will find an opcode - either1
,2
, or99
. The opcode indicates what to do; for example,99
means that the program is finished and should immediately halt. Encountering an unknown opcode means something went wrong.Opcode
1
adds together numbers read from two positions and stores the result in a third position. The three integers immediately after the opcode tell you these three positions - the first two indicate the positions from which you should read the input values, and the third indicates the position at which the output should be stored.For example, if your Intcode computer encounters
1,10,20,30
, it should read the values at positions10
and20
, add those values, and then overwrite the value at position30
with their sum.Opcode
2
works exactly like opcode1
, except it multiplies the two inputs instead of adding them. Again, the three integers after the opcode indicate where the inputs and outputs are, not their values.Once you're done processing an opcode, move to the next one by stepping forward
4
positions.For example, suppose you have the following program:
1,9,10,3,2,3,11,0,99,30,40,50
For the purposes of illustration, here is the same program split into multiple lines:
1,9,10,3, 2,3,11,0, 99, 30,40,50
The first four integers,
1,9,10,3
, are at positions0
,1
,2
, and3
. Together, they represent the first opcode (1
, addition), the positions of the two inputs (9
and10
), and the position of the output (3
). To handle this opcode, you first need to get the values at the input positions: position9
contains30
, and position10
contains40
. Add these numbers together to get70
. Then, store this value at the output position; here, the output position (3
) is at position3
, so it overwrites itself. Afterward, the program looks like this:1,9,10,70, 2,3,11,0, 99, 30,40,50
Step forward
4
positions to reach the next opcode,2
. This opcode works just like the previous, but it multiplies instead of adding. The inputs are at positions3
and11
; these positions contain70
and50
respectively. Multiplying these produces3500
; this is stored at position0
:3500,9,10,70, 2,3,11,0, 99, 30,40,50
Stepping forward
4
more positions arrives at opcode99
, halting the program.Here are the initial and final states of a few more small programs:
1,0,0,0,99
becomes2,0,0,0,99
(1 + 1 = 2
).2,3,0,3,99
becomes2,3,0,6,99
(3 * 2 = 6
).2,4,4,5,99,0
becomes2,4,4,5,99,9801
(99 * 99 = 9801
).1,1,1,4,99,5,6,0,99
becomes30,1,1,4,2,5,6,0,99
.Once you have a working computer, the first step is to restore the gravity assist program (your puzzle input) to the "1202 program alarm" state it had just before the last computer caught fire. To do this, before running the program, replace position
1
with the value12
and replace position2
with the value2
. What value is left at position0
after the program halts?
so as you can see in the tests there are no data changed so my code works fine and all the tests are green but when you want to work with the real data the say that you have to replace two values.
So my question is how to make that part work without breaking the tests.
Roelof
Op 28-12-2019 om 21:46 schreef Sean P. DeNigris:
Pharo Smalltalk Users mailing list wroteso to be clear. In the test are data given which not has to be changed. As soon as you have to solve the real problem , some data needs to be changed.It's difficult to give good design advice with such a partial picture of the domain, but two straightforward solutions might be: 1. self isDeploymentMode ifTrue: [ "change data" ] 2. or, self sanitizationStrategy: (NoSanitization | ProductionSanitization)----- Cheers, Sean -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
--- End Message ---
Re: [Pharo-users] how to change data on real data but not on test data
Roelof Wobben via Pharo-users Sat, 28 Dec 2019 13:04:22 -0800
- [Pharo-users] how to change data on real dat... Roelof Wobben via Pharo-users
- Re: [Pharo-users] how to change data on... Sean P. DeNigris
- Re: [Pharo-users] how to change dat... Roelof Wobben via Pharo-users