From b2508447dc661dafaa8625fe039c1ce127a5d973 Mon Sep 17 00:00:00 2001 From: nin0dev Date: Wed, 4 Dec 2024 07:38:37 -0500 Subject: [PATCH] day 3 part 1 --- .gitignore | 5 ++++- 2024/day3/run.sh | 5 +++++ 2024/day3/solution.sql | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 2024/day3/run.sh create mode 100644 2024/day3/solution.sql 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