Compare commits
No commits in common. "4d2c3161d2c449c4fa815b86eb302b280243c70c" and "67130ccc370e9e6fb5f23a1a0f702cbd0f3a1c55" have entirely different histories.
4d2c3161d2
...
67130ccc37
|
@ -15,7 +15,6 @@
|
||||||
'';
|
'';
|
||||||
py_pkgs = [ pkgs.python310 ];
|
py_pkgs = [ pkgs.python310 ];
|
||||||
lua_pkgs = [ (pkgs.lua.withPackages (luapkgs: [ luapkgs.busted luapkgs.luafilesystem ])) ];
|
lua_pkgs = [ (pkgs.lua.withPackages (luapkgs: [ luapkgs.busted luapkgs.luafilesystem ])) ];
|
||||||
fennel_pkgs = [];
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Jack of all trades
|
# Jack of all trades
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
echo "This problem shares one input between two parts"
|
echo "This problem shares one input between two parts"
|
||||||
'';
|
'';
|
||||||
py_pkgs = [ pkgs.python310 ];
|
py_pkgs = [ pkgs.python310 ];
|
||||||
# lua_pkgs = [ (pkgs.lua.withPackages (luapkgs: [ luapkgs.busted luapkgs.luafilesystem ])) ];
|
lua_pkgs = [ (pkgs.lua.withPackages (luapkgs: [ luapkgs.busted luapkgs.luafilesystem ])) ];
|
||||||
fennel_pkgs = [ (pkgs.lua.withPackages (luapkgs: [ luapkgs.fennel luapkgs.readline ])) ];
|
fennel_pkgs = [ pkgs.lua.withPackages (luapkgs: [ luapkgs.fennel ]) ];
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Jack of all trades
|
# Jack of all trades
|
||||||
devShell = pkgs.mkShell {
|
devShell = pkgs.mkShell {
|
||||||
nativeBuildInputs = py_pkgs ++ fennel_pkgs;
|
nativeBuildInputs = py_pkgs ++ fennel_pkgs;
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
echo "> Default runtime. This contains both fennel and python3 env"
|
echo "> Default runtime. This contains both lua and python3 env"
|
||||||
echo "Run ./run-py.sh for Python's output and ./run-fnl.sh for Fennel's output"
|
echo "Run ./run-py.sh for Python's output and ./run-lua.sh for Lua's output"
|
||||||
'' + shellHookAfter;
|
'' + shellHookAfter;
|
||||||
};
|
};
|
||||||
devShells = {
|
devShells = {
|
||||||
|
@ -35,17 +35,6 @@
|
||||||
# echo "Run ./run-lua.sh to see the output of the solution"
|
# echo "Run ./run-lua.sh to see the output of the solution"
|
||||||
# '' + shellHookAfter;
|
# '' + shellHookAfter;
|
||||||
# };
|
# };
|
||||||
|
|
||||||
# nix develop ./#fennel
|
|
||||||
fennel = pkgs.mkShell
|
|
||||||
{
|
|
||||||
nativeBuildInputs = fennel_pkgs;
|
|
||||||
shellHook = ''
|
|
||||||
echo "> Fennel runtime"
|
|
||||||
echo "Run ./run-fnl.sh to see output of Fennel solution"
|
|
||||||
'' + shellHookAfter;
|
|
||||||
};
|
|
||||||
|
|
||||||
# nix develop ./#python
|
# nix develop ./#python
|
||||||
python = pkgs.mkShell {
|
python = pkgs.mkShell {
|
||||||
nativeBuildInputs = py_pkgs;
|
nativeBuildInputs = py_pkgs;
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
echo "example"
|
|
||||||
fennel ./src/d5.fnl ./data/example.txt
|
|
||||||
|
|
||||||
echo "submission"
|
|
||||||
fennel ./src/d5.fnl ./data/submission.txt
|
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
(local fennel (require :fennel))
|
|
||||||
|
|
||||||
(fn pp [x]
|
|
||||||
(print (fennel.view x)))
|
|
||||||
|
|
||||||
(fn get-crates-insns [fileloc]
|
|
||||||
(let [file (assert (io.open fileloc :r))
|
|
||||||
contents (file:read "*a")
|
|
||||||
(crates instrs) ((string.gmatch contents "(.+)\n\n(.+)"))
|
|
||||||
]
|
|
||||||
(file:close)
|
|
||||||
[crates instrs]))
|
|
||||||
|
|
||||||
(let [fileloc (. _G.arg 1)
|
|
||||||
(crates instrs) (get-crates-insns fileloc)
|
|
||||||
]
|
|
||||||
;; (pp contents)
|
|
||||||
;; (print split)
|
|
||||||
(pp crates)
|
|
||||||
(pp instrs)
|
|
||||||
)
|
|
||||||
|
|
||||||
; REPL helpers
|
|
||||||
(tset _G :arg ["./data/example.txt"]) ; provides hint for arg[1] to the REPL
|
|
||||||
(assert (= (. _G.arg 1) "../data/example.txt"))
|
|
||||||
(local fennel (require :fennel))
|
|
||||||
|
|
||||||
(fn _G.pp [x]
|
|
||||||
(print (fennel.view x)))
|
|
||||||
;; (_G.pp _G.arg)
|
|
||||||
|
|
||||||
|
|
||||||
;; REPL sandbox
|
|
||||||
; Function vs lambda: failure to pass a specific or nil variable
|
|
||||||
;; (fn nilable [a b c]
|
|
||||||
;; (print a b c))
|
|
||||||
;; (nilable 10 12)
|
|
||||||
;;
|
|
||||||
;; (lambda non-nilable [a b c]
|
|
||||||
;; (print a b c))
|
|
||||||
;; (non-nilable 10 12)
|
|
||||||
|
|
||||||
|
|
||||||
;; (let [(a b) ((string.gmatch "hello\nmy\nrandom\nstranger\n\nin\nthis\nsmall\nworld" "(.+)\n\n(.+)"))]
|
|
||||||
;; (_G.pp a)
|
|
||||||
;; (_G.pp b))
|
|
||||||
|
|
||||||
;; (let [split ((string.gmatch "hello\nmy\nrandom\nstranger\n\nin\nthis\nsmall\nworld" "(.+)\n"))]
|
|
||||||
;; (_G.pp split)
|
|
||||||
;; )
|
|
||||||
|
|
||||||
;; (fn overpass [a]
|
|
||||||
;; (print a)) (overpass "hello" "world")
|
|
||||||
;;
|
|
||||||
;; (lambda overpass [a]
|
|
||||||
;; (print a)) (overpass "hello" "world")
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ class MoveInsn:
|
||||||
def part1(crates: list[list[str]], insns: list[MoveInsn]) -> str:
|
def part1(crates: list[list[str]], insns: list[MoveInsn]) -> str:
|
||||||
for move in insns:
|
for move in insns:
|
||||||
for _ in range(move.how_many):
|
for _ in range(move.how_many):
|
||||||
# print(crates)
|
|
||||||
crates[move.to_crate - 1].append(crates[move.from_crate - 1].pop())
|
crates[move.to_crate - 1].append(crates[move.from_crate - 1].pop())
|
||||||
return "".join([crate[-1] for crate in crates])
|
return "".join([crate[-1] for crate in crates])
|
||||||
|
|
||||||
|
@ -76,4 +75,3 @@ if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
with open(sys.argv[1], "r") as f:
|
with open(sys.argv[1], "r") as f:
|
||||||
main(f)
|
main(f)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
if command -v nix-shell &> /dev/null
|
|
||||||
then
|
|
||||||
use flake
|
|
||||||
fi
|
|
|
@ -1,43 +0,0 @@
|
||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"flake-utils": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1667395993,
|
|
||||||
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1670064435,
|
|
||||||
"narHash": "sha256-+ELoY30UN+Pl3Yn7RWRPabykwebsVK/kYE9JsIsUMxQ=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "61a8a98e6d557e6dd7ed0cdb54c3a3e3bbc5e25c",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "nixos-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
{
|
|
||||||
description = "D4 AOC with Lua!";
|
|
||||||
inputs = {
|
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
|
||||||
};
|
|
||||||
outputs = { nixpkgs, flake-utils, ... } @ inputs:
|
|
||||||
flake-utils.lib.eachSystem flake-utils.lib.defaultSystems (sys:
|
|
||||||
let
|
|
||||||
overlays = [ ];
|
|
||||||
pkgs = import nixpkgs { system = sys; overlays = overlays; };
|
|
||||||
shellHookAfter = ''
|
|
||||||
echo "The input files should be placed under ./data/{submission,example}.txt"
|
|
||||||
echo "This problem shares one input between two parts"
|
|
||||||
'';
|
|
||||||
py_pkgs = [ pkgs.python310 ];
|
|
||||||
# lua_pkgs = [ (pkgs.lua.withPackages (luapkgs: [ luapkgs.busted luapkgs.luafilesystem ])) ];
|
|
||||||
fennel_pkgs = [ (pkgs.lua.withPackages (luapkgs: [ luapkgs.fennel luapkgs.readline ])) ];
|
|
||||||
in
|
|
||||||
{
|
|
||||||
# Jack of all trades
|
|
||||||
devShell = pkgs.mkShell {
|
|
||||||
nativeBuildInputs = py_pkgs ++ fennel_pkgs;
|
|
||||||
shellHook = ''
|
|
||||||
echo "> Default runtime. This contains both fennel and python3 env"
|
|
||||||
echo "Run ./run-py.sh for Python's output and ./run-fnl.sh for Fennel's output"
|
|
||||||
'' + shellHookAfter;
|
|
||||||
};
|
|
||||||
devShells = {
|
|
||||||
# nix develop ./#lua
|
|
||||||
# lua = pkgs.mkShell {
|
|
||||||
# nativeBuildInputs = lua_pkgs;
|
|
||||||
# shellHook = ''
|
|
||||||
# echo "> Lua runtime"
|
|
||||||
# echo "Run ./run-lua.sh to see the output of the solution"
|
|
||||||
# '' + shellHookAfter;
|
|
||||||
# };
|
|
||||||
|
|
||||||
# nix develop ./#fennel
|
|
||||||
fennel = pkgs.mkShell
|
|
||||||
{
|
|
||||||
nativeBuildInputs = fennel_pkgs;
|
|
||||||
shellHook = ''
|
|
||||||
echo "> Fennel runtime"
|
|
||||||
echo "Run ./run-fnl.sh to see output of Fennel solution"
|
|
||||||
'' + shellHookAfter;
|
|
||||||
};
|
|
||||||
|
|
||||||
# nix develop ./#python
|
|
||||||
python = pkgs.mkShell {
|
|
||||||
nativeBuildInputs = py_pkgs;
|
|
||||||
shellHook = ''
|
|
||||||
echo "> Python3 runtime"
|
|
||||||
echo "Run ./run-py.sh to see the output of the solution"
|
|
||||||
'' + shellHookAfter;
|
|
||||||
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
echo "example"
|
|
||||||
python3 ./src/d6.py ./data/example.txt
|
|
||||||
|
|
||||||
echo "submission"
|
|
||||||
python3 ./src/d6.py ./data/submission.txt
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from typing import TextIO
|
|
||||||
|
|
||||||
|
|
||||||
def part1(f: TextIO):
|
|
||||||
s = f.read().strip()
|
|
||||||
print(f"{s=}")
|
|
||||||
for i in range(3, len(s)):
|
|
||||||
if len({c for c in s[i-3:i+1]}) == 4:
|
|
||||||
return i + 1
|
|
||||||
return None
|
|
||||||
|
|
||||||
def part2(f: TextIO):
|
|
||||||
s = f.read().strip()
|
|
||||||
print(f"{s=}")
|
|
||||||
for i in range(13, len(s)):
|
|
||||||
if len({c for c in s[i-13:i+1]}) == 14:
|
|
||||||
return i + 1
|
|
||||||
return None
|
|
||||||
|
|
||||||
def main(fileloc: str):
|
|
||||||
with open(fileloc, "r") as f:
|
|
||||||
print(f"{part1(f)=}")
|
|
||||||
|
|
||||||
with open(fileloc, "r") as f:
|
|
||||||
print(f"{part2(f)=}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import sys
|
|
||||||
main(sys.argv[1])
|
|
||||||
|
|
Loading…
Reference in New Issue