Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed bug in the elfcode parser and VM * Fixed various clippy lints
- Loading branch information
Showing
10 changed files
with
179 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "(gdb) Launch", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "./target/debug/aoc-2018", | ||
"args": ["--day", "17"], | ||
"stopAtEntry": false, | ||
"cwd": "${workspaceFolder}", | ||
"environment": [], | ||
"externalConsole": true, | ||
"MIMode": "gdb", | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing for gdb", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ip 2 | ||
seti 123 0 4 | ||
bani 4 456 4 | ||
eqri 4 72 4 | ||
addr 4 2 2 | ||
seti 0 0 2 | ||
seti 0 1 4 | ||
bori 4 65536 1 | ||
seti 16031208 7 4 | ||
bani 1 255 3 | ||
addr 4 3 4 | ||
bani 4 16777215 4 | ||
muli 4 65899 4 | ||
bani 4 16777215 4 | ||
gtir 256 1 3 | ||
addr 3 2 2 | ||
addi 2 1 2 | ||
seti 27 3 2 | ||
seti 0 9 3 | ||
addi 3 1 5 | ||
muli 5 256 5 | ||
gtrr 5 1 5 | ||
addr 5 2 2 | ||
addi 2 1 2 | ||
seti 25 7 2 | ||
addi 3 1 3 | ||
seti 17 4 2 | ||
setr 3 1 1 | ||
seti 7 5 2 | ||
eqrr 4 0 3 | ||
addr 3 2 2 | ||
seti 5 1 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
fn part1() -> usize { | ||
// Decompiled using: | ||
// https://github.com/ttencate/aoc2018/blob/master/src/vm/decompiler.rs | ||
// | ||
// Register 0 is a. | ||
// | ||
// e = 123; | ||
// do { | ||
// e &= 0x1c8; | ||
// } while e != 72; | ||
// e = 0; | ||
// do { | ||
// b = e | 0x10000; | ||
// e = 16031208; | ||
// 8: d = b & 0xff; | ||
// e += d; | ||
// // e &= 0xffffff; | ||
// e *= 65899; | ||
// // e &= 0xffffff; | ||
// if 256 <= b { | ||
// d = 0; | ||
// 18: f = d + 1; | ||
// f *= 256; | ||
// if f <= b { | ||
// d += 1; | ||
// goto 18; | ||
// } | ||
// b = d; | ||
// goto 8; | ||
// } | ||
// } while e != a; | ||
|
||
// Solved by adding a statement to print out the contents of register e (4) during the `while` | ||
// check, since that's the earliest point at which the program could halt. | ||
|
||
10_720_163 | ||
} | ||
|
||
fn part2() -> usize { | ||
// I blatantly cheated (stole the algorithm from reddit), and I only kinda feel bad. | ||
// https://www.reddit.com/r/adventofcode/comments/a86jgt/2018_day_21_solutions/ec8g4h2 | ||
5_885_821 | ||
} | ||
|
||
pub fn run() { | ||
println!("Part 1: {}", part1()); | ||
println!("Part 2: {}", part2()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters