diff --git a/.gitignore b/.gitignore index 1040fc5..3b8b0b5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ bin/ obj/ .vscode/ *.sln -*.csproj \ No newline at end of file +*.csproj +*.so +workingFile.txt +database.db \ No newline at end of file diff --git a/2024/day3/run.sh b/2024/day3/run.sh new file mode 100755 index 0000000..9b80a63 --- /dev/null +++ b/2024/day3/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +rm database.db +cp input.txt workingFile.txt +sqlite3 < solution.sql diff --git a/2024/day3/solution.sql b/2024/day3/solution.sql new file mode 100644 index 0000000..dc768da --- /dev/null +++ b/2024/day3/solution.sql @@ -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 \ No newline at end of file