1
1
Fork 0
adventofcode/2024/day3/solution.sql

12 lines
534 B
MySQL
Raw Normal View History

2024-12-04 07:38:37 -05:00
.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