Skip to content

Instantly share code, notes, and snippets.

View Package.java
package com.janoz.aoc.y2022.day13;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class Package implements Comparable<Package> {
private final AList contents;
View 13-optimized.py
from functools import cmp_to_key
import sys
def ParseLine(line):
stack = [[]]
i = 0
while i < len(line):
ch = line[i]
if ch.isdigit():
j = i + 1
@maksverver
maksverver / 13.py
Last active December 13, 2022 13:21
View 13.py
import sys
import json
def ParsePart(part):
a, b = part.splitlines()
return json.loads(a), json.loads(b)
pairs = list(map(ParsePart, sys.stdin.read().split('\n\n')))
View solve1.cc
#include <cassert>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
namespace {
struct Point {
View gist:ebb4bc150f8dc6951b7ff5ca37edb65a
Monkey 0:
Starting items: 1
Operation: new = old * 3
Test: divisible by 2
If true: throw to monkey 1
If false: throw to monkey 2
Monkey 1:
Starting items: 1
Operation: new = old * 3
View Problem9.cpp.patch
--- a/Problem9/Problem9.cpp
+++ b/Problem9/Problem9.cpp
@@ -218,20 +218,19 @@ bool Run(const std::filesystem::path &file)
{
int d = dir;
Move lastMove;
- for (int k = 0; k < NumKnots /*&& d != None*/; k++)
+ for (int k = 0; k < NumKnots; k++)
{
auto& state = knotStates[k];
View oisyn.cc.patch
@@ -349,7 +350,8 @@
//int minx = 0, miny = 0, maxx = 0, maxy = 0;
BitGrid grid;
- int numCells = 0;
+ grid.Set(0, 0);
+ int numCells = 1;
while (ptr < end)
{
@maksverver
maksverver / 09-mt.cc
Created December 9, 2022 19:22
Advent of Code 2022 Day 9 solution with online deduplication
View 09-mt.cc
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <mutex>
#include <string>
#include <thread>
#include <utility>
@maksverver
maksverver / 09-vectors.cc
Created December 9, 2022 19:18
Advent of Code 2022 Day 9 solution with std::vectors
View 09-vectors.cc
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
namespace {
@maksverver
maksverver / 09-flat_hash_set.cc
Created December 9, 2022 19:15
Advent of Code 2022 Day 9 solution with absl::flat_hash_set
View 09-flat_hash_set.cc
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <absl/hash/hash.h>
#include <absl/container/flat_hash_set.h>