From 5bb17e9fcf87a976c69dab9e6a73a42745b3d4ce Mon Sep 17 00:00:00 2001 From: j-james Date: Wed, 30 Nov 2022 19:01:41 -0800 Subject: Move scripts to a util folder --- util/get | 17 +++++++++++++++++ util/main.nim | 16 ++++++++++++++++ util/main.rs | 8 ++++++++ util/one | 7 +++++++ util/run | 5 +++++ util/two | 7 +++++++ util/watch | 7 +++++++ 7 files changed, 67 insertions(+) create mode 100755 util/get create mode 100644 util/main.nim create mode 100644 util/main.rs create mode 100755 util/one create mode 100755 util/run create mode 100755 util/two create mode 100755 util/watch (limited to 'util') diff --git a/util/get b/util/get new file mode 100755 index 0000000..423dfca --- /dev/null +++ b/util/get @@ -0,0 +1,17 @@ +#!/bin/bash + +source "vars" +INPUT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/input" + +mkdir "nim/day${DAY}" +mkdir "nim/day${DAY}/src" +cp "main.nim" "nim/day${DAY}/src/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}/input.txt" + +subl -a "nim/day${DAY}/input.txt" +subl -a "nim/day${DAY}/src/main.nim" +# chromium "https://adventofcode.com/${YEAR}/day/$((10#${DAY}))" diff --git a/util/main.nim b/util/main.nim new file mode 100644 index 0000000..15ba6b9 --- /dev/null +++ b/util/main.nim @@ -0,0 +1,16 @@ +# Day ???: ??? +import std/[os, strutils, sequtils, sugar] +# import std/[algorithm, math, hashes, tables, sets] +# import std/[strformat, strscans, enumerate] + +# 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 +# assert @[0, 1, 2, 3] == collect(for i in 0..3: i) + +let input = paramStr(1).readFile().strip().split("\n") + +for line in input: + discard diff --git a/util/main.rs b/util/main.rs new file mode 100644 index 0000000..2cad662 --- /dev/null +++ b/util/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/util/one b/util/one new file mode 100755 index 0000000..6b7db35 --- /dev/null +++ b/util/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/util/run b/util/run new file mode 100755 index 0000000..3d068e1 --- /dev/null +++ b/util/run @@ -0,0 +1,5 @@ +#!/bin/bash + +source "vars" + +nim c --warnings:off --hints:off -r "nim/day${DAY}/src/main.nim" "nim/day${DAY}/input.txt" diff --git a/util/two b/util/two new file mode 100755 index 0000000..8dd0080 --- /dev/null +++ b/util/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/util/watch b/util/watch new file mode 100755 index 0000000..9c79c6e --- /dev/null +++ b/util/watch @@ -0,0 +1,7 @@ +#!/bin/bash + +source "vars" + +while inotifywait --quiet --event modify "nim/day${DAY}/src/main.nim" +do ./run +done -- cgit v1.2.3-70-g09d2