|
|
|
@ -47,7 +47,36 @@
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
(func (export "part2") (result i32)
|
|
|
|
|
i32.const 0
|
|
|
|
|
(local $currentScore i32)
|
|
|
|
|
(local $lastRead i32)
|
|
|
|
|
call $initRead
|
|
|
|
|
|
|
|
|
|
loop $readLoop
|
|
|
|
|
call $readLine
|
|
|
|
|
|
|
|
|
|
;; check to see if we've hit the end
|
|
|
|
|
local.tee $lastRead
|
|
|
|
|
i32.eqz
|
|
|
|
|
if
|
|
|
|
|
call $initWrite
|
|
|
|
|
|
|
|
|
|
local.get $currentScore
|
|
|
|
|
call $writeNum
|
|
|
|
|
|
|
|
|
|
call $closeWrite
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local.get $lastRead
|
|
|
|
|
call $solveRound
|
|
|
|
|
call $getScore
|
|
|
|
|
local.get $currentScore
|
|
|
|
|
i32.add
|
|
|
|
|
local.set $currentScore
|
|
|
|
|
br $readLoop
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
unreachable
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
(func $initRead
|
|
|
|
@ -88,6 +117,29 @@
|
|
|
|
|
global.get $inputEnd
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
(func $solveRound (param $theirs i32) (param $outcome i32) (result i32 i32)
|
|
|
|
|
(local $tmp i32)
|
|
|
|
|
|
|
|
|
|
local.get $outcome
|
|
|
|
|
i32.const 1
|
|
|
|
|
i32.add
|
|
|
|
|
|
|
|
|
|
local.get $theirs
|
|
|
|
|
i32.add
|
|
|
|
|
i32.const 3
|
|
|
|
|
i32.rem_s
|
|
|
|
|
local.tee $tmp
|
|
|
|
|
|
|
|
|
|
i32.eqz
|
|
|
|
|
if
|
|
|
|
|
i32.const 3
|
|
|
|
|
local.set $tmp
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local.get $theirs
|
|
|
|
|
local.get $tmp
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
(func $getScore (param $theirs i32) (param $ours i32) (result i32)
|
|
|
|
|
(local $diff i32)
|
|
|
|
|
|
|
|
|
|