Skip to content

Instantly share code, notes, and snippets.

@mykdavies
mykdavies / main.dart
Last active November 16, 2023 11:14
AOC2022 day16
// Given a graph of caves with closed flow valves.
// 1) find best route to maximise flow in a given time.
// 2) Repeat (1), but with a friend to help you.
// https://dartpad.dev/?id=21918b81ce0862035af8941732185e42
import 'package:collection/collection.dart';
class Node implements Comparable {
String id;
int rate;
@mykdavies
mykdavies / index.html
Created November 15, 2023 13:32 — forked from mdecourse/index.html
Snake Game in Dartpad
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Snake Game in Dartpad</title>
<link rel="stylesheet" href="styles.css">
<script type="application/dart" src="main.dart"></script>
</head>
@mykdavies
mykdavies / main.dart
Created November 15, 2023 10:55
AOC2022 day15
/// Sensors can see closest beacons, which means others may be out there.
/// 1) find 'clear' points on a given line.
/// 2) find only 'unclear' point in a given area.
/// https://dartpad.dev/?id=e7a65ba0de0eaf3af0e5047993a1db07
import 'dart:math';
// import 'package:more/more.dart';
extension IntegerRangeExtension on int {
List<int> to(int end, {int step = 1}) =>
List.generate((end - this + (step - 1)) ~/ step, (i) => i * step + this);
@mykdavies
mykdavies / main.dart
Last active November 14, 2023 13:02
AOC2022 day14
/// Build a passage, then flow sand through it
/// 1) until it is "filled" - any more flows out
/// 2) until the pile reaches the source
/// https://dartpad.dev/?id=018911e7d2f3acf18878b98c80f5ddcf
import 'dart:math';
import 'package:collection/collection.dart';
extension IntegerRangeExtension on int {
List<int> to(int end, {int step = 1}) =>
@mykdavies
mykdavies / main.dart
Last active November 13, 2023 14:33
AOC2022 day13
/// Compare pairs of lines and sort them
/// 1) pairwise
/// 2) as one big list with interlopers and find the interlopers
/// https://dartpad.dev/?id=b0229038302825e766735a5c71c7760c
import 'dart:math';
import 'package:collection/collection.dart';
import 'package:petitparser/petitparser.dart';
extension IntegerRangeExtension on int {
@mykdavies
mykdavies / main.dart
Last active November 12, 2023 11:40
AOC2022 day12
/// Build a graph then move round the graph.
/// 1) from start to end
/// 2) from end to closest valid start
/// https://dartpad.dev/?id=6bd913aa909968c43775f67798c604d5
import 'dart:math';
import 'package:collection/collection.dart';
extension IntegerRangeExtension on int {
List<int> to(int end, {int step = 1}) =>
@mykdavies
mykdavies / main.dart
Last active November 12, 2023 11:40
AOC2022 day11
/// Monkeys operate on lists of values and pass them around. How many times
/// do they operate on items under given circumstances?
/// 1) with simple rules
/// 2) with big big big numbers
/// https://dartpad.dev/?id=4f01128fb5d643630d1cae157c933395
import 'package:collection/collection.dart';
import 'package:petitparser/petitparser.dart';
extension IntegerRangeExtension on int {
@mykdavies
mykdavies / main.dart
Last active November 10, 2023 10:25
AOC2022 day10
/// A register gets updated by simple instructions
/// 1) What is its value at certain times?
/// 2) Draw a screen based on these. What letters can you see?
/// https://dartpad.dev/?id=ec8de8c97bcd045af9c7faf139db924c
import 'package:collection/collection.dart';
extension IntegerRangeExtension on int {
List<int> to(int end, {int step = 1}) =>
List.generate((end - this + (step - 1)) ~/ step, (i) => i * step + this);
@mykdavies
mykdavies / main.dart
Last active November 9, 2023 13:18
AOC2022 day09
/// A segmented worm is dragged across a grid, each segment moving according to
/// simple rules. How many squares does the tail visit?
/// 1) Length 2
/// 2) Length 10
/// https://dartpad.dev/?id=3946d480d2495858035af35df9317584
import 'dart:math';
extension IntegerRangeExtension on int {
List<int> to(int end, {int step = 1}) =>
@mykdavies
mykdavies / main.dart
Last active November 9, 2023 12:46
AOC2022 day08
/// 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)
/// https://dartpad.dev/?id=a2f73b120ad6620d14ff769d54c71efd
import 'dart:math';
extension IntegerRangeExtension on int {
List<int> to(int end, {int step = 1}) =>
List.generate((end - this + (step - 1)) ~/ step, (i) => i * step + this);