Group solutions by language
This commit is contained in:
parent
d8a19b1fc6
commit
6352486a0a
|
@ -7,3 +7,8 @@
|
|||
|
||||
# OCaml build artifacts
|
||||
**/_build/**
|
||||
|
||||
# Direnv
|
||||
.direnv
|
||||
|
||||
**/obj/**
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
0 3 6 9 12 15
|
||||
1 3 6 10 15 21
|
||||
10 13 16 21 30 45
|
|
@ -0,0 +1 @@
|
|||
use flake
|
|
@ -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 ];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
use flake
|
|
@ -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
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
use flake
|
|
@ -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
|
||||
}
|
|
@ -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 ];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
use flake
|
|
@ -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)))
|
|
@ -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
|
||||
}
|
|
@ -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 ];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue