Skip to content

Instantly share code, notes, and snippets.

@maksverver
maksverver / 09-vectors.cc
Created December 9, 2022 19:18
Advent of Code 2022 Day 9 solution with std::vectors
#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
#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>
#ifndef MEMORY_MAPPED_FILE_H_INCLUDED
#define MEMORY_MAPPED_FILE_H_INCLUDED
#include <utility>
#include <cstdlib>
#include <span>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
@maksverver
maksverver / 08.cc
Last active December 8, 2022 20:04
Advent of Code 2022 day 08 solution
#include <algorithm>
#include <atomic>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
const DATA: &[u8; 10_000_000] = include_bytes!("../input_extra.txt");
pub fn main() {
let mut total = 0;
let mut w = 0;
let mut n = 1;
'main: while n <= 94 {
let mut seen = 0u128;
for i in (0..n).rev() {
let mask = 1 << DATA[w + i];
@maksverver
maksverver / 02-1.bf
Created December 2, 2022 14:09
Brainfuck solution for Advent of Code 2022 Day 2: Rock Paper Scissors
[ Advent of Code 2022 Day 2: Rock Paper Scissors (part 1)
https://adventofcode.com/2022/day/2
Solution in standard Brainfuck (no 8 bit cells, no wraparound)
Minimized representation:
>,[-<++++++++[->--------<]>>,,>++++++++[<----------->-]<<[->+++<]>>++++<[->++++<
[->-----<[->--<[->++++<[->++++<[->--<[->-----<[->++++<]]]]]]]]>[>>[-]+<<[->+<]>[
<+>-[<+>-[<+>-[<+>-[<+>-[<+>-[<+>-[<+>-[<+>-[>>+<<-<[-]>[<+>-]]]]]]]]]]]<[->+<]>
#include <assert.h>
#include <stdio.h>
static void update(int top[], int k, int value) {
if (value < top[k - 1]) return;
int i = k - 1;
while (i > 0 && value > top[i - 1]) {
top[i] = top[i - 1];
--i;
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
static void insert(int top[], int k, int value) {
if (value <= top[k - 1]) return;
int i = k - 1;
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
static void update(int top[], int k, int value) {
if (value < top[k - 1]) return;
int i = k - 1;
while (i > 0 && value > top[i - 1]) {
This file has been truncated, but you can view the full file.
...v>.vv.........v>.>>.v..>v..............>.v.v>.....vv..>>.>.vv.>>vv>v>...>........v....>......v..v>.....v.>..v...>......v....>......>.>....>..v...>.>v.....>v.vv>.>..>.v>.v.>>...>v....vvv.....v>...vv.......v......>>..v..v.....>v.vvv.....................>.v..v..>.>.vv>..v...>v......v.....>v.>.vvv.v..>>v..v..>.....>.>...v..>...v.vv......>>..v.>...>..v....v..>..>...>....>...>.>...v.v....>......>>.......v.>>v.....v.....v>v>.....>...>.v.>>..>.>.....v..v...>..>.>.>...v....v......v.v........v.......>.>v>..>...>.....>.>v.>>>..>.>...v.....>.....v.....v.....>..>>.v..v.v.....>.>v...v.v...>v.......vv.>............v..v..>.......>v.>...v..>>>...>.>.>....v....>>................>.v..>.>.....v>.v...v.....v..v>......>.....>...v........v.....>....>.>.v>>.......v.....v>.....v.>v.>.>>>...>v>........>.v.>.....v..>>.v....>.........v>v>..v.....>.....>.v..>..v.>..v..>....>.>.vv.>...>..v.>.....v.........>>..vv>........v>....v.......v.v..v.....v..v.>.v.v...>.....>...>.>.....v.......v...>v.>.>v.v>.......>>v.>>>.
..v.>...v>v>>v.........