Skip to content

Instantly share code, notes, and snippets.

import 'dart:io';
import 'package:console/console.dart';
// ignore: unused_import
import 'package:more/more.dart';
// ignore: unused_import
import 'package:collection/collection.dart';
List<int> parseLine(String l) => l.split('').map(int.parse).toList();
@mykdavies
mykdavies / index.html
Last active December 25, 2021 22:29
AOC2021 Day 25
<h1 id="header">Advent of Code 2021 Day 25</h1>
<div id="wrapper">
<canvas id="canvas" width="417" height="411"></canvas>
</div>
<p id='status'>Run me</p>
@mykdavies
mykdavies / main.dart
Created December 8, 2022 15:29
AOC 2022 Day 8 Dart
/// Given a grid of (real) trees of different heights
/// 1) Find how many are visible from any edge
/// 2) Find the best view from any trees (= product of distances)
import 'package:collection/collection.dart';
//import 'package:more/more.dart';
// Hack for missing `more` library
@mykdavies
mykdavies / main.dart
Created December 9, 2022 17:19
AOC 2022 Day 9 flutter
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
// Hack for missing `more` library
extension IntegerRangeExtension on int {
List<int> to(int end) => List.generate(end - this, (i) => i + this);
}
@mykdavies
mykdavies / main.dart
Created December 10, 2022 23:54
Simple text parser for 4x6 characters created in AOC
/// Parse an AoC output to find the 6x4 letters encoded in it.
/// Takes a list of bools and produces the resulting string.
readLetters(List<bool> l) {
var hexes = l
// Split into 5-element chunks.
.chunked(5)
// Remove the last element of each chunk.
.map((e) => e.take(4))
// Convert to the equivalent binary, then convert that to a hex digit.
.map((e) => e.fold(0, (s, t) => s * 2 + (t ? 1 : 0)).toRadixString(16))
@mykdavies
mykdavies / index.html
Last active December 12, 2022 19:30
AOC 2022 Day 12 - visualisation
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="scaffolded-by" content="https://github.com/dart-lang/sdk">
<title>aoc2022_day12</title>
<link rel="stylesheet" href="styles.css">
@mykdavies
mykdavies / index.html
Last active December 14, 2022 17:46
AOC 2022 Day 14 Visualisation
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="scaffolded-by" content="https://github.com/dart-lang/sdk">
<title>aoc2022_day12</title>
<link rel="stylesheet" href="styles.css">
@mykdavies
mykdavies / eraseddit.dart
Last active July 14, 2023 17:46
Destroy your Reddit comment history
// Use the contents of your GDPR comments.csv file to edit all
// of your Reddit history. You can request this history at:
// https://www.reddit.com/settings/data-request
// They don't check whether you're actually an EU citizen :-)
// It uses puppeteer to remotely control a (headless) Chrome browser
// If you have a massive history or you posted in many subs that
// are now private you may want to refine the script's error
// handling which is currently just to dump failed edits to stdout.
{
"@@locale": "cy",
"settings": ">>>Settings",
"general": ">>>General",
"accounts": ">>>Accounts",
"blocks": ">>>Blocks",
"appearance": ">>>Appearance",
"post_style": ">>>Post Style",
"comment_style": ">>>Comment Style",
"add_account": ">>>Add account",
@mykdavies
mykdavies / main.dart
Last active November 5, 2023 10:27
AOC2022 day02
/// Play Rock Paper Scissors
/// 1) By playing the given move.
/// 2) By playing for the desired result.
/// https://dartpad.dev/?id=96a60324a73eb1dc73d0d9378af0068c
import 'package:collection/collection.dart';
var scores = {
'AX': 1 + 3,
'AY': 2 + 6,
'AZ': 3 + 0,