From 70348ba551d17676e465fa463b32ff0f97e1fd75 Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Tue, 19 Nov 2024 20:32:23 -0500 Subject: [PATCH] C3 --- c3/.gitignore | 4 ++++ c3/2015/1/problem.c3 | 24 ++++++++++++++++++++++++ c3/README.md | 1 + c3/bin/run | 7 +++++++ 4 files changed, 36 insertions(+) create mode 100644 c3/.gitignore create mode 100644 c3/2015/1/problem.c3 create mode 100644 c3/README.md create mode 100755 c3/bin/run diff --git a/c3/.gitignore b/c3/.gitignore new file mode 100644 index 0000000..9db4e84 --- /dev/null +++ b/c3/.gitignore @@ -0,0 +1,4 @@ +bin/* +!bin/run + +**/problem \ No newline at end of file diff --git a/c3/2015/1/problem.c3 b/c3/2015/1/problem.c3 new file mode 100644 index 0000000..27140e8 --- /dev/null +++ b/c3/2015/1/problem.c3 @@ -0,0 +1,24 @@ +import std::io; + +fn void main() +{ + String! line = io::readline(); + if (try line) { + int floor = 0; + foreach (paren : line) { + if (paren == '(') floor++; + if (paren == ')') floor--; + } + io::printfn("Part 1: %d", floor); + + floor = 0; + int index = 0; + foreach (paren : line) { + if (paren == '(') floor++; + if (paren == ')') floor--; + index++; + if (floor < 0) break; + } + io::printfn("Part 2: %d", index); + } +} diff --git a/c3/README.md b/c3/README.md new file mode 100644 index 0000000..5ace109 --- /dev/null +++ b/c3/README.md @@ -0,0 +1 @@ +To run this, download the c3 tar and unzip it directly into the bin directory diff --git a/c3/bin/run b/c3/bin/run new file mode 100755 index 0000000..c1d2851 --- /dev/null +++ b/c3/bin/run @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +year=$1 +day=$2 + +../c3/bin/c3c compile -o $year/$day/problem $year/$day/problem.c3 && \ +time (cat ../data/$year/$day/input.txt | ./$year/$day/problem)