aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorj-james2022-11-23 10:18:23 +0000
committerj-james2022-11-23 10:18:23 +0000
commit91b4352bb2563ae335732b0042c6e422414b6e1e (patch)
tree7be4e83cca72c56072a5c64e6c4fc3c6cf98a524
parent4cbdf16fbf2168feb6dc473f003e701623b75584 (diff)
Prepare scripts and templates for 2022
-rwxr-xr-x2022/get16
-rw-r--r--2022/main.nim12
-rw-r--r--2022/main.rs8
-rwxr-xr-x2022/one7
-rwxr-xr-x2022/run5
-rwxr-xr-x2022/two7
-rwxr-xr-x2022/vars4
7 files changed, 59 insertions, 0 deletions
diff --git a/2022/get b/2022/get
new file mode 100755
index 0000000..48f39d6
--- /dev/null
+++ b/2022/get
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+source "vars"
+INPUT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/input"
+
+mkdir "nim/day${DAY}"
+cp "main.nim" "nim/day${DAY}/main.nim"
+curl $INPUT_URL --cookie "session=${TOKEN}" > "nim/day${DAY}/input.txt"
+
+cargo new "rust/day${DAY}"
+cp "main.rs" "rust/day${DAY}/src/main.rs"
+cp "nim/day${DAY}/input.txt" "rust/day${DAY}/src/input.txt"
+
+subl -a "nim/day${DAY}/input.txt"
+subl -a "nim/day${DAY}/main.nim"
+chromium "https://adventofcode.com/${YEAR}/day/$((10#${DAY}))"
diff --git a/2022/main.nim b/2022/main.nim
new file mode 100644
index 0000000..9960bf9
--- /dev/null
+++ b/2022/main.nim
@@ -0,0 +1,12 @@
+# Day ???: ???
+import std/[os, strutils, sequtils, sugar, enumerate]
+# import std/[algorithm, math, hashes, tables, sets]
+# import std/[strformat, strscans]
+
+# useful functions and things to remember:
+# - readFile, splitLines, split(""), strip({''})
+# - map(func), filter(func), all(func), any(func)
+# - foldl(func, init), string.repeat(count), zip(a, b)
+# for i, chr in "string": assert "string"[i] == chr
+
+let input: string = paramStr(1).readFile()
diff --git a/2022/main.rs b/2022/main.rs
new file mode 100644
index 0000000..2cad662
--- /dev/null
+++ b/2022/main.rs
@@ -0,0 +1,8 @@
+use std::env;
+use std::fs;
+
+fn main() {
+ let args = env::args().nth(1).expect("");
+ let input = fs::read_to_string(args).expect("");
+ println!("{}", input);
+}
diff --git a/2022/one b/2022/one
new file mode 100755
index 0000000..6b7db35
--- /dev/null
+++ b/2022/one
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+source "vars"
+LEVEL="1"
+SUBMIT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/answer"
+
+curl $SUBMIT_URL --cookie "session=${TOKEN}" --data "level=${LEVEL}&answer=$1" | rg -C 1 "main"
diff --git a/2022/run b/2022/run
new file mode 100755
index 0000000..a3d77e4
--- /dev/null
+++ b/2022/run
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+source "vars"
+
+nim c -r "nim/day${DAY}/main.nim" "nim/day${DAY}/input.txt"
diff --git a/2022/two b/2022/two
new file mode 100755
index 0000000..8dd0080
--- /dev/null
+++ b/2022/two
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+source "vars"
+LEVEL="2"
+SUBMIT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/answer"
+
+curl $SUBMIT_URL --cookie "session=${TOKEN}" --data "level=${LEVEL}&answer=$1" | rg -C 1 "main"
diff --git a/2022/vars b/2022/vars
new file mode 100755
index 0000000..e29495c
--- /dev/null
+++ b/2022/vars
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+DAY="01"
+YEAR="2021"