algorithm wrote: ↑Fri Feb 19, 2021 6:27 pm
I ran my complete code for day 22 on the Pico, which gave:
Part 1: winner = 1, score = 31629, time = 0.00035 s
Part 2: winner = 1, score = 35196, time = 0.09832 s
With the CRC-32 hash it's a bit slower because of extra copying and calculating:
Part 1: winner = 1, score = 31629, time = 0.00035 s
Part 2: winner = 1, score = 35196, time = 0.17132 s
Project at
https://github.com/ednl/pico/tree/main/aoc20d22
Somewhat of an improvement on the Python version, although that didn't use the recursion shortcut.
That's not a bad tradeoff for a more reliable hash of the game state.
The Go program doesn't even run on a Pi 4B anymore. Maybe the initial configuration of cards quoted above is triggering some sort of bug in the associative array implementation, since it's inconceivable there could be any more bugs in my code. At any rate, after two and a half hours the run ended with
Code: Select all
$ time ./go22
Advent of Code Day 22
Part 1 Player 1 won with score 32701
runtime: out of memory: cannot allocate 748683264-byte block (2541355008 in use)
fatal error: out of memory
runtime stack:
runtime.throw(0xd467b, 0xd)
/usr/lib/go-1.11/src/runtime/panic.go:608 +0x5c
runtime.largeAlloc(0x2ca00000, 0x50001, 0xb6f39000)
/usr/lib/go-1.11/src/runtime/malloc.go:1021 +0x120
runtime.mallocgc.func1()
/usr/lib/go-1.11/src/runtime/malloc.go:914 +0x38
runtime.systemstack(0x5d980)
/usr/lib/go-1.11/src/runtime/asm_arm.s:354 +0x84
runtime.mstart()
/usr/lib/go-1.11/src/runtime/proc.go:1229
goroutine 1 [running]:
runtime.systemstack_switch()
/usr/lib/go-1.11/src/runtime/asm_arm.s:298 +0x4 fp=0x145f84c sp=0x145f848 pc=0x5da88
runtime.mallocgc(0x2ca00000, 0xc5d68, 0x19260c01, 0x0)
/usr/lib/go-1.11/src/runtime/malloc.go:913 +0x898 fp=0x145f8b0 sp=0x145f84c pc=0x1a32c
runtime.newarray(0xc5d68, 0x880000, 0x26)
/usr/lib/go-1.11/src/runtime/malloc.go:1048 +0x5c fp=0x145f8c4 sp=0x145f8b0 pc=0x1a684
runtime.makeBucketArray(0xc0898, 0xb6f39017, 0x0, 0x1e83c, 0x8fb5ed80)
/usr/lib/go-1.11/src/runtime/map.go:355 +0x170 fp=0x145f8e0 sp=0x145f8c4 pc=0x1b42c
runtime.hashGrow(0xc0898, 0x145fa74)
/usr/lib/go-1.11/src/runtime/map.go:963 +0x7c fp=0x145f904 sp=0x145f8e0 pc=0x1c650
runtime.mapassign_faststr(0xc0898, 0x145fa74, 0x8fb5ed80, 0x26, 0x17f5a8)
/usr/lib/go-1.11/src/runtime/map_faststr.go:256 +0x1f4 fp=0x145f934 sp=0x145f904 pc=0x1e9e0
main.dogame(0xc0801, 0x145fc24)
/x/turb/ejolson/code/aofcode/fuzz/go22.go:125 +0xfc fp=0x145fae4 sp=0x145f934 pc=0xa2e80
main.dogame(0xc0801, 0x14a4dd4)
/x/turb/ejolson/code/aofcode/fuzz/go22.go:134 +0x260 fp=0x145fc94 sp=0x145fae4 pc=0xa2fe4
main.dogame(0x1, 0xa3574)
/x/turb/ejolson/code/aofcode/fuzz/go22.go:134 +0x260 fp=0x145fe44 sp=0x145fc94 pc=0xa2fe4
main.part2()
/x/turb/ejolson/code/aofcode/fuzz/go22.go:161 +0x1c fp=0x145fe88 sp=0x145fe44 pc=0xa33b8
main.main()
/x/turb/ejolson/code/aofcode/fuzz/go22.go:181 +0xa4 fp=0x145ffc4 sp=0x145fe88 pc=0xa3584
runtime.main()
/usr/lib/go-1.11/src/runtime/proc.go:201 +0x204 fp=0x145ffe4 sp=0x145ffc4 pc=0x390ec
runtime.goexit()
/usr/lib/go-1.11/src/runtime/asm_arm.s:867 +0x4 fp=0x145ffe4 sp=0x145ffe4 pc=0x5f7d0
real 163m58.645s
user 28m21.369s
sys 4m28.784s
which makes me think the 32-bit address space of Raspberry Pi OS was exhausted.
For reference, the exact same program completes all 50,000 test cases on an x86 server. Even on the 64-bit machine, that particular test case takes more CPU than all the other 49,999 shuffles of the deck combined.
Next up is to run the CRC hash version of the C code from the repository to see if there are still any differences between the two improved programs. I've improved my C code too, for comparison, but it might have become too memory intensive to actually run on a PET.