From 07af61effb2a03025adfe7411a4b61a584a2f734 Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Thu, 12 Dec 2024 22:11:26 +0100 Subject: [PATCH] day3 done --- day3/day.py | 23 +++++++++++++++++++++++ day3/parser-second.sh | 2 ++ day3/parser.sh | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 day3/day.py create mode 100755 day3/parser-second.sh create mode 100755 day3/parser.sh diff --git a/day3/day.py b/day3/day.py new file mode 100644 index 0000000..a34ff3e --- /dev/null +++ b/day3/day.py @@ -0,0 +1,23 @@ +res = 0 +write = True + +def mul(a, b): + global write + if write: + global res + res += (a * b) + +def do(): + global write + write = True + +def dont(): + global write + write = False + +with open('parsed_sec', 'r') as file: + # Read each line in the file + for line in file: + # Print each line + exec(line) +print(res) \ No newline at end of file diff --git a/day3/parser-second.sh b/day3/parser-second.sh new file mode 100755 index 0000000..ac71e69 --- /dev/null +++ b/day3/parser-second.sh @@ -0,0 +1,2 @@ +#!/bin/bash +grep -o "mul([0-9]*[0-9],[0-9]*[0-9])\|do()\|don't()" $1 | tr -d "'" \ No newline at end of file diff --git a/day3/parser.sh b/day3/parser.sh new file mode 100755 index 0000000..806f259 --- /dev/null +++ b/day3/parser.sh @@ -0,0 +1,2 @@ +#!/bin/bash +grep -o 'mul([0-9]*[0-9],[0-9]*[0-9])' $1 \ No newline at end of file