day 3 part 1
This commit is contained in:
parent
a65d4fb1e8
commit
b2508447dc
3 changed files with 21 additions and 1 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -5,4 +5,7 @@ bin/
|
||||||
obj/
|
obj/
|
||||||
.vscode/
|
.vscode/
|
||||||
*.sln
|
*.sln
|
||||||
*.csproj
|
*.csproj
|
||||||
|
*.so
|
||||||
|
workingFile.txt
|
||||||
|
database.db
|
5
2024/day3/run.sh
Executable file
5
2024/day3/run.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
rm database.db
|
||||||
|
cp input.txt workingFile.txt
|
||||||
|
sqlite3 < solution.sql
|
12
2024/day3/solution.sql
Normal file
12
2024/day3/solution.sql
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
.open database.db
|
||||||
|
.load ./sqlean
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS RESULTS (result number);
|
||||||
|
INSERT INTO results SELECT sum(regexp_capture(readfile('workingFile.txt'), 'mul\(([0-9]+),([0-9]+)\)', 1) * regexp_capture(readfile('workingFile.txt'), 'mul\(([0-9]+),([0-9]+)\)', 2));
|
||||||
|
|
||||||
|
SELECT fileio_write('workingFile.txt', text_replace(readfile('workingFile.txt'), regexp_substr(readfile('workingFile.txt'), 'mul\(([0-9]+),([0-9]+)\)'), ''));
|
||||||
|
|
||||||
|
SELECT 'answer (when 0 shows above):';
|
||||||
|
SELECT sum(result) FROM results;
|
||||||
|
|
||||||
|
.shell sqlite3 < solution.sql
|
Loading…
Reference in a new issue