From 3d57434c04a669610d5f15bd2a7713e6928cdef7 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Thu, 30 Nov 2023 22:46:45 -0700 Subject: add aoc2023 --- README.md | 32 -- aoc_2022/README.md | 32 ++ aoc_2022/day-00/.gitkeep | 0 aoc_2022/day-00/sol.sh | 40 ++ aoc_2022/day-01/.gitkeep | 0 aoc_2022/day-01/sol.c | 74 +++ aoc_2022/day-02/.gitkeep | 0 aoc_2022/day-02/sol.clj | 34 ++ aoc_2022/day-03/.gitkeep | 0 aoc_2022/day-03/sol.lisp | 33 ++ aoc_2022/day-04/.gitkeep | 0 aoc_2022/day-04/a.out | Bin 0 -> 92448 bytes aoc_2022/day-04/sol.cpp | 103 ++++ aoc_2022/day-05/.gitkeep | 0 aoc_2022/day-05/sol.exs | 28 ++ aoc_2022/day-06/.gitkeep | 0 aoc_2022/day-06/package.json | 3 + aoc_2022/day-06/sol.js | 115 +++++ aoc_2022/day-07/.gitkeep | 0 aoc_2022/day-07/sol.hs | 114 +++++ aoc_2022/day-08/.gitkeep | 0 aoc_2022/day-09/.gitkeep | 0 aoc_2022/day-10/.gitkeep | 0 aoc_2022/day-11/.gitkeep | 0 aoc_2022/day-11/sol.py | 67 +++ aoc_2022/day-12/.gitignore | 3 + aoc_2022/day-12/.gitkeep | 0 aoc_2022/day-12/package-lock.json | 46 ++ aoc_2022/day-12/package.json | 9 + aoc_2022/day-12/sol.ts | 59 +++ aoc_2022/day-12/tsconfig.json | 103 ++++ aoc_2022/day-13/.gitkeep | 0 aoc_2022/day-13/sol.java | 147 ++++++ aoc_2022/day-14/.gitkeep | 0 aoc_2022/day-15/.gitkeep | 0 aoc_2022/day-16/.gitkeep | 0 aoc_2022/day-17/.gitkeep | 0 aoc_2022/day-18/.gitkeep | 0 aoc_2022/day-19/.gitkeep | 0 aoc_2022/day-20/.gitkeep | 0 aoc_2022/day-21/.gitkeep | 0 aoc_2022/day-22/.gitkeep | 0 aoc_2022/day-23/.gitkeep | 0 aoc_2022/day-24/.gitkeep | 0 aoc_2023/day0/input.txt | 1000 +++++++++++++++++++++++++++++++++++++ aoc_2023/day0/main_1.js | 18 + aoc_2023/day0/main_2.js | 43 ++ day-00/.gitkeep | 0 day-00/sol.sh | 40 -- day-01/.gitkeep | 0 day-01/sol.c | 74 --- day-02/.gitkeep | 0 day-02/sol.clj | 34 -- day-03/.gitkeep | 0 day-03/sol.lisp | 33 -- day-04/.gitkeep | 0 day-04/a.out | Bin 92448 -> 0 bytes day-04/sol.cpp | 103 ---- day-05/.gitkeep | 0 day-05/sol.exs | 28 -- day-06/.gitkeep | 0 day-06/package.json | 3 - day-06/sol.js | 115 ----- day-07/.gitkeep | 0 day-07/sol.hs | 114 ----- day-08/.gitkeep | 0 day-09/.gitkeep | 0 day-10/.gitkeep | 0 day-11/.gitkeep | 0 day-11/sol.py | 67 --- day-12/.gitignore | 3 - day-12/.gitkeep | 0 day-12/package-lock.json | 46 -- day-12/package.json | 9 - day-12/sol.ts | 59 --- day-12/tsconfig.json | 103 ---- day-13/.gitkeep | 0 day-13/sol.java | 147 ------ day-14/.gitkeep | 0 day-15/.gitkeep | 0 day-16/.gitkeep | 0 day-17/.gitkeep | 0 day-18/.gitkeep | 0 day-19/.gitkeep | 0 day-20/.gitkeep | 0 day-21/.gitkeep | 0 day-22/.gitkeep | 0 day-23/.gitkeep | 0 day-24/.gitkeep | 0 89 files changed, 2071 insertions(+), 1010 deletions(-) delete mode 100644 README.md create mode 100644 aoc_2022/README.md create mode 100644 aoc_2022/day-00/.gitkeep create mode 100755 aoc_2022/day-00/sol.sh create mode 100644 aoc_2022/day-01/.gitkeep create mode 100644 aoc_2022/day-01/sol.c create mode 100644 aoc_2022/day-02/.gitkeep create mode 100644 aoc_2022/day-02/sol.clj create mode 100644 aoc_2022/day-03/.gitkeep create mode 100644 aoc_2022/day-03/sol.lisp create mode 100644 aoc_2022/day-04/.gitkeep create mode 100755 aoc_2022/day-04/a.out create mode 100644 aoc_2022/day-04/sol.cpp create mode 100644 aoc_2022/day-05/.gitkeep create mode 100644 aoc_2022/day-05/sol.exs create mode 100644 aoc_2022/day-06/.gitkeep create mode 100644 aoc_2022/day-06/package.json create mode 100644 aoc_2022/day-06/sol.js create mode 100644 aoc_2022/day-07/.gitkeep create mode 100644 aoc_2022/day-07/sol.hs create mode 100644 aoc_2022/day-08/.gitkeep create mode 100644 aoc_2022/day-09/.gitkeep create mode 100644 aoc_2022/day-10/.gitkeep create mode 100644 aoc_2022/day-11/.gitkeep create mode 100644 aoc_2022/day-11/sol.py create mode 100644 aoc_2022/day-12/.gitignore create mode 100644 aoc_2022/day-12/.gitkeep create mode 100644 aoc_2022/day-12/package-lock.json create mode 100644 aoc_2022/day-12/package.json create mode 100644 aoc_2022/day-12/sol.ts create mode 100644 aoc_2022/day-12/tsconfig.json create mode 100644 aoc_2022/day-13/.gitkeep create mode 100644 aoc_2022/day-13/sol.java create mode 100644 aoc_2022/day-14/.gitkeep create mode 100644 aoc_2022/day-15/.gitkeep create mode 100644 aoc_2022/day-16/.gitkeep create mode 100644 aoc_2022/day-17/.gitkeep create mode 100644 aoc_2022/day-18/.gitkeep create mode 100644 aoc_2022/day-19/.gitkeep create mode 100644 aoc_2022/day-20/.gitkeep create mode 100644 aoc_2022/day-21/.gitkeep create mode 100644 aoc_2022/day-22/.gitkeep create mode 100644 aoc_2022/day-23/.gitkeep create mode 100644 aoc_2022/day-24/.gitkeep create mode 100644 aoc_2023/day0/input.txt create mode 100644 aoc_2023/day0/main_1.js create mode 100644 aoc_2023/day0/main_2.js delete mode 100644 day-00/.gitkeep delete mode 100755 day-00/sol.sh delete mode 100644 day-01/.gitkeep delete mode 100644 day-01/sol.c delete mode 100644 day-02/.gitkeep delete mode 100644 day-02/sol.clj delete mode 100644 day-03/.gitkeep delete mode 100644 day-03/sol.lisp delete mode 100644 day-04/.gitkeep delete mode 100755 day-04/a.out delete mode 100644 day-04/sol.cpp delete mode 100644 day-05/.gitkeep delete mode 100644 day-05/sol.exs delete mode 100644 day-06/.gitkeep delete mode 100644 day-06/package.json delete mode 100644 day-06/sol.js delete mode 100644 day-07/.gitkeep delete mode 100644 day-07/sol.hs delete mode 100644 day-08/.gitkeep delete mode 100644 day-09/.gitkeep delete mode 100644 day-10/.gitkeep delete mode 100644 day-11/.gitkeep delete mode 100644 day-11/sol.py delete mode 100644 day-12/.gitignore delete mode 100644 day-12/.gitkeep delete mode 100644 day-12/package-lock.json delete mode 100644 day-12/package.json delete mode 100644 day-12/sol.ts delete mode 100644 day-12/tsconfig.json delete mode 100644 day-13/.gitkeep delete mode 100644 day-13/sol.java delete mode 100644 day-14/.gitkeep delete mode 100644 day-15/.gitkeep delete mode 100644 day-16/.gitkeep delete mode 100644 day-17/.gitkeep delete mode 100644 day-18/.gitkeep delete mode 100644 day-19/.gitkeep delete mode 100644 day-20/.gitkeep delete mode 100644 day-21/.gitkeep delete mode 100644 day-22/.gitkeep delete mode 100644 day-23/.gitkeep delete mode 100644 day-24/.gitkeep diff --git a/README.md b/README.md deleted file mode 100644 index 5ce862f..0000000 --- a/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# AOC 2022 - -## Goal Languages - -- [x] BASH - - [Day 0](./day-00) -- [x] C - - [Day 1](./day-01) -- [x] Clojure - - [Day 2](./day-02) -- [x] Common LISP - - [Day 3](./day-03) -- [x] C++ - - [Day 4](./day-04) -- [] Dart -- [x] Elixir - - [Day 5](./day-05) -- [] Emacs Lisp -- [x] Haskell - - [Day 7](./day-07) -- [x] Java - - [Day 13](./day-13) -- [x] JavaScript - - [Day 6](./day-06) -- [] Kotlin -- [] PHP -- [x] Python - - [Day 11](./day-11) -- [] Ruby -- [x] TypeScript - - [Day 12](./day-12) - diff --git a/aoc_2022/README.md b/aoc_2022/README.md new file mode 100644 index 0000000..5ce862f --- /dev/null +++ b/aoc_2022/README.md @@ -0,0 +1,32 @@ +# AOC 2022 + +## Goal Languages + +- [x] BASH + - [Day 0](./day-00) +- [x] C + - [Day 1](./day-01) +- [x] Clojure + - [Day 2](./day-02) +- [x] Common LISP + - [Day 3](./day-03) +- [x] C++ + - [Day 4](./day-04) +- [] Dart +- [x] Elixir + - [Day 5](./day-05) +- [] Emacs Lisp +- [x] Haskell + - [Day 7](./day-07) +- [x] Java + - [Day 13](./day-13) +- [x] JavaScript + - [Day 6](./day-06) +- [] Kotlin +- [] PHP +- [x] Python + - [Day 11](./day-11) +- [] Ruby +- [x] TypeScript + - [Day 12](./day-12) + diff --git a/aoc_2022/day-00/.gitkeep b/aoc_2022/day-00/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-00/sol.sh b/aoc_2022/day-00/sol.sh new file mode 100755 index 0000000..441efb2 --- /dev/null +++ b/aoc_2022/day-00/sol.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# USAGE: ./sol.sh (n: top elves) + +NUM_ELVES=${1:-3} + +declare -a ELVES=() +for (( i = 0; i<$NUM_ELVES; i++)) +do + ELVES+=(0) +done + + +add_to_elves () { + local max=$1 + for (( i = 0; i<${NUM_ELVES}; i++)); + do + local tmp="${ELVES[$i]}"; + if [[ $max -ge $tmp ]]; + then + ELVES[$i]=$max + max=$tmp + fi + done +} + +CURRENT_ELF=0 +while read -r line +do + if [[ -z "$line" ]]; + then + add_to_elves $CURRENT_ELF + CURRENT_ELF=0 + else + CURRENT_ELF=$((CURRENT_ELF+line)) + fi +done < input + +echo "MAX ELF = ${ELVES[0]}" +echo "sum(TOP $NUM_ELVES ELVES) = $(printf "%s\n" $(echo "${ELVES[*]}") | paste -sd+ - | bc)" diff --git a/aoc_2022/day-01/.gitkeep b/aoc_2022/day-01/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-01/sol.c b/aoc_2022/day-01/sol.c new file mode 100644 index 0000000..612692a --- /dev/null +++ b/aoc_2022/day-01/sol.c @@ -0,0 +1,74 @@ +#include + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +/* + USAGE: ./sol +*/ + +int get_my_score(char elf, char me) +{ + int elf_choice = (int)(elf - 'A') + 1; + int my_choice = (int)(me - 'X') + 1; + int i_won = 0; + if (elf_choice == my_choice) + return my_choice + 3; + + switch (elf_choice + my_choice) + { + case 3: + i_won = (elf_choice == 1); + break; + case 4: + i_won = (elf_choice == 3); + break; + case 5: + i_won = (elf_choice == 2); + break; + } + + return my_choice + i_won * 6; +} + +const int wins[3] = {2, 3, 1}; +const int loss[3] = {3, 1, 2}; + +int get_my_score_2(char elf, char me) +{ + int elf_choice = (int)(elf - 'A') + 1; + int outcome = (int)(me - 'X') + 1; + + if (outcome == 2) + return elf_choice + 3; + + if (outcome == 1) + return loss[elf_choice - 1]; + return 6 + wins[elf_choice - 1]; +} + +int main(int argc, char *argv[]) +{ + char *fileName = argv[1]; + + FILE *file = fopen(fileName, "r"); + char line[256]; + char elf, me; + + int score1 = 0; + int score2 = 0; + while (1) + { + int i = fscanf(file, "%c %c\n", &elf, &me); + if (i == EOF) + break; + score1 += get_my_score(elf, me); + score2 += get_my_score_2(elf, me); + } + + printf("Score one: %d\n", score1); + printf("Score two: %d\n", score2); + + fclose(file); + return 0; +} diff --git a/aoc_2022/day-02/.gitkeep b/aoc_2022/day-02/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-02/sol.clj b/aoc_2022/day-02/sol.clj new file mode 100644 index 0000000..99783cc --- /dev/null +++ b/aoc_2022/day-02/sol.clj @@ -0,0 +1,34 @@ +(require '[clojure.java.io]) + +(defn find-recurring-characters [strs] + (reduce (fn [a x] + (into #{} (filter #(contains? a %) x))) + (into #{} (first strs)) + strs)) + +(defn get-priority [c] + (if (>= c 97) + (- c 96) + (- c 38))) + +(defn obtain-total-priorities [rucksacks] + (reduce + (map (fn [line] + (let [half (/ (count line) 2)] + (get-priority (int + (first (find-recurring-characters + (list (subs line 0 half) + (subs line half)))))))) + rucksacks))) + +(defn obtain-total-priorities-2 [rucksacks] + (reduce + (map (fn [lines] + (get-priority (int (first (find-recurring-characters lines))))) + (partition 3 rucksacks)))) + +(defn main [] + (with-open [rdr (clojure.java.io/reader "input")] + (println (obtain-total-priorities (line-seq rdr)))) + (with-open [rdr (clojure.java.io/reader "input")] + (println (obtain-total-priorities-2 (line-seq rdr)))) + (System/exit 0)) +(main) \ No newline at end of file diff --git a/aoc_2022/day-03/.gitkeep b/aoc_2022/day-03/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-03/sol.lisp b/aoc_2022/day-03/sol.lisp new file mode 100644 index 0000000..7f9ba90 --- /dev/null +++ b/aoc_2022/day-03/sol.lisp @@ -0,0 +1,33 @@ +(ql:quickload "cl-ppcre") + +(defun get-ranges (line) + (ppcre:register-groups-bind ((#'parse-integer first second third fourth)) + ("(\\d+)-(\\d+),(\\d+)-(\\d+)" line :sharedp t) + `((,first ,second) (,third ,fourth)))) + +(defun ranges-may-subset-of-one (a b) + (member-if + (lambda (r) + (and + (>= (caar r) (caadr r)) + (<= (cadar r) (cadadr r)))) + `((,a ,b) (,b ,a)))) + +(defun range-is-contained-at-all (a b) + (and + (<= (car a) (cadr b)) + (>= (cadr a) (car b)))) + +(defun main () + (let ((lines (uiop:read-file-lines "input"))) + (print + (mapcar (lambda (f) + (reduce (lambda (a x) + (if (apply f (get-ranges x)) + (1+ a) + a)) + lines + :initial-value 0)) + '(range-is-contained range-may-be-subset-of-one))))) + +(main) diff --git a/aoc_2022/day-04/.gitkeep b/aoc_2022/day-04/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-04/a.out b/aoc_2022/day-04/a.out new file mode 100755 index 0000000..d31e159 Binary files /dev/null and b/aoc_2022/day-04/a.out differ diff --git a/aoc_2022/day-04/sol.cpp b/aoc_2022/day-04/sol.cpp new file mode 100644 index 0000000..d7847da --- /dev/null +++ b/aoc_2022/day-04/sol.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using stack_type = std::stack; + +enum PROBLEM +{ + PROBLEM_1 = 1, + PROBLEM_2 = 2 +}; + +std::tuple, int> build_stacks(std::vector &lines) +{ + int num_stacks = std::ceil(lines[0].size() / 4.0); + + std::vector stacks(num_stacks); + + std::vector stack_positions(num_stacks, 0); + int lines_of_stacks = 0; + for (std::string line : lines) + { + char l = '1'; + for (int i = 0; i < line.size(); ++i) + if (line[i] == l) + { + stack_positions[l - '1'] = i; + l++; + } + if (l == num_stacks + '1') + break; + lines_of_stacks++; + } + + for (int i = lines_of_stacks - 1; i >= 0; i--) + for (int j = 0; j < num_stacks; ++j) + if (lines[i][stack_positions[j]] != ' ') + stacks[j].push(lines[i][stack_positions[j]]); + + return std::make_tuple(stacks, lines_of_stacks); +} + +std::string solve(std::vector &stacks, std::vector &lines, int start_from, PROBLEM problem) +{ + stack_type curr; + for (auto line = lines.begin() + start_from; line != lines.end(); ++line) + { + std::istringstream iss(*line); + std::string word; + int from = 0, to = 0, amount = 0; + + while (iss >> word >> amount >> word >> from >> word >> to) + ; + + if (problem == PROBLEM_1) + for (int i = 0; i < amount; ++i) + { + stacks[to - 1].push(stacks[from - 1].top()); + stacks[from - 1].pop(); + } + else + { + for (int i = 0; i < amount; ++i) + { + curr.push(stacks[from - 1].top()); + stacks[from - 1].pop(); + } + for (int i = 0; i < amount; ++i) + { + stacks[to - 1].push(curr.top()); + curr.pop(); + } + } + } + + std::string result; + for (auto &stack : stacks) + result += stack.top(); + return result; +} + +int main() +{ + std::ifstream input("input"); + std::vector lines; + for (std::string line; std::getline(input, line);) + lines.push_back(line); + + auto [stacks, start_from] = build_stacks(lines); + std::cout << "Solve 1: " << solve(stacks, lines, start_from + 1, PROBLEM_1) << std::endl; + auto [stacks2, start_from2] = build_stacks(lines); + std::cout << "Solve 2: " << solve(stacks2, lines, start_from2 + 1, PROBLEM_2) << std::endl; + + return 0; +} diff --git a/aoc_2022/day-05/.gitkeep b/aoc_2022/day-05/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-05/sol.exs b/aoc_2022/day-05/sol.exs new file mode 100644 index 0000000..e1dab2b --- /dev/null +++ b/aoc_2022/day-05/sol.exs @@ -0,0 +1,28 @@ +defmodule Solution do + def solve(input, chunk) do + (String.split(input, "", trim: true) + |> Enum.chunk_every(chunk, 1, :discard) + |> Enum.map(fn window -> + Enum.reduce(window, %{}, fn char, acc -> + Map.put(acc, char, Map.get(acc, char, 0) + 1) + end) + end) + |> Enum.find_index(fn letter_counts -> + Enum.all?(letter_counts, fn {_key, value} -> + value == 1 + end) + end)) + chunk + end + + def main do + input = File.read!("input") + + solve(input, 4) + |> IO.inspect() + + solve(input, 14) + |> IO.inspect() + end +end + +Solution.main() diff --git a/aoc_2022/day-06/.gitkeep b/aoc_2022/day-06/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-06/package.json b/aoc_2022/day-06/package.json new file mode 100644 index 0000000..3dbc1ca --- /dev/null +++ b/aoc_2022/day-06/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/aoc_2022/day-06/sol.js b/aoc_2022/day-06/sol.js new file mode 100644 index 0000000..28b7b0d --- /dev/null +++ b/aoc_2022/day-06/sol.js @@ -0,0 +1,115 @@ +import input from "fs"; + +class File { + constructor(name, size, parent) { + this.name = name; + this.fileSize = size; + this.parent = parent; + } + + size() { + return this.fileSize; + } +} + +class Directory { + constructor(name, parent) { + this.children = []; + this.name = name; + this.parent = parent; + } + + add(child) { + this.children.push(child); + } + + size() { + return this.children.reduce((acc, child) => acc + child.size(), 0); + } + + searchDirectoresOfSizePredicate(sizeP) { + const dirs = []; + for (const child of this.children) { + if (child instanceof Directory) { + if (sizeP(child.size())) { + dirs.push(child); + } + dirs.push(...child.searchDirectoresOfSizePredicate(sizeP)); + } + } + return dirs; + } +} + +class OS { + constructor() { + this.root = new Directory("/", null); + + this.current = this.root; + } + + cd(path) { + if (path === "/") { + this.current = this.root; + } else if (path === ".." && this.current.parent) { + this.current = this.current.parent; + } else { + this.current = this.current.children.find((child) => child.name === path); + } + } + + printFs() { + const print = (dir, depth) => { + for (const child of dir.children) { + console.log(" ".repeat(depth) + child.name); + if (child instanceof Directory) { + print(child, depth + 1); + } + } + }; + + print(this.root, 0); + } +} + +const main = () => { + const os = new OS(); + const lines = input.readFileSync("input", "utf8").split("\n"); + + let currentCommand = null; + for (const line of lines) { + if (line.startsWith("$")) { + const [command, path] = line.split(" ").splice(1); + if (command == "cd") os.cd(path); + currentCommand = command; + } else if (currentCommand == "ls") { + const [dirOrSize, name] = line.split(" "); + if (dirOrSize === "dir") { + const dir = new Directory(name, os.current); + os.current.add(dir); + } else { + const file = new File(name, parseInt(dirOrSize), os.current); + os.current.add(file); + } + } + } + + //os.printFs(); + + console.log( + os.root + .searchDirectoresOfSizePredicate((size) => size <= 100000) + .reduce((a, x) => a + x.size(), 0) + ); + + const rootSize = os.root.size(); + const freeSpace = 70000000 - rootSize; + console.log( + [...os.root.searchDirectoresOfSizePredicate(() => true), os.root] + .map((x) => x.size()) + .filter((x) => freeSpace + x >= 30000000) + .reduce((a, x) => Math.min(a, x), Infinity) + ); +}; + +main(); diff --git a/aoc_2022/day-07/.gitkeep b/aoc_2022/day-07/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-07/sol.hs b/aoc_2022/day-07/sol.hs new file mode 100644 index 0000000..c6b8c35 --- /dev/null +++ b/aoc_2022/day-07/sol.hs @@ -0,0 +1,114 @@ +import Data.List (find, transpose) +import qualified Data.Set as Set +import qualified Data.Text as Text +import qualified Data.Text.IO as Text + +countVisibleTrees :: + [[Int]] -> [Int] -> Int -> (Set.Set (Int, Int)) -> (Set.Set (Int, Int)) +countVisibleTrees [] _ _ seen = seen +countVisibleTrees (row:rows) maxTrees depth seen = + countVisibleTrees + rows + (zipWith (\x y -> max x y) row maxTrees) + (depth + 1) + (foldl + (\acc x -> Set.insert x acc) + seen + (zipWith + (\i x -> + if x == 1 + then (depth, i) + else (0, 0)) + [0 ..] + (zipWith + (\x y -> + if x > y + then 1 + else 0) + row + maxTrees))) + +treeScore :: [[Int]] -> (Int, Int) -> Int -> Int -> [Int] +treeScore digits (x, y) width height = + let currentHeight = ((digits !! y) !! x) + in [ (case (find + (\x -> (digits !! y) !! x >= currentHeight) + [(x + 1) .. (width - 1)]) of + Just value -> (value - x) + Nothing -> (width - x - 1)) + , (case (find + (\x -> (digits !! y) !! x >= currentHeight) + (reverse [0 .. (x - 1)])) of + Just value -> (x - value) + Nothing -> x) + , (case (find + (\y -> (digits !! y) !! x >= currentHeight) + (reverse [0 .. (y - 1)])) of + Just value -> (y - value) + Nothing -> y) + , (case (find + (\y -> (digits !! y) !! x >= currentHeight) + [(y + 1) .. (height - 1)]) of + Just value -> (value - y) + Nothing -> (height - y - 1)) + ] + +getDigitsFromString :: String -> [Int] +getDigitsFromString = map (read . (: "")) + +rotl :: [[Int]] -> [[Int]] +rotl = reverse . transpose + +rotr :: [[Int]] -> [[Int]] +rotr = transpose . reverse + +main = do + ls <- fmap Text.lines (Text.readFile "input") + let digits = map (getDigitsFromString . Text.unpack) ls + let height = length digits + let width = length (head digits) + let topDownSeen = + countVisibleTrees digits (take width (repeat (-1))) 0 Set.empty + let rightLeftSeen = + Set.map + (\x -> ((snd x), width - (fst x) - 1)) + (countVisibleTrees + (rotl digits) + (take height (repeat (-1))) + 0 + Set.empty) + let downTopSeen = + Set.map + (\x -> (height - (fst x) - 1, (snd x))) + (countVisibleTrees + (reverse digits) + (take width (repeat (-1))) + 0 + Set.empty) + let leftRightSeen = + Set.map + (\x -> (height - (snd x) - 1, (fst x))) + (countVisibleTrees + (rotr digits) + (take height (repeat (-1))) + 0 + Set.empty) + let allSeen = + (foldl + (\acc x -> Set.union acc x) + Set.empty + [topDownSeen, rightLeftSeen, downTopSeen, leftRightSeen]) + print (Set.size allSeen) + print + (maximum + (map + (\y -> + maximum + (map + (\x -> + (foldl + (\acc x -> acc * x) + 1 + (treeScore digits (x, y) width height))) + [0 .. (width - 1)])) + [0 .. (height - 1)])) diff --git a/aoc_2022/day-08/.gitkeep b/aoc_2022/day-08/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-09/.gitkeep b/aoc_2022/day-09/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-10/.gitkeep b/aoc_2022/day-10/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-11/.gitkeep b/aoc_2022/day-11/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-11/sol.py b/aoc_2022/day-11/sol.py new file mode 100644 index 0000000..9da8cec --- /dev/null +++ b/aoc_2022/day-11/sol.py @@ -0,0 +1,67 @@ + +def get_neighbors(grid, current): + neighbors = [] + y, x = current + cur_height = ord(grid[y][x]) + if (grid[y][x] == "S"): + cur_height = ord("a") + for i in range(-1, 2): + for j in range(-1, 2): + if i == 0 and j == 0 or (i != 0 and j != 0): + continue + if (y + i) < 0 or (y + i) >= len(grid): + continue + if (x + j) < 0 or (x + j) >= len(grid[y + i]): + continue + new_height = ord(grid[y + i][x + j]) + if (grid[y + i][x + j] == "E"): + new_height = ord("z") + if abs(new_height - cur_height) <= 1 or new_height <= cur_height: + neighbors.append((y + i, x + j)) + return neighbors + +def bfs(grid, start, end): + queue = [] + queue.append(start) + visited = {} + visited[start] = 0 + while queue: + current = queue.pop(0) + if current == end: + return visited[current] + for neighbor in get_neighbors(grid, current): + if neighbor not in visited: + queue.append(neighbor) + visited[neighbor] = visited[current] + 1 + return False + +def main(): + file = open("input", "r") + grid = file.readlines() + file.close() + + start = (0, 0) + end = (0, 0) + + for i in range(len(grid)): + for j in range(len(grid[i])): + if grid[i][j] == "S": + start = (i, j) + elif grid[i][j] == "E": + end = (i, j) + + best = bfs(grid, start, end) + print(best) + + for i in range(len(grid)): + for j in range(len(grid[i])): + if grid[i][j] == "a": + this_as_start = bfs(grid, (i, j), end) + if this_as_start and this_as_start < best: + best = this_as_start + + print(best) + + +if __name__ == "__main__": + main() diff --git a/aoc_2022/day-12/.gitignore b/aoc_2022/day-12/.gitignore new file mode 100644 index 0000000..5bf19b0 --- /dev/null +++ b/aoc_2022/day-12/.gitignore @@ -0,0 +1,3 @@ +build/ +sol.js +node_modules/ diff --git a/aoc_2022/day-12/.gitkeep b/aoc_2022/day-12/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-12/package-lock.json b/aoc_2022/day-12/package-lock.json new file mode 100644 index 0000000..15123cd --- /dev/null +++ b/aoc_2022/day-12/package-lock.json @@ -0,0 +1,46 @@ +{ + "name": "day-12", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "devDependencies": { + "@types/node": "^18.11.14", + "typescript": "^4.9.4" + } + }, + "node_modules/@types/node": { + "version": "18.11.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.14.tgz", + "integrity": "sha512-0KXV57tENYmmJMl+FekeW9V3O/rlcqGQQJ/hNh9r8pKIj304pskWuEd8fCyNT86g/TpO0gcOTiLzsHLEURFMIQ==", + "dev": true + }, + "node_modules/typescript": { + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", + "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + } + }, + "dependencies": { + "@types/node": { + "version": "18.11.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.14.tgz", + "integrity": "sha512-0KXV57tENYmmJMl+FekeW9V3O/rlcqGQQJ/hNh9r8pKIj304pskWuEd8fCyNT86g/TpO0gcOTiLzsHLEURFMIQ==", + "dev": true + }, + "typescript": { + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", + "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "dev": true + } + } +} diff --git a/aoc_2022/day-12/package.json b/aoc_2022/day-12/package.json new file mode 100644 index 0000000..cfc736a --- /dev/null +++ b/aoc_2022/day-12/package.json @@ -0,0 +1,9 @@ +{ + "devDependencies": { + "@types/node": "^18.11.14", + "typescript": "^4.9.4" + }, + "scripts": { + "build": "tsc" + } +} diff --git a/aoc_2022/day-12/sol.ts b/aoc_2022/day-12/sol.ts new file mode 100644 index 0000000..7143403 --- /dev/null +++ b/aoc_2022/day-12/sol.ts @@ -0,0 +1,59 @@ +import * as input from "fs"; + +type NestedNumbers = Array; + +const compare = ( + a: NestedNumbers | number, + b: NestedNumbers | number +): boolean => { + if (typeof a === typeof b && typeof b === "number") return a < b; + if (Array.isArray(a) && Array.isArray(b)) { + for (let i = 0; i < a.length; i++) { + if (i >= b.length) return false; + if (compare(a[i], b[i])) return true; + if (compare(b[i], a[i])) return false; + } + return compare(a.length, b.length); + } + return compare(Array.isArray(b) ? [a] : a, Array.isArray(a) ? [b] : b); +}; + +const main = (): void => { + const lines: NestedNumbers[] = input + .readFileSync("input", "utf-8") + .split("\n") + .filter((x) => x) + .map((x) => JSON.parse(x)); + + const pairs: [NestedNumbers, NestedNumbers][] = []; + for (let i = 0; i < lines.length; i += 2) { + const pair: [NestedNumbers, NestedNumbers] = [lines[i], lines[i + 1]]; + pairs.push(pair); + } + + console.log( + pairs.reduce((acc, [a, b], i) => acc + (compare(a, b) ? i + 1 : 0), 0) + ); + + lines.push([[2]]); + lines.push([[6]]); + + const sorted = lines.sort((a, b) => { + if (compare(a, b)) return -1; + if (compare(b, a)) return 1; + return 0; + }); + + const isPacket = (num: number) => (x: NestedNumbers) => + Array.isArray(x) && + x.length === 1 && + Array.isArray(x[0]) && + x[0].length === 1 && + x[0][0] === num; + + console.log( + (sorted.findIndex(isPacket(6)) + 1) * (sorted.findIndex(isPacket(2)) + 1) + ); +}; + +main(); diff --git a/aoc_2022/day-12/tsconfig.json b/aoc_2022/day-12/tsconfig.json new file mode 100644 index 0000000..75dcaea --- /dev/null +++ b/aoc_2022/day-12/tsconfig.json @@ -0,0 +1,103 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} diff --git a/aoc_2022/day-13/.gitkeep b/aoc_2022/day-13/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-13/sol.java b/aoc_2022/day-13/sol.java new file mode 100644 index 0000000..7613dcd --- /dev/null +++ b/aoc_2022/day-13/sol.java @@ -0,0 +1,147 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Scanner; +import java.awt.Point; +import java.util.Set; + +public class sol { + enum PROBLEM { + PROBLEM_1, PROBLEM_2 + } + + class Grid { + private Set sand; + private Set filled; + private Point source; + private int maxYP2; + + public Grid(Point source, ArrayList> paths) { + this.sand = new HashSet(); + this.filled = new HashSet(); + this.source = source; + + for (ArrayList path : paths) + for (int i = 1; i < path.size(); i++) { + Point p1 = path.get(i - 1); + Point p2 = path.get(i); + for (int x = Math.min(p1.x, p2.x); x <= Math.max(p1.x, p2.x); x++) + for (int y = Math.min(p1.y, p2.y); y <= Math.max(p1.y, p2.y); y++) + this.filled.add(new Point(x, y)); + } + + maxYP2 = bottomRight().y + 1; + } + + public boolean addSandGrain(PROBLEM problem) { + Point p = new Point(this.source.x, this.source.y); + while (true) { + if (this.filled.contains(p) || (problem == PROBLEM.PROBLEM_2 && p.y >= maxYP2)) { + if (problem == PROBLEM.PROBLEM_2 && p.x == this.source.x && p.y == this.source.y) + return false; + + p.y--; + filled.add(p); + sand.add(p); + return true; + } + + if (problem == PROBLEM.PROBLEM_1 && p.y >= bottomRight().y) + return false; + + p.y++; + if (this.filled.contains(new Point(p.x, p.y))) { + if (!this.filled.contains(new Point(p.x - 1, p.y))) + p.x--; + else if (!this.filled.contains(new Point(p.x + 1, p.y))) + p.x++; + } + } + } + + public Point topLeft() { + return new Point( + filled.stream().min((p1, p2) -> p1.x - p2.x).get().x, + filled.stream().min((p1, p2) -> p1.y - p2.y).get().y); + } + + public Point bottomRight() { + return new Point( + filled.stream().max((p1, p2) -> p1.x - p2.x).get().x, + filled.stream().max((p1, p2) -> p1.y - p2.y).get().y); + } + + public void print() { + Point topLeft = topLeft(); + Point bottomRight = bottomRight(); + + Point curr = new Point(topLeft.x, topLeft.y); + for (; curr.y <= bottomRight.y; curr.y++) { + for (; curr.x <= bottomRight.x; curr.x++) { + if (sand.contains(curr)) + System.out.print("o"); + else if (filled.contains(curr)) + System.out.print("#"); + else + System.out.print("."); + } + curr.x = topLeft.x; + System.out.println(); + } + } + } + + public static ArrayList> parsePaths(ArrayList inputList) { + ArrayList> paths = new ArrayList>(); + for (String line : inputList) { + ArrayList path = new ArrayList(); + + String[] points = line.split(" -> "); + for (String point : points) { + String[] coords = point.split(","); + path.add(new Point(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]))); + } + + paths.add(path); + } + return paths; + } + + public static ArrayList getInputLines(String file) { + ArrayList inputList = new ArrayList(); + + try { + File input = new File(file); + Scanner sc = new Scanner(input); + + while (sc.hasNextLine()) + inputList.add(sc.nextLine()); + + sc.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + return inputList; + } + + public static void main(String[] args) { + ArrayList> paths = parsePaths(getInputLines("input")); + + sol s = new sol(); + Grid gridP1 = s.new Grid(new Point(500, 0), paths); + int i = 0; + for (; gridP1.addSandGrain(PROBLEM.PROBLEM_1); i++) { + // gridP1.print(); + } + System.out.println(i); + + Grid gridP2 = s.new Grid(new Point(500, 0), paths); + i = 0; + for (; gridP2.addSandGrain(PROBLEM.PROBLEM_2); i++) { + // gridP2.print(); + } + System.out.println(i); + } +} \ No newline at end of file diff --git a/aoc_2022/day-14/.gitkeep b/aoc_2022/day-14/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-15/.gitkeep b/aoc_2022/day-15/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-16/.gitkeep b/aoc_2022/day-16/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-17/.gitkeep b/aoc_2022/day-17/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-18/.gitkeep b/aoc_2022/day-18/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-19/.gitkeep b/aoc_2022/day-19/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-20/.gitkeep b/aoc_2022/day-20/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-21/.gitkeep b/aoc_2022/day-21/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-22/.gitkeep b/aoc_2022/day-22/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-23/.gitkeep b/aoc_2022/day-23/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2022/day-24/.gitkeep b/aoc_2022/day-24/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/aoc_2023/day0/input.txt b/aoc_2023/day0/input.txt new file mode 100644 index 0000000..143e7a3 --- /dev/null +++ b/aoc_2023/day0/input.txt @@ -0,0 +1,1000 @@ +kjrqmzv9mmtxhgvsevenhvq7 +four2tszbgmxpbvninebxns6nineqbqzgjpmpqr +rkzlnmzgnk91zckqprrptnthreefourtwo +fouronevzkbnzm6seven47 +zphgdcznqsm2 +4gjnmxtrbflgp71 +4sqvv1cnpn +8sevengzfvjrhnsb6ddb8ninerkgkxthtfkvbcmqs +1seven336 +86one34vvvgdngbt39 +37qdmsqzsq72clfntfxqfrhbxtmfourzcjxfmmfz +3rxgts +skhcdbnrninethree5 +qtkhfdsixnine3bvpcpmjbzjonefivethree3 +seven4six51zlrvqmbgpzplxtk6ptcr +eightczxhbntwo9sl83 +42m1ndvqkz16seven +three9oneeightmqbtwo +vt81pzcchsvz +eight6349jr +8czmcdhjzpsbpjgngdvtxczgsl6th36 +gbddhhhhkgjltwothree57 +pjjlddnvtwo884 +eight5fbcxqlqkplm +cdzgbtxbzl43vvnx +onefxtprsml8fqptvmfthreesix2jbeightwor +nine8twolrpzp +eightvjdzfmqlvceightnine6rlpzkdmk +8tqmjgpfzrnineeightpcfltmzn8 +9nnnh +49onefour7fivezchhjrpbmteightwokrs +7zqhjkjkmm7448 +ninebndfdjbxx9sixltsjbsbgone45kpcln +zhqkrndh5 +p61five44cvgxlgkdseven +8two4kpdxdf +two773t1rcdvxldjrjjq +lnqhgfivebdhpshzfiveonefivejsqzzdxq7 +72vlqqdtwo4xdzlreight7 +27zpq4one +xczj475 +2two3seven9rshkhrjzlv2 +onethree222 +fgeight6threegkjcgzjsfxqksgqvhnrhqf +sixsix8twotwoone +five3qr3two +76zxcjmfq +xchtklzgtwo4lbvnsix +cffmlvmsvnlrtgkstmqsdone9mdlkdgpgeightwogd +3onethree +lrdtfive3six +foursixsixntwoeightthree9zmcmxdn +threefmqjzhzdseight8dfkbstnineeighttlzhjrrgcl7 +7msqnfdbbseventwofivesixrrqgsvxn3 +64dlmxn +3two7vrv2rlqc4nine +rmxqpktrxsixsix634 +tjlrqkj1 +dthree2qhhnbeight5two +zjvvmskpnclgnfnjqr7 +two425zfiveeightjmhznf +113njjz +pdchljrdrlntkdn1pc8 +5twom9hpmbggpeightjnddsfbfpsslvvt +one52ctrkkc +dnbtwovcvxggsbsix219 +fivetjmg5sevenjp +131 +8two9khfl +threethreetcghqbv3rbnsdsk4sevennine +stlttkxrsninetwolftchdtcrpfivelmsmgcdpprqx1qh +sptb46rtrzhcmbf3seven7 +six6tntbjjtsdnczlnbeightlsfplsqq6 +33bldlptj2twosevenxk +five8snvmzqcksix7 +vx49six +three7sixfourfxfcljfdhfl6fgktbsxxrrp +4csxnkvmdnfive2rkkppdqln +dpxhgssggqoneqsvp9eightjvgjrjbd9eight +five6xrrzpdp8five44hqxqbnhxslrjfh +fkpcdb2sltktfghhmxdtxxffssxztjngkthree4 +ndhcxeightthree3 +qrrslbfxklbxnine99lcdtpbf +mvmcg5three +g9one +2ninegdsix3kb9ninerssqbpxgs +blfclcvsh8seventwo8fourznjjssvtlg +ppjdvrxb6eight37cnqmgl9dghbrgrnine +nine6zzcvprthreefive +8fourshkcchfb4sixlv +9tpqqs3qxvqhqmb2 +fljrhvnr722threetpghbftdt +2five2bhhq +18jhhzczcncjnjjx +jgvzzrklz8svzfcgzgggseven +8rdjdvmvcheightrvkpcmjnshhltgghf41 +9three4cffsxc5vhcvdcqtv +86tghvbgthreebkrgf6one +331s2twonep +rtvz4bsdzqeightwodth +3vggdskpcdjfivezpjgrfsqone4z85 +xsftxsrk6threeconesevenncvs8nine +3two2xjrqhrzjv +smdmb1gnlbvkq5nrmqmc +qmmpthreenine7sixczhlfttvphzkbqnm +2rmsrzrbgfjrones +81bmfddsmngkqpq5zsnrcnhqt +two1lzf4two +4sixonetwobzvll +eightpggvssixfivelpm4three1hz +77nine3ninefive7 +oneninerhplrfsxlltwonineszhdqskt9 +lxvtzvjzrreight931 +38z +zfxtdnbqtwoseven1grtpbonenk +fivesixkbzcbvcn76pdclljqsix18 +mrxtfour5vkkmshbmpx2fourtwocpdzkmspqxqrvf +8sevenfiveqvbsnine +onetcdfdtnsthree21four +3zqcbvdftwotttfdvtmtxvhrsixtwo +lqmxvcplqs8bhsixb97 +bmvxz27sixtwocvhtmqlls73 +five1lvzzbv +5oneqdcztvjsqmjf6 +61hjj4onetqlgkllr +sixthree9five +8sevenjqgvlfoureightqnghxptsmc6xmrrnzd +ftjbhzkmvtwooneninenine9sevenqgb +onesixtworksmtc3 +3oner65 +3trmpzmc622 +seven14 +xfgbmsixeight6twocsevenzx6 +3xfdpbpnzzkdrbmrdjrtsrvx37 +nflclprfgnt7 +fiventkj8three4twolkrztseven +19tbgcfourseven +9onefour54seven +hkmfqcnpncfzgrplqq9xqklcb +ninemxhkpspbqn69zmlsbtsevensixfive4 +zvfmhfjflscnqskzgnz74jlxrzm3 +fiveeightvdqtlcfzzrpfd7eightwosn +2nineone7fourninethreeeightsix +ppzf4five9threeseven +six1kzczzlssp84three +885dlzlnnfth1xthreetfm +vqmntfbqgt6four57six5 +mqgmbp3 +threesix3one33seven +46sixptwoone1vnnqlmrr +vvmcjdbjbthreeljznqhh5ztwodj8eight +rxhxx6ninesixeightrxffqrgdqx +ninefive2twoccpxbfcfkzpzhsf243 +fourmvxpxsglhthreeone4jlgsfvxhmmjt1eight +9crfpmnine19four6vkbsdfqn +6ninekxjcfxfthreejpfmtjjbeightone +xknxrr6threeglmjzxpvxmfivethreezn +7five737 +1qstxdtctlk94gtnqvfxmbjtnlkconetlkdmqgrxz +6mgqtjq +4pt +eightjkdl54one5eighttwofour +ttjblsrrl2three +mtwone8onethreecprdhtdgxvdqcptplmsixtwo +tqlkbkjrclseven9lprrcpnxv5zs +seven94mgljdpp8fourfour +htxchhjv6fivethree +gprqsxbnlpls2two +7cjtrglplbm7pdbvjtnineonerqnkt8 +8onezjrxcsfjfoursz2seven +mcrpvnlsix8fourdblmxkhcsx +413zsixhbsxqsplhz +fxqthree99 +onenine46twotwoeight5three +2559nhlsgmknq +sevenonexzxgxkhvln1v +68 +7dcbpcxrm87crhzlmfgk58 +36one81foursevenfourpcnjgf +eightxlbgssonerjfone7ztfftmn2one +eightzkvcbzmceight5four +four79ninefive9sixh5 +2lmggjph5eight +ninetwojhzxf5kpfp +7xvnbfbzpspbfxlpsfrzteightqtvdxnlkp2seven8 +lgblvsjdrnjqfgxlfqh37852six +jtrnmqseven6bqbsdvtzd8ppzmnfmdhkrd +seven5seven676fivelctxb +mctbkczczspvhjfhfivesix3gtnqgkjzc3 +psnhmjsix9 +four4nlrhxflrrtxsixeightwosk +npkxv1grrrrbcsbq67538 +35thrcjrkrdptwo +klsnbcjfpdsrfnsclvnfczjfsixqpdhmmfmcqfive4bmtpctone +zxkncsrktnrv74eighttwonine +jdmfscrdlbj2brseighteight +8ktjrzprt8khpvszbtn +547jrxkhmheightfour +fivetwobpjrjczflhljvdlhl9fivernglhclznzfq +threenzlvrgjonenjbqnlfxhmfourone4mdnld +6jbzzxsix9ninefivebdjmgnzcqqckkl +gone6sevencdmrdbrgh +cssoneighthmmxvqvbfflkjsixone361 +5onekpsevendcrzcgcs7hfvffksqr11 +mfxjbzn9 +6nine4 +cbljjfthree42sixkss5b +36pvqf2cmvvzzdfour8 +ntwone84three +twothree745seven4rsdlbtkoneightrbj +sixfivexfzfjhnzpfv8vz +four8five +bpqrcnj3 +45przmdflrrd +zcbpzhzq2nvjsk +xbrdcttltxnhdfgh33fivepthree +seven5six +3three21tlfxhmlkqx9 +sixkdxjtskknd1nrgbqxjsixbznjqhpfz2 +eighthsfnljrpvqnzpkninebbbjfcshfq5one +nzqbqklqlsixseven56twoonethreeone +nfsixeight5jflseveneight3 +sevensevenp63twoonevxlsgmcfvk +fourgncfdfoursix5mnlhvvml +sixseven66hrqjbkvfrjkmbg +339lnhgjzxbdmfh +pvdnppdt3bxxqvdc +sixmqrcvtzdtsb4 +two9xtsv5 +fourdvt1 +two2cbpqfgszpgbkrrbbnjzh1sixfourtqkns +sevennine6451oneninefourtwonenn +vbxrslkfour7four4qsmlhqvm3 +foureightc3kjvmgtc6eightseven +oneone8bcpmdfcszz4kmrfrd +sixcqpbffcsctccd281sevensixeight +6kxbhq5mnvt9cpbcpzslg77 +cpjfplxvpzqfng4four516three +3eightlnqzzsfhmndftc72 +six2xsdhxgdlfnonenine46sevenseven +qdpdrkrt754 +5twosevenninerg6ninefcvgdtk +six31twox8sevenfourone +8eighthplftwo +41ninejdcvrlplk +9hlnjcjjgdrhvmpvbmdzcmmzjtj2six +3vpvdeighttwo +4sznqlshqmninefourseven +eightthreeseven7 +sevenfourzsfjplg1sevenfour +34zbrvfjqckr8cknzsmpqc1seven7seven +21shklthree59two +7fivefive1gdtf8 +8gzfnxsp6hlpr +nineznbgntvcqjtft24threerkp1jlrdjhlg +3414zzrxbgdvmp +fbjzjffour3lxzmck9 +lsccprmgh1 +33two6ppjhfkcxpthreejm +sixsevenseven33 +3rphhpfdbh1cbmonetwo7five +8hqmcqxcj6two1eighthbkcvvvt +63fourrtfztfvonesevenseven1 +d9ggdsxgnxvdlqhclgstn7 +5fourskvdvntzgmrmsgxqzd +11onenine4eightsix +three4sixkrgfour9fourtwol +8seven2pthreetjxzhrzvxrrfpdfnxsdbshrtnqgmzxsg +twonzbbtjkvtbcxrtszxmdtffkdndzqdfffxckznine5 +two5rljthree64n8seven +fourninetwopnhzzrdmng4 +7vfivemlqgctmzrk +85d7onefour1 +9nine6xddqgvth3six6 +fjszdfnmg7one +m2 +threenqglsjplgbpsixfour7fourninefive +4bszvrqdvninesix6seveneightmfrgnxftkvchk +xnstcjndqzthvczfninendvksmmzzxsjt5 +413f9sevenninesix +21mthreethree +fourmpsgpone6txh376eightwods +onetwo1ninefourfive4twohbb +7hpxlcsh7 +cqtwoneonelgjmxxjkv8 +6threetwotwo93nn +1fmbdzfkkcg +4mqfpxjhmmzfive9sixsevenhckjrrzxqcxnfppjchrh +55xcxtfour +gbpcvzsklsix7eight +83seventwoseven7ninetwo7 +hdstztbpg8twofbtfeightninemzgrx +78kzbqq3686bsnmvnchts5 +689113fbgjtjd +nine1threesevenninefour +6sevenfxrhbxktxfive +3lhpktqh89two4bpheight +85three1dgvtjtg6cdtkhccnhhjfbsxdc +ninebvvhmlkrkllhjsl4five1 +four7pvbvqjxsnfh +882qtlk +8onetk7eight8four4 +cpkjmtpone68twojcmjbfsj7sixtwo +nineslzthree8fqtfckjdkl3 +6five9pkl +1nine48dlxscmvsvpxtcsqhpfxn2 +22fourthree +8dstsdqpffkfivegqmrvqr +6rbdxrvxhsix44 +34three +dnkmhlzq4seven9 +5twohpxxfive8eight +5eightz +jmmzbfk8ltkksfbbskcdrrgfnz21 +eight1zqzr92two56 +bvvmeight4twofour +147gfslhl +dmfz59qsqmxngqxdlbhcxrqbonesix +nine8eight +3ttzjhjdcqk +62nine64ninebktrj15 +mkdfdzxkbfctv47 +vvhsvgjhhonenl7mrhdskxfrr +oneeightgqtp7fiverkvqjtsdeight1nine +eightonethree416gbqgnf +seven144 +twoeightpprtlffourfive5jfjdvcvkd8 +jppmcvlzrg96 +8eightonesevenzcvknjfvdkhrrzfmeight9 +cm97three2 +eightzptfnlgpfive6prrgtjone7vbnfml +threethree1ljbsfqcrsix +njnpsxlfivenine28two +95dneightsevenxdtzbk86 +eightm399lthreeoneqbjjjtwonef +2kzxgfmcseven6qv7eight +bkrkfdfqbbcl84sevenfourpjf +552 +lmccgmxbzfour16zlbrrcgpln +nine7ngkjczfv7ktmvvgqb +qcqtseventwolg8 +foursrbl91rsvtlbqdn6five +sixhvszbkncglchflsevenoneone4fivenmrcgkkvpk +1threetwofive4fiveeight +seven8ghsqbmfzvpzbvvrtmxnhf +4sixfive +3six3sixfourseven5 +hsbprzpjfhflrggjdpdsn23five +zzjqrc7 +737rmjmftkrdkvgs6five +sevenseven81 +four69hdsevensix +jjgqr5pqtwo3one5cgkftvz +seven3threeseven1n6 +7ninenxktnbfiveeighthqmfdlkb +cgrztlh4gsdfjqzqvr2znxzkrjrkmd2eight1 +87eightfourdjbbjkpfpqrqmtfdhjrrfive +qqbglmxcsix8vftfivefvpfivevzvtz +fourpcksixjslx26six7 +mfgleightc15frgtvxdnfour37 +67qbqpsgfcfgsccdt4 +cfpjlxh16 +21sixslgcrgc3two +kmgfivextrdeightnine8sl +6eight62fivekj2clfk3 +fivetwo5three6 +9rzdrhvf4 +62fivetsceightfive6 +847gnmgjjksvdbkklpqsbfbzsffmm +cdtbhbfvgkkh7vhbcqkbjkkcrkhxfive +7onethree3pnsfbhqsgpkgvncs26 +2jkfqkc +sevensixztcfmt88 +nineeightxsfivekfv5 +5one5 +48jjvh4rprbgqzpgr +23six +vztbppbsevenfive88gpmgjkq +2hpnxbssr +2jkgvrsevenntvzdkjzsmnjtcllttbxrnddmjceight +snn2cmvphzbbjlphrdkpqnqssixtwo +threeeightrbeightsevenkcfpn5qjmjbtc +l4four +2two1 +two6zmzvkx5nine +sccjntwo9 +6twothree9nineq +nine749sevensmvggvmfxghvmp5 +4six7sixeight9 +3seventwoxjmh76gllshjm6 +threesevenxkftjzmpc6 +rs4onefhnzkt +6dprgnfhhfhnglddzksbk922 +oneninejgcmvkkhxtsrmgqvninerpqmlmm89 +cdvvddhxc1dtrzjl7nine9rxxkgb +71chdqhbzps8sj +nkqpjmvjkzeightfourthree9sevenfqffcpbdsfks +kjtzdpxnmcvcsixbzcvdnzhnbkn7 +3xnvkmxqhgnzfour5 +4sevenxftdgseven94phsgkflqbpgjs +98jhbgtdlrmjonesix +86625three2one +onefoursixone8bphb6 +eighthkzfnllhk3onethreezfttbtqljd8 +peightcfdlhk9dvdtmbqgcone +ninefqtnjkqvrfbj8nine5 +5vtsntrvfivelpfln3kpkskrbrhbnhrncthree +nine6rpdsrkhzrqthreegkdlhxvzvfzmfive4krbdxjxtjr +eightseven3nine8threethree +sixdvqlt5zp3threemszxfdfiveone +hrtwovfive8ssfmbfsztwodthdlrxtjfive +qmlzrzfj2ccvztbn314 +xvcgcljm6seven6 +two7787fivesnine1 +twodlhhsqseven8twosevenfour9 +gktrrqrffg6sixkpbtldbzj35seven14 +8fivexnxsseven6hjdbbhxlt +cfzmmoneninefour4 +823eighteighthsonenzt +4four6eightkdqljeightthree +5jdpdgml22four +6threefive7eightlzdlcxfvthgrlm7mjkmx +6pldrbjfceightbnktrtqgtrxbt +b5seventhreexl +194zgeight54 +7threethreez1sixthreetwonemr +zcnltvvhjr5vvdvkbnn2 +frcdgbkjmqqzshjkfsixzxkgvmfrkfxqjpbgn5zgsn +sixonenine6 +twotwoninenine6ttxh +nine4three32 +four9three6bgbsqq +seventrseven1three7jxsmnrnlgdf +2sfflb +twohfcr5one +fivetwohgrqtbhx619twonedv +9lcsvtveightninerfxkxvzgpl +sixeight6sixfivethreeoneqj +dfourktxv2msshb8seven12 +sgljk4 +mjgk11eightrlbqpdl +jfdrflpxh489bkjtlj +pftppcr85three +onefivemfsfk3five +5x7twoseven +cqkz8sevenfiveninefnbrht2nine +ninehhm2three986foureight +63ljkvtrtwo9g +dqfour95fiveseven6 +8twozthreetwofive +six91fhzjs +1slknxtrv +psxvkdcsdldxjninejfzblssv5z +bczst26r +btoneight79fninejvhvdccnhtwo +onejcnlqmnhjeight34z5 +clbqcdmzc4mjlxgfournineddtlj6 +1pqqphfgqv5nine +five2tvzshsixfive +8ninedhvzbsvcqgone +bqlgonesix7 +75bltzpqpntwosixtwo +onefxlvlqseven47twoslgffq +nsrnltmf4 +mgshfseven33 +2p24 +jklglqrone3qmjbdgpgzmznd +eight23fkgb2 +187two +vlvncjgmqtwo5771sixftz +lzr9 +chrshzthree5641nine +rnnqlfgfmpscnmgjqvq84 +gzltjddjpb937 +ninethree5 +fouronehvmmfrcgjcnmgcgkjnctnvvqftmdgzds89 +6xjone244 +ninefour8four +49threeq95five +gpeightwothree8lsjgjfourninehseven5 +2kfmzscsvssseveneightsevennine7bfct6 +cbmtfpvsevenvsbbcpkzlqlgsixfghzrnn28 +eightpslnsnnonemqxmmhch42six +2one42bgllqb2 +rjshlfvkkgqzsnttwo3vfourgkplcs +eight96 +16qng4fiveseventhreenine +bldtndftseven9qhhxgmgxd2 +219ninebklfrvppfmzrjnv9g +jvzdghjjv298zkssjc714 +1eighteight +onejkzeight7seven +37five4 +zxqrfpr7lnsqmcrtxkpvxkzjgdsmncvqhvrmnvqzkl +1dxfivepqbvrp3 +krpjpfxbrstwosixkr3dceightwoj +5nineeightjbfzclpdjone2threebddbpxrcjf +rqlfljnktwo57 +tsleightwocdzzmgpxsix4seven +xdvrspvzbx2 +jlbvjskhsnttvzdlhsveightthree9 +5one7jlsnzbbbzxkvrtd +foureight6rpsrtrrzcnvtc8mdqzdxnrsqtcxkskd +gtdxgdj2jlhfltkbmq45zhqcqmzbfninenrvvqcj +seventwoeightonebkcbxqpdhn42 +rrqchvstrmfive3mzmvcrprssbvthrg1twotwo +414nmdkhgfive7seven1llbpxdv +eightfivecflctsdvs262nineseven +sixfive71sthtxdgbbtntqpqnltmf83 +kboneighttwordldqjvvkh4ctntmtvsv +jxmdndmtxhqndfptmnine8three3 +cvmqjmbsm2c3onecvftwofourtwo +one7fkckcjknb2l +onefnbtgpqkghcxlgthreevvlxp94jdrgfvpmf +eightjxktztgfgpnine1threexgfklt +six1llzdnkvn4twotwo +7mfnnptwosix2five +qgzftjcdgs45fivezzvrtjonep +boneightnxggjksdcg8 +2three7mfqvtzlk +fxg8gsffbl84pjvk +sixpj5 +4qbvpfqrnplq2snsfive1hnmkxgszqdseven +9sixcjnqgxtzh4 +2sxmbjxfive2 +9kqcndbqfvs +kvrhxlsbqh7fivethreemmflkfq +khonesix28 +nineeightvhncnbtbp68fone +8eightnine +four71eight +nnvonethreepktq8threed +x373one +flv3nlzxszdbhbdcntp +vm76xr +pksrznbsfg4 +7twobsxjrz1eighttscqzfl +6sixoneightnc +bnvvfour7sixzgxxgctdvfive +qrxoneight7vsdlprzmvneight +5blqzhrdr8ptwoseven7twonefh +j8 +three3938ninethree8 +ctvc2 +sixqdmvtwosixpfour3 +86xqkfzzn +dcjxcj4sevenkglhzcthreesvbkcgxkg +sixcqncsgn6cqfvcl28three +4five6fivetwothreehtpfqvfnvteight +rdcmt3 +4eightzxxfvrp4sixz +sixsevenhcf13qfdnnqml +sevenqzflnkpppvdln5mcztone +twosixqdqdscpzfvzxx4 +seven3six +48four8 +kmsflcqndhnl3onedqfkd7seven +lrtdllmlz3smpvmhsggfjrvheight42fl +vpftvkgzmjl57qgvlsd5 +bkbrkjtpmtwo2gpmkjxnxlfive +eight7three8twonbl +nflq6nine4qrpzclr7 +onefour1hjndfpkndthreetwo2 +gphthpbfeightmsvtdp2six +98two6threemqnscvg3seven +kbrqglhqseven3onetwo13 +rvzddkzftqlnine8hngltmmz +fkeightseven52hptcfivengnrj2 +7sevenfivefourrdbdxh7 +pnjpbvlrd2jfivexflcbseven +four887seven9lc2 +4sixlsxxlqqvpxxhrlhqc +cq5four8 +7threedzdp527eighthxjtzfxv +bdlhgonexrjsfvxghxxchcdd3dpltbbklpvbszm4 +6twonineeightkvhlhlfm +nine6krqqzfive +eight8qzkhfhm +3eightsevennine +eightx38fourf88 +qkjxldk8418n +r15xhtkntq6nxcqvrmfpbvcponeone +ztgf92 +five9vbqlbvkksixtwoone9 +onevjbktjqn4onebxml1gckfssxst63 +fhrhvvst9fivefourxmspzh +3six191dbxtkm +mq5vczknqlqdd4eightvpv +ffourthree4 +four4rvcrlbb96 +95ninelttmq9 +9fivetwothree71five7oneightrt +zvhmfqbzfjtrv19h +57eightvmqfvrjg9 +r2lszmztwo +5919xj +jkmrvxgmzrflqtzkc44onenjftxgm3 +pmjpbdxpgctkninelpgrdjkrrzdpf2 +dxveightwo6psqffzhc5jc +seven5ftzpsvcfzhhtgpdtghpxfmhfjvppkone +822oneoneoneightct +mhzjmppgh7cqpxkmdtlthree1vgkqxcfvpgtwo +78bbrbspqpjkjcprh +eight7hdgm +rpvrvrqtgc87 +6oneqcntnrblvqmm2 +nbsoneight7 +hxfzqzqvsnfive4five44ctbldgcpg +fxvnkksjcz77threemgcgzfrbqzdqtfgnine +qcl45q17 +3gdqztrfjcmz +threebkcvccgsrrp77onetwoccrmtwo +1vmvqqjg58onetwoeight +jknhpr85stqcsfbrbm +three941rlqcpcjmffivecqgzbzjl +44dnnvrlgqsixone +4kkxgggmcbn4bqjrcvdbd4vcgxsvsrk +8fivemgvrcxlhsix4 +twobvccclhj6vtzfhtwofiveninehqsnvcxgfourtwonexrv +3sixvzzdkblrhlgbplqkqeightsnlncvqcxqsix +six9jgsrxknfmfv5four4seven +fourthree1 +1xndxzh +2znktjrsevenrgvc2tcmbbxzj +416nineonebgnninetwoqlpglcvcxc +gone9bjv8 +2gltwof +hhonencqn2dnzhjpfrs3n59 +fourcjmsf3 +mtwothree82four +onefivetwonxv5 +xgvfxzfshr1 +nine15 +21rfhzxlngk2fourfm79 +3cdzbnrvqbbrklrsvxktmghrn6eight +two25gv8sevenkmkprbgzzlkddnine +fiveeightrscknxv1jlhzgjjrxktcvjgqkqqzjqdjgsixvqlhjghsm +33nine39pfgsdtptzbqhfjppp4 +7nftkbhcgtthreethree44 +fivefournrqbl3 +43fzvdptqnq +499four1bdpvvvfnine +9tt +381ldxxmdsgtwonine +pmctnnbdzmxmqrdgcj8sxbpshfzxdnznvtldqj5 +jnhtfjqfive7hvsxqsixnine1 +cnhkqbhtwoonezhdlbxdtdk6 +four5oneonefivehkzcxq9seven4 +onefivexpfour2 +42six2threesixfour5 +8fmqpdhpjv1 +1bnlfgqnseven +tkzcs9ndthree2366 +qttwone5711vjvonesix +nrp62ggmtwo87twofbkpbgtlr +11cgcbfprckdrtzxqlckxhvbjqbslvvnchpkdqfg +1nhkzggnnxhnrbkzjq3nine6one +zvhgzgpvll1dkvbdf5fourfgqqdnp +one1rkpsfddfh6four +hmfxqb9twol4dpfmz4threelkg +xlcmzqgrq7threetwo97 +ntwonedz3dbgngsnshb6bdbtspkzzttvhphqdbz7mpkbpchsf +one586fivethree4ghcgjrqltgeight +1eightone +seven96two2hjxp +9two5bzzfzfive661 +nine12ninefourone8oneightsv +pdlcdbgsc5 +xnpbsr3fourrgjhdzgbxsfbvhhjlthree69seven +qtnxqffour6sixfour9cmnxsrjttonej +psshpgrbhnjhgr7 +428 +7twotwolghmqhkxthreefoursevenzmkzhvs +13hcnzjhsix2 +7four5nxdq3fivesevenfivesix +hzfqzc2fourone34 +7tdr46hrdgjlzkptkqhmsffh +gqc76 +33376 +32three45kvlmcvmmh63slm +842xbtj +lvjzkvqthree2six +64ninentjfiveeightppljppn1d +four8fzvmnfourtwopggbxv +fivexftmjtmxdp7 +sevensjmhskjnmpfnfj55xhgchqcgbsixdrtg +sixccttdcpvklgspscrbronefour3 +foureightnine4jnm +86twofour +fqrpnphnqr98nine7 +fivetwo3 +8dbqjkxjfsgpsixsixeightthreepfmtsnk +9sixonembbhvbmsfseven1 +sixdsvdctxpchvgkggtwocvzvseven8onesix +5lmbjk7nine7szmvnkmz2 +fiveeightfive7xlcszxsevencrxdfzsmccb +lhmvzszvbxxq592 +eight814srjh99 +qdqzvx2sixjp +4fbtjrxs +9ftbf668sixsjninethggtdncsv +4ninezzmbfbjn +75nineonefivesix +ninethreevntrpltfttnlzgn7 +fivefiveseven4seveneight9three +89bspmdgzcm +6jnnmhkfourfive63eightggchjtwonet +6twocsjssxfnfxbqrqrhdfrlzfldf +xhlk7xdmg +64ninesixhhmjhglhp +6fourkm9mnnrbjpjtwozdgtrsseightwox +rjrldgmzthree5kqnjmxpmmr1threefiveeightbjjvk +2bzsevenfour +pkkrrzlnm31gkfvfjpvhfivefour +jtnkdkldq285fiveg +tvzmqone8mqsfeight5 +9nineeight1vnsm6tx6three +24gnthreebzz9six +dvcmqppn7 +one5three3ninedqxqljq +five8gdtthree4jjnhbdkp51gtkmbnjzk +cvsgrlfdflhjp8dvfourninefive +113three26 +6dhfrhjthreebslzctwo85vgjbr +4seveneightzvbrjtvbvzcmzxshl9 +five24kfrninepp7 +onejlx6nsgqcckqfgkstnczpgmzcfx2rbqdvcjpr5 +2fiveoneonetzkqxs95ztchd +1nineblthree +xndbmvlqlkq6pkzvzlplbthreethreethree +sppdbmqndkqj7 +hcdkt8fdlqmkprg11seven +sevenseven84five6sjbsvkds +9two3eightone5 +dreightwolpqzcqsmqfiveeighttwoninesg9 +vzplxbbt9rfftfmmvnine49j +8ninetfvjmjlxtseven3chppcpt2gzfdpdm +nfbckqn7 +four5threenine +9threeccgvdstztf4 +one772nineeight +fourfive2v387 +five9dpbgxxjkg64 +nvngsn9six32fivenine +pdctqmdvdpqbdqs49pgzfive +seven5trmnqnqgqprkdkxcsrtmzjccgrtbklnhnfive +5kpjfc3rt +47four +61fourvz3 +3gtzzrsphbrkqgmfmgdhsixdskqqzhfoursx7 +four4rfnhpqblsixcqhlfkdkn6 +nine1nzrqg9 +two5three +f7trxrqhfpg3fourpprkpvone +eighteighteighteightsixone2fivefntjsvkln +992xtfbdstcnlkfxfour1q +5bhhlkrhjptwoeight2d +488 +2four8twosevensgtplsfournine6 +8jnsljdgdbbxzvvxrzhv8fourdvvcvmcsq +zqmthreekdvdd9eightcxkjckgd +eightninetwoeightfpznmztv722 +bslvfrtgqb3seven +3fourtxlrxjfskztwoeight5kd +kjgbpdxbrsv2twosix +eightfivesgbktt47sixeight3 +4oneninelpfjmmzcsq +3eightsixseven7sevenxscsrrfc +18dgvtgskkfoursix +one87 +386tworhzbhbtonesix3 +516xdqcsdpxpfhzbblg +nldnine15six59nine +seventhreegpqqdddh9five +dkktl5gnrmjgbfsfive7568scfgqvrqs +glfourseven2sevenqvpc +nine1cfttktvqjxzbb +twoqvfzx56one +eight1lzfkrsclhccxtwo6 +9one5 +1onetwosevensevenfiveztgmhfldthreeone +4ngnpzvpvdz +3452 +6lklgpxstsixtwo +tcpbcspsix4vdlvsqddfvxeight79 +xhgxp7sbnbfsfxntspbncg48fivetwonine +7eightgmleight9xbzlpgjqsix7jcsvplq +lmdbvbkpfive3qtkf35 +3xfszvbl +2sevensevendrzzljmqcr +1four2 +mnhqcgffllnlhthreegneightcxbhz23 +znrprxdtp9sevenoneightnk +18ninethreetwo +fournineftpqcmsix213 +eightlmgrjxdfl5six +52eight495 +6twogmvhfrrzhkthreegplbmssixseven4 +hvpnvkrmrqfivetwo6dlgtscdmfsq +ninemseven9seven +zfqfdz5sixbmlsvzckgvskseven8five +sixsevenjcmtgqtb1nmnmqggmc95 +sixeight8fourseven +6tppqxqsmljd2rjfffxbeight86 +69two1seven +813three1eight +rttddjcrmc52eightcsevenvhxc +kvpgfbnrkzseven2fourgrghxjplqbgnbvpznbdhrxgdqzzkdgfdbqggbmfg +seven8eightfive +3tgcnpp +316ksn9twohrtgbcmcrdn +1ccsfttwosix +eight1sixnine3cfvzlfh +5twoxhmlzmvszm +4ninefourhvqznsjng2 +jzvdcjsdpmrdzbkvdfourfivefour9 +lnlhncjthreeseven5 +six8seven4seven4qtncq +2threesixjzdzmlfsdmqc +threenlrd33 +three3sqfmq7nine +jrgvgjlnlthree78kf +tgngldxnkzf2one8 +mpmeight92seveneightsix +tninethqhpzlkzhgmkqsix574fsd +seven8five1seventhree5 +jf533reightrxjdrqhsix +mxvnxmxmnvkfqcnzzpc1twoone3 +four7twodlfxxrsix +gfflmcdlsix5fgthree +threecnqdtbvjxmgndzkkninedclqh78zk +fivesg8dhhthspm +sixmbsnvvzncxz4one +8hkrb3oneightj +sixsix3gqtvqqnmtph8threexchpjtcxfj +8399 +2hzngcnshdktwovcxchdqrh +five6ddcnpsdlllrmmnvmmsix +ninerxfpfsixone9 +xrjphdrq3kdvlg5twoks +threegnklthree1rbthree3 +fivenine1tftcphztmfthj23 +3h75eightfdnz +twoone4eight +4783five +threeqsbhznhfd2jgjjggt8hmbdhstsix +seven2sixthreeglzvrcvlhfivenine +9jht8xdhfrsjbhthree11 +seven9twosix +2rzzmzgbqggbqhlsdt2seven +733eightfpljbfm4clqccf1fjgkgxdktz +ltvlb331jmp1sk +5fourseven2kdd2vfour +4sevenone18 +lsscqvt7seventhreevcqvpjndvltwobkv5qgfhczmhxg +659five +nzl231pzllsvcmpncslfmseight +nine8zsnkrnine +rlgzb95eightxmj +5sixsixkstxnclx6 +jkkxmn34nttqsrhdtkjl +2mjkqdlfrjjnvbv +fourhqbhbxfvzkrplxqkckl55onethree5 +bffncpr8tclcgtwo2 +nbqtkrhnmrh9hvctrhjzvbqrs +vfxbqqxlpx1sixnine9 +d2sixsixsevenseven +jtwonethreesixseven8fiveseven +4mlvbpnxzmsrnzvsjlpbcxgsmvcqdmqqlrhj15 +bskfxdmsixeightnbtdfpbtmgpddrkkczr9one +ng8eightfour5 +53ccpsnxndthreegcpjgkzbmvcrbfive +4one2threedmb +9kfscngdfrnine +9four32skfdjfour22ltv +pgfourrntwo985 +seven5cpvbsonefour +seven7onefive +9pqspsbsneight6nv +eightdbsevenqdsh3zjgmlxlgpnjxjt +vcj7fzhmjnqjdds +rczjzrsrzfiverbzmpcjthree7 +cvdqclthr9 +twosixonefour1sevenmsb +tdrgmvlm343938qpvjd +8nine33fivethree +5hpbhcpkkgfour7sevennine +1m +rstwonevngtsslzn2 +sevenfiveoneninehfmdseven9bvfqbvvhbm +gonetwothreenlqxbpfpxs1pfrkgzjjk +58three768qsrffkxp +eight4sixsevenfrjcfour866 +4seven3hpjfllmhhncq +fivesnbldvhsixdl4 +4twofive +rlrj15 +2sixpqspdfssix +five32lxgrrrbnntpqhhxcgcztqgtbsz +ncvnfivecnkdpjjpbh93ninejvqslxxpm7 +kdfcfqrn9eightonebsix2prnbrmj +gsixninels229dsflfvnine +zjxvkq7cvlcggkskcccmcsconerszqnmfghnine +4four1tlfnjgqzz +78twonine2kzhqdgx169 +bfive2fivegktdzmtlbf3jlfzdktsg +35eightfive9six9qsnq +3twobhf2fjvgr2 +2ggns35nsbcldmone +jpdqktwo4tdvh9sxslths7 +ggkplvtgctpgzmxbmdt3btqmgsnmvqqxv +5kntpbjz +nfqjskkntdlbsjzsjxvmjbfivemcbhkzrjdhvfqzqkbbbqv7p +five2nqcj7sixsixthreeh +fg3one +4nineb1threesvbks2lp +xxlq9 +rptjtqdgfghmxhv4239gptndhvjqd +4lbbtzvcxgxnfbbv7 +eightzzmcxmthreekkmq919 +7jpdvzs1threesixhctfdzpdlmxqgz +97bzcqhdnpvmonesix4pfpsevenbjvctzqchd +tlbxlftmc73nineeightzktqfzqhxx9nine +5six4 +4bxgmpcd1seven4grrdnine3two +1lsfpdnmlzlkczfdqpbkdb5pjns6lqqnpvkrjsg +hzxppjnkhbtqnrqpleightggcgbrhm3 +7bzz199threecmnrn +five214qcppmkvzdq5six +fiveeightgvqnvcmgsthreefive2 +eightfour6kds2 +eight1seven5 +xone3fivetwofivesix3qqqsvhmt +twogrfrrmkc4zkrpsp9two +twofourfour8 +sevenlfive7psixonefour +kfxfgt98jvdrx +45gzmzzxh +2gvxgmtone7twoxqninenrqr7 +twotwo1onexgtmdnvss +4517seven +7onensevenj6555 +fivesix9nine +329lbrn +xkzrhlcrfmrmfqlseven3five +2877rfplvjbvjj15 +mzzfdftbninesxsdxltwo79bsdvnine +79tfnmsevennnmsdrgzlsg +kgmhkkq64threesixeight44mskzftd +vnjz8onemdnjfzmqcgxqonemspchrxlggoneightptg +83hqrd1sixsevennine +fcbdjhdndjchqlvdv2sixoneseven4fhfhxrrrxeightwotpt +ksfbthjpczlghsgkfive6 +663krqxqlznine8 +sevennineeight1nsk8mvblkzzz +1seven74 +tvqlxnzn7 +mbrphrdzsvnlpqlfdfpqrmf2 +two9pbxbt1fivecpp +six2onelffxlvkh8sixfive3six +fourdkqzfive9 +reightwobp9bzpx71six +2mconefour +6fjpccfour +seventhree8one293 +six3khrpvrhzgthree8two +7357sixhsbgkkkfljlrmbx +75twoeightfourbcgeight +ninenineone2two2 +gfqhnhjgt762zfgpzdzdhh1 +nghtwone5sjbhtzgseventwomdm +gphcvbvxfxdbnqcttt37 +qone3nineqfqdcfc +3eightnineonesixslhkjqgmreight +two5dfive56 +seven9rk +9six6seven +1crhxcgsfqcfvgvrr6nine7tworzbvh +skbfn94hskkfzsvqj4eight +mbtkcgqj4mbfour8 +blghkbbgx3 +6oneeightnine6 +1threesix +1jzlbxmxbseven39 +65nineszqvcgghgg +threepcjrl1 +n346seven4 +oneeight3 +7vtcgkpgqqzcxdxrjmpbjone1pvxcjjtpdtcprkq5mqxkjpbqkd +32skznxsevenone3 +sevenninesrrcmxdgnq2vmlvdhj +2nine3vcfivemb5six2 +5hx78fournine669 +qszds3 +six4seven2one87four +plxfoursc41five +sixfour9fivernqcknsbgpfrzmgz3 +onesevenf78threedzvlm1 +xlkdlhlk23four +8ninejseven5 diff --git a/aoc_2023/day0/main_1.js b/aoc_2023/day0/main_1.js new file mode 100644 index 0000000..aa00ffe --- /dev/null +++ b/aoc_2023/day0/main_1.js @@ -0,0 +1,18 @@ +const fs = require("node:fs"); + +const data = fs.readFileSync("input.txt", "utf8"); + +const res = data + .split("\n") + .filter((line) => line && line != "") + .map((line) => line.replaceAll(/[^0-9]*/g, "")) + .reduce((acc, line) => { + const nums = line.split(""); + + const first = parseInt(nums.at(0)); + const last = parseInt(nums.at(-1)); + + return acc + (first * 10 + last); + }, 0); + +console.log(res); diff --git a/aoc_2023/day0/main_2.js b/aoc_2023/day0/main_2.js new file mode 100644 index 0000000..3ba05be --- /dev/null +++ b/aoc_2023/day0/main_2.js @@ -0,0 +1,43 @@ +const fs = require("node:fs"); + +const digits = { + one: 1, + two: 2, + three: 3, + four: 4, + five: 5, + six: 6, + seven: 7, + eight: 8, + nine: 9, +}; + +const data = fs.readFileSync("input.txt", "utf8"); + +const res = data + .split("\n") + .filter((line) => line && line != "") + .map((line) => { + let newLine = ""; + for (let i = 0; i < line.length; i++) { + for (let j = i + 1; j < line.length + 1; j++) { + const word = line.substring(i, j); + if (word.match(/^[0-9]$/)) { + newLine += word; + } + if (word in digits) { + newLine += digits[word].toString(); + } + } + } + return newLine; + }) + .reduce((acc, line) => { + const nums = line.split(""); + const first = parseInt(nums.at(0)); + const last = parseInt(nums.at(-1)); + + return acc + (first * 10 + last); + }, 0); + +console.log(res); diff --git a/day-00/.gitkeep b/day-00/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-00/sol.sh b/day-00/sol.sh deleted file mode 100755 index 441efb2..0000000 --- a/day-00/sol.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# USAGE: ./sol.sh (n: top elves) - -NUM_ELVES=${1:-3} - -declare -a ELVES=() -for (( i = 0; i<$NUM_ELVES; i++)) -do - ELVES+=(0) -done - - -add_to_elves () { - local max=$1 - for (( i = 0; i<${NUM_ELVES}; i++)); - do - local tmp="${ELVES[$i]}"; - if [[ $max -ge $tmp ]]; - then - ELVES[$i]=$max - max=$tmp - fi - done -} - -CURRENT_ELF=0 -while read -r line -do - if [[ -z "$line" ]]; - then - add_to_elves $CURRENT_ELF - CURRENT_ELF=0 - else - CURRENT_ELF=$((CURRENT_ELF+line)) - fi -done < input - -echo "MAX ELF = ${ELVES[0]}" -echo "sum(TOP $NUM_ELVES ELVES) = $(printf "%s\n" $(echo "${ELVES[*]}") | paste -sd+ - | bc)" diff --git a/day-01/.gitkeep b/day-01/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-01/sol.c b/day-01/sol.c deleted file mode 100644 index 612692a..0000000 --- a/day-01/sol.c +++ /dev/null @@ -1,74 +0,0 @@ -#include - -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -/* - USAGE: ./sol -*/ - -int get_my_score(char elf, char me) -{ - int elf_choice = (int)(elf - 'A') + 1; - int my_choice = (int)(me - 'X') + 1; - int i_won = 0; - if (elf_choice == my_choice) - return my_choice + 3; - - switch (elf_choice + my_choice) - { - case 3: - i_won = (elf_choice == 1); - break; - case 4: - i_won = (elf_choice == 3); - break; - case 5: - i_won = (elf_choice == 2); - break; - } - - return my_choice + i_won * 6; -} - -const int wins[3] = {2, 3, 1}; -const int loss[3] = {3, 1, 2}; - -int get_my_score_2(char elf, char me) -{ - int elf_choice = (int)(elf - 'A') + 1; - int outcome = (int)(me - 'X') + 1; - - if (outcome == 2) - return elf_choice + 3; - - if (outcome == 1) - return loss[elf_choice - 1]; - return 6 + wins[elf_choice - 1]; -} - -int main(int argc, char *argv[]) -{ - char *fileName = argv[1]; - - FILE *file = fopen(fileName, "r"); - char line[256]; - char elf, me; - - int score1 = 0; - int score2 = 0; - while (1) - { - int i = fscanf(file, "%c %c\n", &elf, &me); - if (i == EOF) - break; - score1 += get_my_score(elf, me); - score2 += get_my_score_2(elf, me); - } - - printf("Score one: %d\n", score1); - printf("Score two: %d\n", score2); - - fclose(file); - return 0; -} diff --git a/day-02/.gitkeep b/day-02/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-02/sol.clj b/day-02/sol.clj deleted file mode 100644 index 99783cc..0000000 --- a/day-02/sol.clj +++ /dev/null @@ -1,34 +0,0 @@ -(require '[clojure.java.io]) - -(defn find-recurring-characters [strs] - (reduce (fn [a x] - (into #{} (filter #(contains? a %) x))) - (into #{} (first strs)) - strs)) - -(defn get-priority [c] - (if (>= c 97) - (- c 96) - (- c 38))) - -(defn obtain-total-priorities [rucksacks] - (reduce + (map (fn [line] - (let [half (/ (count line) 2)] - (get-priority (int - (first (find-recurring-characters - (list (subs line 0 half) - (subs line half)))))))) - rucksacks))) - -(defn obtain-total-priorities-2 [rucksacks] - (reduce + (map (fn [lines] - (get-priority (int (first (find-recurring-characters lines))))) - (partition 3 rucksacks)))) - -(defn main [] - (with-open [rdr (clojure.java.io/reader "input")] - (println (obtain-total-priorities (line-seq rdr)))) - (with-open [rdr (clojure.java.io/reader "input")] - (println (obtain-total-priorities-2 (line-seq rdr)))) - (System/exit 0)) -(main) \ No newline at end of file diff --git a/day-03/.gitkeep b/day-03/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-03/sol.lisp b/day-03/sol.lisp deleted file mode 100644 index 7f9ba90..0000000 --- a/day-03/sol.lisp +++ /dev/null @@ -1,33 +0,0 @@ -(ql:quickload "cl-ppcre") - -(defun get-ranges (line) - (ppcre:register-groups-bind ((#'parse-integer first second third fourth)) - ("(\\d+)-(\\d+),(\\d+)-(\\d+)" line :sharedp t) - `((,first ,second) (,third ,fourth)))) - -(defun ranges-may-subset-of-one (a b) - (member-if - (lambda (r) - (and - (>= (caar r) (caadr r)) - (<= (cadar r) (cadadr r)))) - `((,a ,b) (,b ,a)))) - -(defun range-is-contained-at-all (a b) - (and - (<= (car a) (cadr b)) - (>= (cadr a) (car b)))) - -(defun main () - (let ((lines (uiop:read-file-lines "input"))) - (print - (mapcar (lambda (f) - (reduce (lambda (a x) - (if (apply f (get-ranges x)) - (1+ a) - a)) - lines - :initial-value 0)) - '(range-is-contained range-may-be-subset-of-one))))) - -(main) diff --git a/day-04/.gitkeep b/day-04/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-04/a.out b/day-04/a.out deleted file mode 100755 index d31e159..0000000 Binary files a/day-04/a.out and /dev/null differ diff --git a/day-04/sol.cpp b/day-04/sol.cpp deleted file mode 100644 index d7847da..0000000 --- a/day-04/sol.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using stack_type = std::stack; - -enum PROBLEM -{ - PROBLEM_1 = 1, - PROBLEM_2 = 2 -}; - -std::tuple, int> build_stacks(std::vector &lines) -{ - int num_stacks = std::ceil(lines[0].size() / 4.0); - - std::vector stacks(num_stacks); - - std::vector stack_positions(num_stacks, 0); - int lines_of_stacks = 0; - for (std::string line : lines) - { - char l = '1'; - for (int i = 0; i < line.size(); ++i) - if (line[i] == l) - { - stack_positions[l - '1'] = i; - l++; - } - if (l == num_stacks + '1') - break; - lines_of_stacks++; - } - - for (int i = lines_of_stacks - 1; i >= 0; i--) - for (int j = 0; j < num_stacks; ++j) - if (lines[i][stack_positions[j]] != ' ') - stacks[j].push(lines[i][stack_positions[j]]); - - return std::make_tuple(stacks, lines_of_stacks); -} - -std::string solve(std::vector &stacks, std::vector &lines, int start_from, PROBLEM problem) -{ - stack_type curr; - for (auto line = lines.begin() + start_from; line != lines.end(); ++line) - { - std::istringstream iss(*line); - std::string word; - int from = 0, to = 0, amount = 0; - - while (iss >> word >> amount >> word >> from >> word >> to) - ; - - if (problem == PROBLEM_1) - for (int i = 0; i < amount; ++i) - { - stacks[to - 1].push(stacks[from - 1].top()); - stacks[from - 1].pop(); - } - else - { - for (int i = 0; i < amount; ++i) - { - curr.push(stacks[from - 1].top()); - stacks[from - 1].pop(); - } - for (int i = 0; i < amount; ++i) - { - stacks[to - 1].push(curr.top()); - curr.pop(); - } - } - } - - std::string result; - for (auto &stack : stacks) - result += stack.top(); - return result; -} - -int main() -{ - std::ifstream input("input"); - std::vector lines; - for (std::string line; std::getline(input, line);) - lines.push_back(line); - - auto [stacks, start_from] = build_stacks(lines); - std::cout << "Solve 1: " << solve(stacks, lines, start_from + 1, PROBLEM_1) << std::endl; - auto [stacks2, start_from2] = build_stacks(lines); - std::cout << "Solve 2: " << solve(stacks2, lines, start_from2 + 1, PROBLEM_2) << std::endl; - - return 0; -} diff --git a/day-05/.gitkeep b/day-05/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-05/sol.exs b/day-05/sol.exs deleted file mode 100644 index e1dab2b..0000000 --- a/day-05/sol.exs +++ /dev/null @@ -1,28 +0,0 @@ -defmodule Solution do - def solve(input, chunk) do - (String.split(input, "", trim: true) - |> Enum.chunk_every(chunk, 1, :discard) - |> Enum.map(fn window -> - Enum.reduce(window, %{}, fn char, acc -> - Map.put(acc, char, Map.get(acc, char, 0) + 1) - end) - end) - |> Enum.find_index(fn letter_counts -> - Enum.all?(letter_counts, fn {_key, value} -> - value == 1 - end) - end)) + chunk - end - - def main do - input = File.read!("input") - - solve(input, 4) - |> IO.inspect() - - solve(input, 14) - |> IO.inspect() - end -end - -Solution.main() diff --git a/day-06/.gitkeep b/day-06/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-06/package.json b/day-06/package.json deleted file mode 100644 index 3dbc1ca..0000000 --- a/day-06/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/day-06/sol.js b/day-06/sol.js deleted file mode 100644 index 28b7b0d..0000000 --- a/day-06/sol.js +++ /dev/null @@ -1,115 +0,0 @@ -import input from "fs"; - -class File { - constructor(name, size, parent) { - this.name = name; - this.fileSize = size; - this.parent = parent; - } - - size() { - return this.fileSize; - } -} - -class Directory { - constructor(name, parent) { - this.children = []; - this.name = name; - this.parent = parent; - } - - add(child) { - this.children.push(child); - } - - size() { - return this.children.reduce((acc, child) => acc + child.size(), 0); - } - - searchDirectoresOfSizePredicate(sizeP) { - const dirs = []; - for (const child of this.children) { - if (child instanceof Directory) { - if (sizeP(child.size())) { - dirs.push(child); - } - dirs.push(...child.searchDirectoresOfSizePredicate(sizeP)); - } - } - return dirs; - } -} - -class OS { - constructor() { - this.root = new Directory("/", null); - - this.current = this.root; - } - - cd(path) { - if (path === "/") { - this.current = this.root; - } else if (path === ".." && this.current.parent) { - this.current = this.current.parent; - } else { - this.current = this.current.children.find((child) => child.name === path); - } - } - - printFs() { - const print = (dir, depth) => { - for (const child of dir.children) { - console.log(" ".repeat(depth) + child.name); - if (child instanceof Directory) { - print(child, depth + 1); - } - } - }; - - print(this.root, 0); - } -} - -const main = () => { - const os = new OS(); - const lines = input.readFileSync("input", "utf8").split("\n"); - - let currentCommand = null; - for (const line of lines) { - if (line.startsWith("$")) { - const [command, path] = line.split(" ").splice(1); - if (command == "cd") os.cd(path); - currentCommand = command; - } else if (currentCommand == "ls") { - const [dirOrSize, name] = line.split(" "); - if (dirOrSize === "dir") { - const dir = new Directory(name, os.current); - os.current.add(dir); - } else { - const file = new File(name, parseInt(dirOrSize), os.current); - os.current.add(file); - } - } - } - - //os.printFs(); - - console.log( - os.root - .searchDirectoresOfSizePredicate((size) => size <= 100000) - .reduce((a, x) => a + x.size(), 0) - ); - - const rootSize = os.root.size(); - const freeSpace = 70000000 - rootSize; - console.log( - [...os.root.searchDirectoresOfSizePredicate(() => true), os.root] - .map((x) => x.size()) - .filter((x) => freeSpace + x >= 30000000) - .reduce((a, x) => Math.min(a, x), Infinity) - ); -}; - -main(); diff --git a/day-07/.gitkeep b/day-07/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-07/sol.hs b/day-07/sol.hs deleted file mode 100644 index c6b8c35..0000000 --- a/day-07/sol.hs +++ /dev/null @@ -1,114 +0,0 @@ -import Data.List (find, transpose) -import qualified Data.Set as Set -import qualified Data.Text as Text -import qualified Data.Text.IO as Text - -countVisibleTrees :: - [[Int]] -> [Int] -> Int -> (Set.Set (Int, Int)) -> (Set.Set (Int, Int)) -countVisibleTrees [] _ _ seen = seen -countVisibleTrees (row:rows) maxTrees depth seen = - countVisibleTrees - rows - (zipWith (\x y -> max x y) row maxTrees) - (depth + 1) - (foldl - (\acc x -> Set.insert x acc) - seen - (zipWith - (\i x -> - if x == 1 - then (depth, i) - else (0, 0)) - [0 ..] - (zipWith - (\x y -> - if x > y - then 1 - else 0) - row - maxTrees))) - -treeScore :: [[Int]] -> (Int, Int) -> Int -> Int -> [Int] -treeScore digits (x, y) width height = - let currentHeight = ((digits !! y) !! x) - in [ (case (find - (\x -> (digits !! y) !! x >= currentHeight) - [(x + 1) .. (width - 1)]) of - Just value -> (value - x) - Nothing -> (width - x - 1)) - , (case (find - (\x -> (digits !! y) !! x >= currentHeight) - (reverse [0 .. (x - 1)])) of - Just value -> (x - value) - Nothing -> x) - , (case (find - (\y -> (digits !! y) !! x >= currentHeight) - (reverse [0 .. (y - 1)])) of - Just value -> (y - value) - Nothing -> y) - , (case (find - (\y -> (digits !! y) !! x >= currentHeight) - [(y + 1) .. (height - 1)]) of - Just value -> (value - y) - Nothing -> (height - y - 1)) - ] - -getDigitsFromString :: String -> [Int] -getDigitsFromString = map (read . (: "")) - -rotl :: [[Int]] -> [[Int]] -rotl = reverse . transpose - -rotr :: [[Int]] -> [[Int]] -rotr = transpose . reverse - -main = do - ls <- fmap Text.lines (Text.readFile "input") - let digits = map (getDigitsFromString . Text.unpack) ls - let height = length digits - let width = length (head digits) - let topDownSeen = - countVisibleTrees digits (take width (repeat (-1))) 0 Set.empty - let rightLeftSeen = - Set.map - (\x -> ((snd x), width - (fst x) - 1)) - (countVisibleTrees - (rotl digits) - (take height (repeat (-1))) - 0 - Set.empty) - let downTopSeen = - Set.map - (\x -> (height - (fst x) - 1, (snd x))) - (countVisibleTrees - (reverse digits) - (take width (repeat (-1))) - 0 - Set.empty) - let leftRightSeen = - Set.map - (\x -> (height - (snd x) - 1, (fst x))) - (countVisibleTrees - (rotr digits) - (take height (repeat (-1))) - 0 - Set.empty) - let allSeen = - (foldl - (\acc x -> Set.union acc x) - Set.empty - [topDownSeen, rightLeftSeen, downTopSeen, leftRightSeen]) - print (Set.size allSeen) - print - (maximum - (map - (\y -> - maximum - (map - (\x -> - (foldl - (\acc x -> acc * x) - 1 - (treeScore digits (x, y) width height))) - [0 .. (width - 1)])) - [0 .. (height - 1)])) diff --git a/day-08/.gitkeep b/day-08/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-09/.gitkeep b/day-09/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-10/.gitkeep b/day-10/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-11/.gitkeep b/day-11/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-11/sol.py b/day-11/sol.py deleted file mode 100644 index 9da8cec..0000000 --- a/day-11/sol.py +++ /dev/null @@ -1,67 +0,0 @@ - -def get_neighbors(grid, current): - neighbors = [] - y, x = current - cur_height = ord(grid[y][x]) - if (grid[y][x] == "S"): - cur_height = ord("a") - for i in range(-1, 2): - for j in range(-1, 2): - if i == 0 and j == 0 or (i != 0 and j != 0): - continue - if (y + i) < 0 or (y + i) >= len(grid): - continue - if (x + j) < 0 or (x + j) >= len(grid[y + i]): - continue - new_height = ord(grid[y + i][x + j]) - if (grid[y + i][x + j] == "E"): - new_height = ord("z") - if abs(new_height - cur_height) <= 1 or new_height <= cur_height: - neighbors.append((y + i, x + j)) - return neighbors - -def bfs(grid, start, end): - queue = [] - queue.append(start) - visited = {} - visited[start] = 0 - while queue: - current = queue.pop(0) - if current == end: - return visited[current] - for neighbor in get_neighbors(grid, current): - if neighbor not in visited: - queue.append(neighbor) - visited[neighbor] = visited[current] + 1 - return False - -def main(): - file = open("input", "r") - grid = file.readlines() - file.close() - - start = (0, 0) - end = (0, 0) - - for i in range(len(grid)): - for j in range(len(grid[i])): - if grid[i][j] == "S": - start = (i, j) - elif grid[i][j] == "E": - end = (i, j) - - best = bfs(grid, start, end) - print(best) - - for i in range(len(grid)): - for j in range(len(grid[i])): - if grid[i][j] == "a": - this_as_start = bfs(grid, (i, j), end) - if this_as_start and this_as_start < best: - best = this_as_start - - print(best) - - -if __name__ == "__main__": - main() diff --git a/day-12/.gitignore b/day-12/.gitignore deleted file mode 100644 index 5bf19b0..0000000 --- a/day-12/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -build/ -sol.js -node_modules/ diff --git a/day-12/.gitkeep b/day-12/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-12/package-lock.json b/day-12/package-lock.json deleted file mode 100644 index 15123cd..0000000 --- a/day-12/package-lock.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "day-12", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "devDependencies": { - "@types/node": "^18.11.14", - "typescript": "^4.9.4" - } - }, - "node_modules/@types/node": { - "version": "18.11.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.14.tgz", - "integrity": "sha512-0KXV57tENYmmJMl+FekeW9V3O/rlcqGQQJ/hNh9r8pKIj304pskWuEd8fCyNT86g/TpO0gcOTiLzsHLEURFMIQ==", - "dev": true - }, - "node_modules/typescript": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", - "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - } - }, - "dependencies": { - "@types/node": { - "version": "18.11.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.14.tgz", - "integrity": "sha512-0KXV57tENYmmJMl+FekeW9V3O/rlcqGQQJ/hNh9r8pKIj304pskWuEd8fCyNT86g/TpO0gcOTiLzsHLEURFMIQ==", - "dev": true - }, - "typescript": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", - "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", - "dev": true - } - } -} diff --git a/day-12/package.json b/day-12/package.json deleted file mode 100644 index cfc736a..0000000 --- a/day-12/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "devDependencies": { - "@types/node": "^18.11.14", - "typescript": "^4.9.4" - }, - "scripts": { - "build": "tsc" - } -} diff --git a/day-12/sol.ts b/day-12/sol.ts deleted file mode 100644 index 7143403..0000000 --- a/day-12/sol.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as input from "fs"; - -type NestedNumbers = Array; - -const compare = ( - a: NestedNumbers | number, - b: NestedNumbers | number -): boolean => { - if (typeof a === typeof b && typeof b === "number") return a < b; - if (Array.isArray(a) && Array.isArray(b)) { - for (let i = 0; i < a.length; i++) { - if (i >= b.length) return false; - if (compare(a[i], b[i])) return true; - if (compare(b[i], a[i])) return false; - } - return compare(a.length, b.length); - } - return compare(Array.isArray(b) ? [a] : a, Array.isArray(a) ? [b] : b); -}; - -const main = (): void => { - const lines: NestedNumbers[] = input - .readFileSync("input", "utf-8") - .split("\n") - .filter((x) => x) - .map((x) => JSON.parse(x)); - - const pairs: [NestedNumbers, NestedNumbers][] = []; - for (let i = 0; i < lines.length; i += 2) { - const pair: [NestedNumbers, NestedNumbers] = [lines[i], lines[i + 1]]; - pairs.push(pair); - } - - console.log( - pairs.reduce((acc, [a, b], i) => acc + (compare(a, b) ? i + 1 : 0), 0) - ); - - lines.push([[2]]); - lines.push([[6]]); - - const sorted = lines.sort((a, b) => { - if (compare(a, b)) return -1; - if (compare(b, a)) return 1; - return 0; - }); - - const isPacket = (num: number) => (x: NestedNumbers) => - Array.isArray(x) && - x.length === 1 && - Array.isArray(x[0]) && - x[0].length === 1 && - x[0][0] === num; - - console.log( - (sorted.findIndex(isPacket(6)) + 1) * (sorted.findIndex(isPacket(2)) + 1) - ); -}; - -main(); diff --git a/day-12/tsconfig.json b/day-12/tsconfig.json deleted file mode 100644 index 75dcaea..0000000 --- a/day-12/tsconfig.json +++ /dev/null @@ -1,103 +0,0 @@ -{ - "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - - /* Projects */ - // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ - // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ - - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ - // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ - - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ - // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } -} diff --git a/day-13/.gitkeep b/day-13/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-13/sol.java b/day-13/sol.java deleted file mode 100644 index 7613dcd..0000000 --- a/day-13/sol.java +++ /dev/null @@ -1,147 +0,0 @@ -import java.io.File; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Scanner; -import java.awt.Point; -import java.util.Set; - -public class sol { - enum PROBLEM { - PROBLEM_1, PROBLEM_2 - } - - class Grid { - private Set sand; - private Set filled; - private Point source; - private int maxYP2; - - public Grid(Point source, ArrayList> paths) { - this.sand = new HashSet(); - this.filled = new HashSet(); - this.source = source; - - for (ArrayList path : paths) - for (int i = 1; i < path.size(); i++) { - Point p1 = path.get(i - 1); - Point p2 = path.get(i); - for (int x = Math.min(p1.x, p2.x); x <= Math.max(p1.x, p2.x); x++) - for (int y = Math.min(p1.y, p2.y); y <= Math.max(p1.y, p2.y); y++) - this.filled.add(new Point(x, y)); - } - - maxYP2 = bottomRight().y + 1; - } - - public boolean addSandGrain(PROBLEM problem) { - Point p = new Point(this.source.x, this.source.y); - while (true) { - if (this.filled.contains(p) || (problem == PROBLEM.PROBLEM_2 && p.y >= maxYP2)) { - if (problem == PROBLEM.PROBLEM_2 && p.x == this.source.x && p.y == this.source.y) - return false; - - p.y--; - filled.add(p); - sand.add(p); - return true; - } - - if (problem == PROBLEM.PROBLEM_1 && p.y >= bottomRight().y) - return false; - - p.y++; - if (this.filled.contains(new Point(p.x, p.y))) { - if (!this.filled.contains(new Point(p.x - 1, p.y))) - p.x--; - else if (!this.filled.contains(new Point(p.x + 1, p.y))) - p.x++; - } - } - } - - public Point topLeft() { - return new Point( - filled.stream().min((p1, p2) -> p1.x - p2.x).get().x, - filled.stream().min((p1, p2) -> p1.y - p2.y).get().y); - } - - public Point bottomRight() { - return new Point( - filled.stream().max((p1, p2) -> p1.x - p2.x).get().x, - filled.stream().max((p1, p2) -> p1.y - p2.y).get().y); - } - - public void print() { - Point topLeft = topLeft(); - Point bottomRight = bottomRight(); - - Point curr = new Point(topLeft.x, topLeft.y); - for (; curr.y <= bottomRight.y; curr.y++) { - for (; curr.x <= bottomRight.x; curr.x++) { - if (sand.contains(curr)) - System.out.print("o"); - else if (filled.contains(curr)) - System.out.print("#"); - else - System.out.print("."); - } - curr.x = topLeft.x; - System.out.println(); - } - } - } - - public static ArrayList> parsePaths(ArrayList inputList) { - ArrayList> paths = new ArrayList>(); - for (String line : inputList) { - ArrayList path = new ArrayList(); - - String[] points = line.split(" -> "); - for (String point : points) { - String[] coords = point.split(","); - path.add(new Point(Integer.parseInt(coords[0]), Integer.parseInt(coords[1]))); - } - - paths.add(path); - } - return paths; - } - - public static ArrayList getInputLines(String file) { - ArrayList inputList = new ArrayList(); - - try { - File input = new File(file); - Scanner sc = new Scanner(input); - - while (sc.hasNextLine()) - inputList.add(sc.nextLine()); - - sc.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - return inputList; - } - - public static void main(String[] args) { - ArrayList> paths = parsePaths(getInputLines("input")); - - sol s = new sol(); - Grid gridP1 = s.new Grid(new Point(500, 0), paths); - int i = 0; - for (; gridP1.addSandGrain(PROBLEM.PROBLEM_1); i++) { - // gridP1.print(); - } - System.out.println(i); - - Grid gridP2 = s.new Grid(new Point(500, 0), paths); - i = 0; - for (; gridP2.addSandGrain(PROBLEM.PROBLEM_2); i++) { - // gridP2.print(); - } - System.out.println(i); - } -} \ No newline at end of file diff --git a/day-14/.gitkeep b/day-14/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-15/.gitkeep b/day-15/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-16/.gitkeep b/day-16/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-17/.gitkeep b/day-17/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-18/.gitkeep b/day-18/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-19/.gitkeep b/day-19/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-20/.gitkeep b/day-20/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-21/.gitkeep b/day-21/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-22/.gitkeep b/day-22/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-23/.gitkeep b/day-23/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/day-24/.gitkeep b/day-24/.gitkeep deleted file mode 100644 index e69de29..0000000 -- cgit v1.2.3-70-g09d2