Group solutions by language

This commit is contained in:
aru 2023-12-14 09:10:21 +01:00
parent d8a19b1fc6
commit 6352486a0a
56 changed files with 324 additions and 0 deletions

5
.gitignore vendored
View File

@ -7,3 +7,8 @@
# OCaml build artifacts
**/_build/**
# Direnv
.direnv
**/obj/**

3
2023/data/09/example Normal file
View File

@ -0,0 +1,3 @@
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45

1
2023/elixir/.envrc Normal file
View File

@ -0,0 +1 @@
use flake

20
2023/elixir/flake.nix Normal file
View File

@ -0,0 +1,20 @@
{
description = "A flake for pulling in dependencies.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in rec {
devShells.default = with pkgs; mkShell {
buildInputs = [ clojure ];
};
}
);
}

1
2023/haskell/.envrc Normal file
View File

@ -0,0 +1 @@
use flake

60
2023/haskell/flake.lock Normal file
View File

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1701680448,
"narHash": "sha256-jyBmBxAIOgSxuViuffo4ah8+NRHfY/9ByozjiLk/rf4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "6f3d9c7288802bd463f1419c1354a2d8b5ad1d9a",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

1
2023/nim/.envrc Normal file
View File

@ -0,0 +1 @@
use flake

60
2023/nim/flake.lock Normal file
View File

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1701680448,
"narHash": "sha256-jyBmBxAIOgSxuViuffo4ah8+NRHfY/9ByozjiLk/rf4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "6f3d9c7288802bd463f1419c1354a2d8b5ad1d9a",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

20
2023/nim/flake.nix Normal file
View File

@ -0,0 +1,20 @@
{
description = "A flake for pulling in dependencies.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in rec {
devShells.default = with pkgs; mkShell {
buildInputs = [ nim nimlsp ];
};
}
);
}

1
2023/scheme/.envrc Normal file
View File

@ -0,0 +1 @@
use flake

72
2023/scheme/04/solve.scm Normal file
View File

@ -0,0 +1,72 @@
(use-modules (ice-9 textual-ports)
(srfi srfi-1)
(srfi srfi-8))
(define (read-input)
(get-string-all (current-input-port)))
(define (string-present? s)
(not (string-null? s)))
(define (parse-input line)
(map parse-line
(filter string-present? (string-split line #\Newline))))
(define (parse-line line)
(define (parse-number-list l)
(map string->number (filter string-present? (string-split l #\Space))))
(let* ((num-part (cadr (string-split line #\:)))
(parts (string-split num-part #\|)))
(map parse-number-list parts)))
(define (winning-count l)
(let ((winning (car l))
(current (cadr l)))
(count (lambda (c) (member c winning)) current)))
(define (score v)
(cond
((= v 0) 0)
((= v 1) 1)
(#t (expt 2 (- v 1)))))
;; SRFI-1's take/drop panic if the list doesn't have enough elements
(define (my-take l n)
(if (or (null? l) (= n 0))
'()
(cons (car l) (my-take (cdr l) (- n 1)))))
(define (my-drop l n)
(if (or (null? l) (= n 0))
l
(my-drop (cdr l) (- n 1))))
(define (part1 winning-counts)
(reduce + 0 (map score winning-counts)))
(define (part2 winning-counts)
(define (propagate-forward l count multiplier)
(let ((h (my-take l count))
(t (my-drop l count)))
(append (map (lambda (x) (cons (car x) (+ (cdr x) multiplier))) h) t)))
(let ((with-multiplier (map (lambda (x) (cons x 1)) winning-counts)))
(let loop ((counts with-multiplier)
(n 0))
(if (null? counts)
n
(let* ((current (car counts))
(x (car current))
(multiplier (cdr current)))
(loop (propagate-forward (cdr counts) x multiplier)
(+ n multiplier)))))))
(let* ((input (parse-input (read-input)))
(winning-counts (map winning-count input)))
(begin
(display (part1 winning-counts))
(newline)
(display (part2 winning-counts))
(newline)))

60
2023/scheme/flake.lock Normal file
View File

@ -0,0 +1,60 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1701680448,
"narHash": "sha256-jyBmBxAIOgSxuViuffo4ah8+NRHfY/9ByozjiLk/rf4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "6f3d9c7288802bd463f1419c1354a2d8b5ad1d9a",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

20
2023/scheme/flake.nix Normal file
View File

@ -0,0 +1,20 @@
{
description = "A flake for pulling in dependencies.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in rec {
devShells.default = with pkgs; mkShell {
buildInputs = [ guile_3_0 ];
};
}
);
}