From 91b4352bb2563ae335732b0042c6e422414b6e1e Mon Sep 17 00:00:00 2001 From: j-james Date: Wed, 23 Nov 2022 02:18:23 -0800 Subject: Prepare scripts and templates for 2022 --- 2022/get | 16 ++++++++++++++++ 2022/main.nim | 12 ++++++++++++ 2022/main.rs | 8 ++++++++ 2022/one | 7 +++++++ 2022/run | 5 +++++ 2022/two | 7 +++++++ 2022/vars | 4 ++++ 7 files changed, 59 insertions(+) create mode 100755 2022/get create mode 100644 2022/main.nim create mode 100644 2022/main.rs create mode 100755 2022/one create mode 100755 2022/run create mode 100755 2022/two create mode 100755 2022/vars 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" -- cgit v1.2.3-70-g09d2