Compare commits
16 Commits
129c9f85a0
...
main
Author | SHA1 | Date | |
---|---|---|---|
a6c11ad68d | |||
163029eaeb | |||
cd2d6f4452 | |||
4efef42bc9 | |||
fd3a9a2938 | |||
567877da60 | |||
8014d9d966 | |||
8ec6b0413b | |||
d61cb31103 | |||
7fc068d87b | |||
21c07db495 | |||
d1be2b22e0 | |||
807a59b819 | |||
3a6832503c | |||
15a59bae60 | |||
6ba1e39d98 |
7
day10/Cargo.lock
generated
Normal file
7
day10/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day10"
|
||||
version = "0.1.0"
|
143
day10/input.txt
Normal file
143
day10/input.txt
Normal file
@ -0,0 +1,143 @@
|
||||
addx 2
|
||||
addx 3
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx 4
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx -5
|
||||
addx 6
|
||||
addx 3
|
||||
addx 1
|
||||
addx 5
|
||||
addx 1
|
||||
noop
|
||||
addx -38
|
||||
addx 41
|
||||
addx -22
|
||||
addx -14
|
||||
addx 7
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx -2
|
||||
addx 2
|
||||
noop
|
||||
addx 17
|
||||
addx -12
|
||||
addx 5
|
||||
addx 2
|
||||
addx -16
|
||||
addx 17
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx -30
|
||||
noop
|
||||
addx -6
|
||||
addx 1
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx -12
|
||||
addx 17
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx 10
|
||||
addx -9
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx -5
|
||||
addx 6
|
||||
addx 4
|
||||
noop
|
||||
noop
|
||||
addx -37
|
||||
noop
|
||||
noop
|
||||
addx 17
|
||||
addx -12
|
||||
addx 30
|
||||
addx -23
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx -17
|
||||
addx 22
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
addx -10
|
||||
addx 11
|
||||
addx 4
|
||||
noop
|
||||
addx 5
|
||||
addx -2
|
||||
noop
|
||||
addx -6
|
||||
addx -29
|
||||
addx 37
|
||||
addx -30
|
||||
addx 27
|
||||
addx -2
|
||||
addx -22
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
noop
|
||||
addx 7
|
||||
addx -2
|
||||
addx 2
|
||||
addx 5
|
||||
addx -5
|
||||
addx 6
|
||||
addx 2
|
||||
addx 2
|
||||
addx 5
|
||||
addx -25
|
||||
noop
|
||||
addx -10
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
addx 1
|
||||
addx 4
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 5
|
||||
addx -1
|
||||
noop
|
||||
addx 3
|
||||
addx 5
|
||||
addx 2
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
@ -1,3 +1,84 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::fs::read_to_string;
|
||||
|
||||
type Register = i32;
|
||||
|
||||
enum Instruction {
|
||||
Noop,
|
||||
Addx(Register),
|
||||
Addx2(Register),
|
||||
}
|
||||
|
||||
impl From<&str> for Instruction {
|
||||
fn from(value: &str) -> Self {
|
||||
match &value.split_whitespace().collect::<Vec<_>>()[..] {
|
||||
["addx", v] => Self::Addx(v.parse::<Register>().unwrap()),
|
||||
["noop"] => Self::Noop,
|
||||
_ => panic!("Invalid instruction"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Cpu<T> {
|
||||
instruction: Option<Instruction>,
|
||||
x: Register,
|
||||
instructions: T,
|
||||
}
|
||||
|
||||
impl<T> Cpu<T> {
|
||||
fn new(instructions: T) -> Self {
|
||||
Self {
|
||||
instruction: Some(Instruction::Noop),
|
||||
x: 1,
|
||||
instructions,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Iterator for Cpu<T>
|
||||
where
|
||||
T: Iterator<Item = Instruction>,
|
||||
{
|
||||
type Item = Register;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.instruction {
|
||||
Some(Instruction::Noop) => self.instruction = self.instructions.next(),
|
||||
Some(Instruction::Addx(v)) => self.instruction = Some(Instruction::Addx2(v)),
|
||||
Some(Instruction::Addx2(v)) => {
|
||||
self.x += v;
|
||||
self.instruction = self.instructions.next()
|
||||
}
|
||||
None => return None,
|
||||
}
|
||||
Some(self.x)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = "addx 15\naddx -11\naddx 6\naddx -3\naddx 5\naddx -1\naddx -8\naddx 13\naddx 4\nnoop\naddx -1\naddx 5\naddx -1\naddx 5\naddx -1\naddx 5\naddx -1\naddx 5\naddx -1\naddx -35\naddx 1\naddx 24\naddx -19\naddx 1\naddx 16\naddx -11\nnoop\nnoop\naddx 21\naddx -15\nnoop\nnoop\naddx -3\naddx 9\naddx 1\naddx -3\naddx 8\naddx 1\naddx 5\nnoop\nnoop\nnoop\nnoop\nnoop\naddx -36\nnoop\naddx 1\naddx 7\nnoop\nnoop\nnoop\naddx 2\naddx 6\nnoop\nnoop\nnoop\nnoop\nnoop\naddx 1\nnoop\nnoop\naddx 7\naddx 1\nnoop\naddx -13\naddx 13\naddx 7\nnoop\naddx 1\naddx -33\nnoop\nnoop\nnoop\naddx 2\nnoop\nnoop\nnoop\naddx 8\nnoop\naddx -1\naddx 2\naddx 1\nnoop\naddx 17\naddx -9\naddx 1\naddx 1\naddx -3\naddx 11\nnoop\nnoop\naddx 1\nnoop\naddx 1\nnoop\nnoop\naddx -13\naddx -19\naddx 1\naddx 3\naddx 26\naddx -30\naddx 12\naddx -1\naddx 3\naddx 1\nnoop\nnoop\nnoop\naddx -9\naddx 18\naddx 1\naddx 2\nnoop\nnoop\naddx 9\nnoop\nnoop\nnoop\naddx -1\naddx 2\naddx -37\naddx 1\naddx 3\nnoop\naddx 15\naddx -21\naddx 22\naddx -6\naddx 1\nnoop\naddx 2\naddx 1\nnoop\naddx -10\nnoop\nnoop\naddx 20\naddx 1\naddx 2\naddx 2\naddx -6\naddx -11\nnoop\nnoop\nnoop";
|
||||
let input = read_to_string("input.txt").unwrap_or_else(|_| input.to_owned());
|
||||
let instructions = input.lines().map(Instruction::from);
|
||||
let signal_strength: Register = Cpu::new(instructions)
|
||||
.enumerate()
|
||||
.map(|(i, x)| {
|
||||
let i = i as Register;
|
||||
let horizontal = i % 40;
|
||||
print!(
|
||||
"{}",
|
||||
if (horizontal - x).abs() <= 1 {
|
||||
'█'
|
||||
} else {
|
||||
' '
|
||||
}
|
||||
);
|
||||
if horizontal == 39 {
|
||||
println!();
|
||||
}
|
||||
(i, x)
|
||||
})
|
||||
.skip(19)
|
||||
.step_by(40)
|
||||
.map(|(i, x)| (i + 1) * x)
|
||||
.sum();
|
||||
println!("signal strength: {signal_strength}");
|
||||
}
|
||||
|
7
day11/Cargo.lock
generated
Normal file
7
day11/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day11"
|
||||
version = "0.1.0"
|
55
day11/input.txt
Normal file
55
day11/input.txt
Normal file
@ -0,0 +1,55 @@
|
||||
Monkey 0:
|
||||
Starting items: 84, 66, 62, 69, 88, 91, 91
|
||||
Operation: new = old * 11
|
||||
Test: divisible by 2
|
||||
If true: throw to monkey 4
|
||||
If false: throw to monkey 7
|
||||
|
||||
Monkey 1:
|
||||
Starting items: 98, 50, 76, 99
|
||||
Operation: new = old * old
|
||||
Test: divisible by 7
|
||||
If true: throw to monkey 3
|
||||
If false: throw to monkey 6
|
||||
|
||||
Monkey 2:
|
||||
Starting items: 72, 56, 94
|
||||
Operation: new = old + 1
|
||||
Test: divisible by 13
|
||||
If true: throw to monkey 4
|
||||
If false: throw to monkey 0
|
||||
|
||||
Monkey 3:
|
||||
Starting items: 55, 88, 90, 77, 60, 67
|
||||
Operation: new = old + 2
|
||||
Test: divisible by 3
|
||||
If true: throw to monkey 6
|
||||
If false: throw to monkey 5
|
||||
|
||||
Monkey 4:
|
||||
Starting items: 69, 72, 63, 60, 72, 52, 63, 78
|
||||
Operation: new = old * 13
|
||||
Test: divisible by 19
|
||||
If true: throw to monkey 1
|
||||
If false: throw to monkey 7
|
||||
|
||||
Monkey 5:
|
||||
Starting items: 89, 73
|
||||
Operation: new = old + 5
|
||||
Test: divisible by 17
|
||||
If true: throw to monkey 2
|
||||
If false: throw to monkey 0
|
||||
|
||||
Monkey 6:
|
||||
Starting items: 78, 68, 98, 88, 66
|
||||
Operation: new = old + 6
|
||||
Test: divisible by 11
|
||||
If true: throw to monkey 2
|
||||
If false: throw to monkey 5
|
||||
|
||||
Monkey 7:
|
||||
Starting items: 70
|
||||
Operation: new = old + 7
|
||||
Test: divisible by 5
|
||||
If true: throw to monkey 1
|
||||
If false: throw to monkey 3
|
@ -1,3 +1,426 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{
|
||||
cmp::{Ordering, Reverse},
|
||||
fs::read_to_string,
|
||||
io::Write,
|
||||
ops::{Add, Div, Mul, Rem, Shl, Sub},
|
||||
rc::Rc,
|
||||
str::Lines,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct BigInt {
|
||||
numbers: Vec<u64>,
|
||||
}
|
||||
|
||||
impl From<i32> for BigInt {
|
||||
fn from(int: i32) -> Self {
|
||||
Self {
|
||||
numbers: vec![int as u64],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for BigInt {
|
||||
fn from(int: u64) -> Self {
|
||||
Self { numbers: vec![int] }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u128> for BigInt {
|
||||
fn from(int: u128) -> Self {
|
||||
let lower = ((int << 64) >> 64) as u64;
|
||||
let higher = (int >> 64) as u64;
|
||||
Self {
|
||||
numbers: vec![lower, higher],
|
||||
}
|
||||
.shrink()
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<BigInt> for BigInt {
|
||||
type Output = BigInt;
|
||||
|
||||
fn add(self, rhs: BigInt) -> Self::Output {
|
||||
let (mut output, other) = if self.numbers.len() > rhs.numbers.len() {
|
||||
(self, rhs)
|
||||
} else {
|
||||
(rhs, self)
|
||||
};
|
||||
let mut carry = false;
|
||||
let mut shortest_length = other.numbers.len();
|
||||
for i in 0..shortest_length {
|
||||
let new_carry;
|
||||
(output.numbers[i], new_carry) = output.numbers[i].overflowing_add(other.numbers[i]);
|
||||
if carry {
|
||||
(output.numbers[i], carry) = output.numbers[i].overflowing_add(1);
|
||||
}
|
||||
carry = new_carry || carry;
|
||||
}
|
||||
while carry {
|
||||
if output.numbers.len() == shortest_length {
|
||||
output.numbers.push(0);
|
||||
}
|
||||
(output.numbers[shortest_length], carry) =
|
||||
output.numbers[shortest_length].overflowing_add(1);
|
||||
shortest_length += 1;
|
||||
}
|
||||
output.shrink()
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub for BigInt {
|
||||
type Output = BigInt;
|
||||
|
||||
fn sub(self, other: Self) -> Self::Output {
|
||||
let mut s = self;
|
||||
if s < other {
|
||||
panic!("cannot subtract bigger number from smaller number");
|
||||
}
|
||||
let mut carry = false;
|
||||
for i in (0..other.numbers.len()).rev() {
|
||||
let new_carry;
|
||||
(s.numbers[i], new_carry) = s.numbers[i].overflowing_sub(other.numbers[i]);
|
||||
if carry {
|
||||
(s.numbers[i], carry) = s.numbers[i].overflowing_sub(1);
|
||||
}
|
||||
carry = new_carry || carry;
|
||||
}
|
||||
s.shrink()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for BigInt {
|
||||
type Output = BigInt;
|
||||
|
||||
fn mul(self, other: Self) -> Self::Output {
|
||||
let mut output: Self = 0.into();
|
||||
for &digit in other.numbers.iter().rev() {
|
||||
output = (output << 64) + (digit * self.clone());
|
||||
}
|
||||
output.shrink()
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<BigInt> for u64 {
|
||||
type Output = BigInt;
|
||||
|
||||
fn mul(self, rhs: BigInt) -> Self::Output {
|
||||
let mut output: BigInt = 0.into();
|
||||
for &digit in rhs.numbers.iter().rev() {
|
||||
output = (output << 64) + (digit as u128 * self as u128).into();
|
||||
}
|
||||
output.shrink()
|
||||
}
|
||||
}
|
||||
|
||||
impl BigInt {
|
||||
fn div_rem(self, other: Self) -> (Self, Self) {
|
||||
let mut q: Self = Self {
|
||||
numbers: vec![0; self.numbers.len()],
|
||||
};
|
||||
let mut r: Self = 0.into();
|
||||
for i in (0..(self.numbers.len() * 64)).rev() {
|
||||
r = r << 1;
|
||||
let bit_index = i / 64;
|
||||
let bit = i % 64;
|
||||
r.numbers[0] |= u64::from(self.numbers[bit_index] & (1 << bit) != 0);
|
||||
if r >= other.clone() {
|
||||
r = r - other.clone();
|
||||
q.numbers[bit_index] |= 1 << bit;
|
||||
}
|
||||
}
|
||||
(q.shrink(), r.shrink())
|
||||
}
|
||||
|
||||
fn shrink(self) -> Self {
|
||||
let mut s = self;
|
||||
for i in (1..s.numbers.len()).rev() {
|
||||
if s.numbers[i] == 0 {
|
||||
s.numbers.pop();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
impl Div for BigInt {
|
||||
type Output = BigInt;
|
||||
|
||||
fn div(self, other: Self) -> Self::Output {
|
||||
let (div, _) = self.div_rem(other);
|
||||
div
|
||||
}
|
||||
}
|
||||
|
||||
impl Rem for BigInt {
|
||||
type Output = BigInt;
|
||||
|
||||
fn rem(self, other: Self) -> Self::Output {
|
||||
let (_, rem) = self.div_rem(other);
|
||||
rem
|
||||
}
|
||||
}
|
||||
|
||||
impl Shl<usize> for BigInt {
|
||||
type Output = BigInt;
|
||||
|
||||
fn shl(self, rhs: usize) -> Self::Output {
|
||||
let mut output = self.clone();
|
||||
let q = rhs / 64;
|
||||
let r = rhs % 64;
|
||||
output.numbers.push(0);
|
||||
for i in (1..self.numbers.len()).rev() {
|
||||
output.numbers[i] <<= r;
|
||||
output.numbers[i] |= output.numbers[i] >> (64 - 4);
|
||||
}
|
||||
output.numbers[0] <<= r;
|
||||
for _ in 0..q {
|
||||
output.numbers.push(0);
|
||||
for i in (1..output.numbers.len()).rev() {
|
||||
output.numbers[i] = output.numbers[i - 1];
|
||||
}
|
||||
output.numbers[0] = 0;
|
||||
}
|
||||
output.shrink()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for BigInt {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
let biggest_length = self.numbers.len().max(other.numbers.len());
|
||||
for i in (0..biggest_length).rev() {
|
||||
if i >= self.numbers.len() && other.numbers[i] != 0 {
|
||||
return Some(Ordering::Less);
|
||||
} else if i >= other.numbers.len() && self.numbers[i] != 0 {
|
||||
return Some(Ordering::Greater);
|
||||
} else if i >= self.numbers.len() || i >= other.numbers.len() {
|
||||
continue;
|
||||
} else if self.numbers[i] < other.numbers[i] {
|
||||
return Some(Ordering::Less);
|
||||
} else if self.numbers[i] > other.numbers[i] {
|
||||
return Some(Ordering::Greater);
|
||||
}
|
||||
}
|
||||
Some(Ordering::Equal)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for BigInt {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.partial_cmp(other) == Some(Ordering::Equal)
|
||||
}
|
||||
}
|
||||
|
||||
type Item = BigInt;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Monkey {
|
||||
index: usize,
|
||||
items: Vec<Item>,
|
||||
inspected_items: usize,
|
||||
operation: Rc<dyn Fn(Item) -> Item>,
|
||||
test_divisible_by: Item,
|
||||
test_true: usize,
|
||||
test_false: usize,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Monkey {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Monkey")
|
||||
.field("index", &self.index)
|
||||
.field("items", &self.items)
|
||||
.field("inspected_items", &self.inspected_items)
|
||||
.field("test_divisible_by", &self.test_divisible_by)
|
||||
.field("test_true", &self.test_true)
|
||||
.field("test_false", &self.test_false)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Monkey {
|
||||
fn parse(input: &mut Lines) -> Option<Self> {
|
||||
let mut input = input
|
||||
.take_while(|line| !line.is_empty())
|
||||
.map(|line| line.split_whitespace().collect::<Vec<_>>());
|
||||
let index = match &input.next()?[..] {
|
||||
["Monkey", i] => i.replace(':', "").parse().unwrap(),
|
||||
l => panic!("invalid line: {l:?}"),
|
||||
};
|
||||
let line = input.next()?;
|
||||
let items = match &line[..2] {
|
||||
["Starting", "items:"] => line[2..]
|
||||
.iter()
|
||||
.map(|n| n.replace(',', "").parse::<u64>().unwrap().into())
|
||||
.collect::<Vec<_>>(),
|
||||
l => panic!("invalid line: {l:?}"),
|
||||
};
|
||||
let operation: Rc<dyn Fn(Item) -> Item> = match &input.next()?[..] {
|
||||
["Operation:", "new", "=", "old", "+", "old"] => Rc::new(|old| old.clone() + old),
|
||||
["Operation:", "new", "=", "old", "+", n] => {
|
||||
let n: Item = n.parse::<u64>().unwrap().into();
|
||||
Rc::new(move |old| old + n.clone())
|
||||
}
|
||||
["Operation:", "new", "=", "old", "*", "old"] => Rc::new(|old| old.clone() * old),
|
||||
["Operation:", "new", "=", "old", "*", n] => {
|
||||
let n: Item = n.parse::<u64>().unwrap().into();
|
||||
Rc::new(move |old| old * n.clone())
|
||||
}
|
||||
l => panic!("invalid line: {l:?}"),
|
||||
};
|
||||
let test_divisible_by = match &input.next()?[..] {
|
||||
["Test:", "divisible", "by", n] => n.parse::<u64>().unwrap().into(),
|
||||
l => panic!("invalid line: {l:?}"),
|
||||
};
|
||||
let test_true = match &input.next()?[..] {
|
||||
["If", "true:", "throw", "to", "monkey", n] => n.parse().unwrap(),
|
||||
l => panic!("invalid line: {l:?}"),
|
||||
};
|
||||
let test_false = match &input.next()?[..] {
|
||||
["If", "false:", "throw", "to", "monkey", n] => n.parse().unwrap(),
|
||||
l => panic!("invalid line: {l:?}"),
|
||||
};
|
||||
Some(Self {
|
||||
index,
|
||||
items,
|
||||
operation,
|
||||
test_divisible_by,
|
||||
test_true,
|
||||
test_false,
|
||||
inspected_items: 0,
|
||||
})
|
||||
}
|
||||
|
||||
fn execute_round(
|
||||
&mut self,
|
||||
relief: impl Fn(Item) -> Item,
|
||||
) -> (usize, Vec<Item>, usize, Vec<Item>) {
|
||||
let (items_true, items_false) = self
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| (self.operation)(item.clone()))
|
||||
.map(relief)
|
||||
.partition(|item| item.clone() % self.test_divisible_by.clone() == 0u64.into());
|
||||
self.inspected_items += self.items.len();
|
||||
self.items = vec![];
|
||||
(self.test_true, items_true, self.test_false, items_false)
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_round(monkeys: &mut [Monkey], relief: impl Fn(Item) -> Item) {
|
||||
for index in 0..monkeys.len() {
|
||||
let (index_true, mut items_true, index_false, mut items_false) =
|
||||
monkeys[index].execute_round(&relief);
|
||||
monkeys[index_true].items.append(&mut items_true);
|
||||
monkeys[index_false].items.append(&mut items_false);
|
||||
}
|
||||
}
|
||||
|
||||
fn calc_monkey_business(monkeys: &[Monkey]) -> usize {
|
||||
let mut inspected_items = monkeys
|
||||
.iter()
|
||||
.map(|monkey| monkey.inspected_items)
|
||||
.collect::<Vec<_>>();
|
||||
inspected_items.sort_by_key(|&items| Reverse(items));
|
||||
inspected_items.iter().take(2).product()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = "Monkey 0:
|
||||
Starting items: 79, 98
|
||||
Operation: new = old * 19
|
||||
Test: divisible by 23
|
||||
If true: throw to monkey 2
|
||||
If false: throw to monkey 3
|
||||
|
||||
Monkey 1:
|
||||
Starting items: 54, 65, 75, 74
|
||||
Operation: new = old + 6
|
||||
Test: divisible by 19
|
||||
If true: throw to monkey 2
|
||||
If false: throw to monkey 0
|
||||
|
||||
Monkey 2:
|
||||
Starting items: 79, 60, 97
|
||||
Operation: new = old * old
|
||||
Test: divisible by 13
|
||||
If true: throw to monkey 1
|
||||
If false: throw to monkey 3
|
||||
|
||||
Monkey 3:
|
||||
Starting items: 74
|
||||
Operation: new = old + 3
|
||||
Test: divisible by 17
|
||||
If true: throw to monkey 0
|
||||
If false: throw to monkey 1";
|
||||
let input = read_to_string("input.txt").unwrap_or_else(|_| input.to_owned());
|
||||
let mut lines = input.lines();
|
||||
let mut monkeys = vec![];
|
||||
while let Some(monkey) = Monkey::parse(&mut lines) {
|
||||
lines.next();
|
||||
monkeys.push(monkey);
|
||||
}
|
||||
let min_product: Item = monkeys
|
||||
.iter()
|
||||
.map(|monkey| monkey.test_divisible_by.clone())
|
||||
.fold(1u64.into(), |p, i| p * i);
|
||||
let mut monkeys2 = monkeys.clone();
|
||||
|
||||
for _ in 0..20 {
|
||||
execute_round(&mut monkeys, |item| item / Item::from(3u64));
|
||||
}
|
||||
|
||||
let monkey_business = calc_monkey_business(&monkeys);
|
||||
println!("monkey business: {monkey_business}");
|
||||
|
||||
println!("starting 10000 iterations");
|
||||
for i in 0..10_000 {
|
||||
print!("executing round {i}\r");
|
||||
std::io::stdout().flush().unwrap();
|
||||
execute_round(&mut monkeys2, |item| item % min_product.clone());
|
||||
}
|
||||
let monkey_business = calc_monkey_business(&monkeys2);
|
||||
println!("monkey business: {monkey_business}");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::BigInt;
|
||||
#[test]
|
||||
fn big_int() {
|
||||
let x: BigInt = 1.into();
|
||||
let y: BigInt = 1.into();
|
||||
assert_eq!(
|
||||
x.clone() << 64,
|
||||
BigInt {
|
||||
numbers: vec![0, 1]
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
x.clone() << 2,
|
||||
BigInt {
|
||||
numbers: vec![0b100, 0]
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
x.clone() << 65,
|
||||
BigInt {
|
||||
numbers: vec![0, 2, 0]
|
||||
}
|
||||
);
|
||||
assert_eq!(x.clone() + y.clone(), 2.into());
|
||||
assert_eq!(x.clone() - y.clone(), 0.into());
|
||||
assert_eq!(x.clone() * y.clone(), 1.into());
|
||||
assert_eq!(x.clone() / y.clone(), 1.into());
|
||||
assert_eq!(x % y, 0.into());
|
||||
|
||||
let x: BigInt = 101.into();
|
||||
let y: BigInt = 10.into();
|
||||
assert_eq!(x.clone() + y.clone(), 111.into());
|
||||
assert_eq!(x.clone() - y.clone(), 91.into());
|
||||
assert_eq!(x.clone() * y.clone(), 1010.into());
|
||||
assert_eq!(x.clone() / y.clone(), 10.into());
|
||||
assert_eq!(x % y, 1.into());
|
||||
}
|
||||
}
|
||||
|
7
day12/Cargo.lock
generated
Normal file
7
day12/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day12"
|
||||
version = "0.1.0"
|
41
day12/input.txt
Normal file
41
day12/input.txt
Normal file
@ -0,0 +1,41 @@
|
||||
abcccccccccccccccccccccccccccccccccccccaaaaaaacccccccaaaaaaaaaaaccccccccccccccccccccaaacaaaaaaaacccccccccccccccccccccccccccccccccccaaaaa
|
||||
abccccccccccccccccccaaccaacccccccccccccaaaaaaaccccccccaaaaaaaaaaacccccccaaaaccccccccaaaaaaaaaaaaacccccccccccccccccccccccccccccccccaaaaaa
|
||||
abccccccccccccccccccaaaaaaccccccccccaaaccaaaaaacccccccaaaaaaaaaaccccccccaaaaccccccaaaaaaaaaaaaaaacccccccccccccccccccaaacccccccccccaaaaaa
|
||||
abcccccccccccccccccccaaaaacccccccccccaaccaacaaaccccccaaaaaaaaaaaccccccccaaaacccccaaaaaaaaacaaaaaaacccccccccccccccccaaaacccccccccccaaacaa
|
||||
abccccccccccccccccccaaaaaaccccccccaacaaaaaacccccccccaaaaaaaaaaaaacaaaccccaaccccccaaaaaaaaacaacccccccccccccccccaaaccaaaacccccccccccccccaa
|
||||
abcccccccccccccccccaaaaaaaacccccccaaaaaaaaccccccaaaaaaaacaaaacaaaaaaacccccccccaaccccaaaaaacaaacccccccccccccccaaaakkkaaccccccccccccccccaa
|
||||
abcccccccccccccccccaaaaaaaaccccccccaaaaaccccaacccaaaaaaaaaaaacaaaaaaccccccccccaacccaaaaaaaaaaaacccccccccccccccakkkkkklcccccccccccccccccc
|
||||
abaaacccccccccccaaccccaaccccccccccccaaaaaccaaacccaaaaaaaaaaaaaaaaaaaaccccccaaaaaaaacaacccaaaaaaccccccccccccccckkkkkkkllcccccccaaaccccccc
|
||||
abaaaacccccccaacaaccccaacccccccccccaaacaaaaaaaccccaaaaaaaaaaaaaaaaaaaacccccaaaaaaaaaaaccccaaaaacccccccccccccckkkksssllllccccccaaaaaacccc
|
||||
abaaaacccccccaaaaacccccccccccaaaccccaacaaaaaaccccaaaaaacaaaaaaaaaaaaaacccccccaaaaccccccccaaaaacccccccccccccckkkksssssllllcccccaaaaaacccc
|
||||
abaaacccccccccaaaaaaccccccccaaaaccccccccaaaaaaaacaaaaaaaaaaaaacaaacaaacccccccaaaaacccccccaaaaacccccccccccccjkkkrssssssllllccccccaaaccccc
|
||||
abccccccccccaaaaaaaaccccccccaaaacccccccaaaaaaaaacaacaaaaaaaaaacaaaccccccccccaaacaaccccccccccccccccccccccccjjkkrrsuuussslllllcccccaaccccc
|
||||
abccaaacccccaaaaacccccccccccaaaaccccccaaaaaaaaaacccccaaaaaaaaaacaaccccccccccaacccacccccccccccccccccccccjjjjjjrrrsuuuussslllllmcccddacccc
|
||||
abcccaaaccaccacaaaccccccccccccccccccccaaaaaaaccccccccccaaaaaaaaccccccaacccccccccccaaaaacccccccccccccccjjjjjjrrrruuuuuusssllmmmmmddddcccc
|
||||
abccaaaaaaaacccaaaccccccccccccccccaaacccccaaaccccccccccccaaacccccccccaacccccccccccaaaaacccccccccccccjjjjjrrrrrruuuxuuussqqqqmmmmmdddcccc
|
||||
abcaaaaaaaacccaaaaaacaaaaaccccccaaaaaaccccaaacccaaccccccccaaccccccaaaaaaaaccaaacccaaaaaaccccccccccccjjjjrrrrrruuuxxxuuuqqqqqqqmmmdddcccc
|
||||
abaaaaaaaaaccccaaaaacaaaaaccccccaaaaaaaaccccccaaaaaaccccccccccccccaaaaaaaaccaaacaaaaaaaacccccccccccjjjjrrrtttuuuuxxxyvvvvvqqqqmmmdddcccc
|
||||
abaaaaaaaaaccaaaaaaacaaaaaaccccccaaaaaaaacccccaaaaaaccccccccccccccccaaaaccaaaaaaaaaaaaaacccccccccaaiijqqqrttttuuuxxyyvvvvvvvqqmmmdddcccc
|
||||
abcaaaaaaaaccaaaaaaaaaaaaaacccccaaaaaaaacccccccaaaacccccaaaaccccccccaaaaacaaaaaaaaccaaccccccccccaaaiiiqqqttttxxxxxxyyyyyyvvvqqmmmdddcccc
|
||||
abcccaaaaaaacaaaaaaaaaaaaaacccccaaaaaaaaaaaccccaaaaccccaaaaacccccccaaaaaacaaaaaaacccccccccccccccaaaiiiqqqtttxxxxxxxyyyyyyvvqqqmmmdddcccc
|
||||
SbcccaacccaccccaaacacccaaacccccccccaaaaaaaaacccaccaccccaaaaaaccccccaaccaacccaaaaaccccccccccccccccaaiiiiqqtttxxxxEzzzyyyyvvvqqqmmmddccccc
|
||||
abccaaaccccccccaaccccccccccccccccccaaaaaaaaccccccccccccaaaaaaccccccccccccccaaacaaaccaacccccccccccccciiiqqqttttxxxyyyyyvvvvqqqmmmdddccccc
|
||||
abccccccccccccccccccccccccccccccccaaaaaaaccccccccccccccaaaaaacccccccccccccccaacccccaaaaaaaccccccccccciiiqqqttttxxyyyyyvvvrrrnnneeecccccc
|
||||
abcaaaaccccccccccccccccccccccccccaaaaaaaaccccccccccccccccaacccccccccccccccccccccccccaaaaacccccccccccciiiqqqqttxxyyyyyyyvvrrnnnneeecccccc
|
||||
abcaaaaacccccccccccccccccccccccccaaaacaaacccaccaaacccccccccccccccccccccccccaaaccccaaaaaaaccccccccccccciiiqqqttwwyywwyyywwrrnnneeeccccccc
|
||||
abaaaaaacccaccaccccccccccccccccccaaaaccaacccaaaaaaccccccccccccccccaaaccccaaaaaacccaaaaaaaacccccccccccciiiqqqtswwwwwwwwwwwrrnnneeeccccccc
|
||||
abaaaaaacccaaaaccccccccaaaacccccccaaacccccccaaaaaacccccccccccccccaaaaaaccaaaaaacccaaaaaaaacaaccccccaaciiiqppsswwwwsswwwwwrrrnneeeccccccc
|
||||
abcaaaaacccaaaaacccccccaaaacccccccccccccccccaaaaaaaccccccccccccccaaaaaaccaaaaaacccccaaaaaaaaaccccccaaaahhpppssswwsssswwwwrrrnneeeacccccc
|
||||
abcaaaccccaaaaaacccccccaaaaccccccccccccccccaaaaaaaaccccccccccccccaaaaacccaaaaaccccccaacaaaaaaaaccaaaaaahhpppsssssssssrrrrrrnnneeeacccccc
|
||||
abccccccccaaaaaaccccccccaacccccccccccccccccaaaaaaaaccccaacccccccccaaaaaccaaaaacccccccccaaaaaaaaccaaaaachhpppssssssoosrrrrrrnnneeeaaacccc
|
||||
abccccccccccaaccccccccccccccccaaaaaccccccaacccaaacccaaaaacccccccccaacaacccccccccccccccccaaaaaaacccaaaaahhhppppssppooooorroonnffeaaaacccc
|
||||
abaaccccccccccccccccccccccccccaaaaaccccccaacccaaaccccaaaaacccccccccccccccccccccccccccaacaaaaacccccaacaahhhppppppppoooooooooonfffaaaacccc
|
||||
abaccccccccccccccccccccccccccaaaaaacccaaaaaaaacccccccaaaaaccccccccccccccccccccccccaaaaaaaaaaaccccccccccchhhpppppppgggoooooooffffaacccccc
|
||||
abaccccccccccccccccccccccccccaaaaaacccaaaaaaaaccccccaaaaaccccccacccaacccccccccccccaaaaaccccaaccccccccccchhhhhhggggggggfffffffffaaacccccc
|
||||
abaacccccccccccccccccccccccccaaaaaacccccaaaacccccccccaaaacccaacaacaaacccccccccccccaaaaaaacccccccccccccccchhhhgggggggggffffffffccaacccccc
|
||||
abcccccccaacccccccccccccccccccaaaccccccaaaaaccccccccaaaaccaaaacaaaaacccccccccccccaaaaaaaaccccccccccccccccchhhggggaaaagffffffcccccccccccc
|
||||
abcccccccaacccccccccccccaacccccccccccccaaaaaaccaaccccaaaaaaaaacaaaaaacccccccaaaacaaaaaaaacccccccccccaacccccccaaaacaaaacccccccccccccccccc
|
||||
abccccaaaaaaaacccccccaacaaaccccccccccccaaccaacaaaacccaaaaaaaacaaaaaaaaccccccaaaaccacaaaccaaaccccaaaaaacccccccaacccaaaacccccccccccccaaaaa
|
||||
abccccaaaaaaaacccccccaaaaaccccccccccccccccccccaaaaccccaaaaaaacaaaaaaaaccccccaaaaccccaaaccaaaaaccaaaaaaaacccccccccccaaaccccccccccccccaaaa
|
||||
abccccccaaaaccccccccccaaaaaaccccccccccccccccccaaaacccaaaaaaaaaaccaaccccccccccaacccccccccaaaaacccaaaaaaaacccccccccccaaaccccccccccccccaaaa
|
||||
abcccccaaaaaacccccccaaaaaaaacccccccccccccccccccccccaaaaaaaaaaaaaaaacccccccccccccccccccccaaaaaacccaaaaaaaccccccccccccccccccccccccccaaaaaa
|
@ -1,3 +1,178 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{collections::HashSet, fs::read_to_string};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
enum Tile {
|
||||
Start,
|
||||
End,
|
||||
Hight(u8),
|
||||
}
|
||||
|
||||
impl From<char> for Tile {
|
||||
fn from(input: char) -> Self {
|
||||
match input {
|
||||
'S' => Self::Start,
|
||||
'E' => Self::End,
|
||||
h => Self::Hight(('a'..='z').position(|c| c == h).unwrap() as u8),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Tile {
|
||||
fn can_move_to(self, other: Tile) -> bool {
|
||||
if let Self::Hight(h1) = self {
|
||||
if let Self::Hight(h2) = other {
|
||||
return h1 + 1 >= h2;
|
||||
}
|
||||
}
|
||||
if self == Self::Start {
|
||||
return other == Self::Hight(0) || other == Self::Hight(1);
|
||||
}
|
||||
if other == Self::End {
|
||||
return self == Self::Hight(('a'..='z').position(|c| c == 'z').unwrap() as u8);
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
struct Map<T> {
|
||||
map: Vec<T>,
|
||||
width: usize,
|
||||
height: usize,
|
||||
}
|
||||
|
||||
impl From<&str> for Map<Tile> {
|
||||
fn from(input: &str) -> Self {
|
||||
let width = input.lines().map(|line| line.len()).next().unwrap();
|
||||
let height = input.lines().count();
|
||||
let map = input
|
||||
.lines()
|
||||
.flat_map(|line| line.chars().map(Tile::from).collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>();
|
||||
Self { map, width, height }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Map<T> {
|
||||
fn at(&self, point: (usize, usize)) -> &T {
|
||||
let (x, y) = point;
|
||||
let index = x + y * self.width;
|
||||
&self.map[index]
|
||||
}
|
||||
|
||||
fn at_mut(&mut self, point: (usize, usize)) -> &mut T {
|
||||
let (x, y) = point;
|
||||
let index = x + y * self.width;
|
||||
&mut self.map[index]
|
||||
}
|
||||
}
|
||||
|
||||
fn update(
|
||||
from: (usize, usize),
|
||||
to: (usize, usize),
|
||||
path: &mut Map<Option<u32>>,
|
||||
map: &Map<Tile>,
|
||||
changed: &mut bool,
|
||||
) {
|
||||
if !map.at(from).can_move_to(*map.at(to)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(c) = path.at(from) else {return};
|
||||
let cost = path.at(to);
|
||||
let cost = cost.unwrap_or(u32::MAX);
|
||||
if cost <= c + 1 {
|
||||
return;
|
||||
}
|
||||
|
||||
*path.at_mut(to) = Some(c + 1);
|
||||
*changed = true;
|
||||
}
|
||||
|
||||
fn find_shortest_path(map: &Map<Tile>) -> Option<u32> {
|
||||
let mut path = Map {
|
||||
map: vec![None; map.width * map.height],
|
||||
width: map.width,
|
||||
height: map.height,
|
||||
};
|
||||
let mut start = (0, 0);
|
||||
let mut end = (0, 0);
|
||||
for x in 0..map.width {
|
||||
for y in 0..map.height {
|
||||
match map.at((x, y)) {
|
||||
Tile::Start => start = (x, y),
|
||||
Tile::End => end = (x, y),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
*path.at_mut(start) = Some(0);
|
||||
|
||||
let mut changing = true;
|
||||
while changing {
|
||||
changing = false;
|
||||
for x in 0..map.width {
|
||||
for y in 0..map.height {
|
||||
let point = (x, y);
|
||||
if x != 0 {
|
||||
update((x - 1, y), point, &mut path, map, &mut changing);
|
||||
}
|
||||
if y != 0 {
|
||||
update((x, y - 1), point, &mut path, map, &mut changing);
|
||||
}
|
||||
if x != map.width - 1 {
|
||||
update((x + 1, y), point, &mut path, map, &mut changing);
|
||||
}
|
||||
if y != map.height - 1 {
|
||||
update((x, y + 1), point, &mut path, map, &mut changing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*path.at(end)
|
||||
}
|
||||
|
||||
fn find_best_start(map: &Map<Tile>) -> u32 {
|
||||
let mut start = (0, 0);
|
||||
let mut possible_starts = HashSet::new();
|
||||
for x in 0..map.width {
|
||||
for y in 0..map.height {
|
||||
match map.at((x, y)) {
|
||||
Tile::Start => {
|
||||
possible_starts.insert((x, y));
|
||||
start = (x, y);
|
||||
}
|
||||
Tile::Hight(0) => {
|
||||
possible_starts.insert((x, y));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut map = map.clone();
|
||||
*map.at_mut(start) = Tile::Hight(0);
|
||||
|
||||
possible_starts
|
||||
.iter()
|
||||
.flat_map(|&start| {
|
||||
let mut map = map.clone();
|
||||
*map.at_mut(start) = Tile::Start;
|
||||
find_shortest_path(&map)
|
||||
})
|
||||
.min()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = "Sabqponm
|
||||
abcryxxl
|
||||
accszExk
|
||||
acctuvwj
|
||||
abdefghi";
|
||||
let input = read_to_string("input.txt").unwrap_or_else(|_| input.to_owned());
|
||||
let map: Map<_> = (&*input).into();
|
||||
let cost = find_shortest_path(&map);
|
||||
println!("{cost:?}");
|
||||
let cost = find_best_start(&map);
|
||||
println!("{cost}");
|
||||
}
|
||||
|
7
day13/Cargo.lock
generated
Normal file
7
day13/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day13"
|
||||
version = "0.1.0"
|
449
day13/input.txt
Normal file
449
day13/input.txt
Normal file
@ -0,0 +1,449 @@
|
||||
[[1,[0,3,5,[2,1,3,3,5]],4,[[],5]],[],[0,[7,[5],7,7]]]
|
||||
[[[],[[],[5,2,8,9,7],1,5],[3,[]]]]
|
||||
|
||||
[[[[1,3,6],[7,9,2,7],[5,0,5,8,4]]],[[8,2,6,[]],[],1,6]]
|
||||
[[5,10,4],[6,9,8],[5,[4,[3,8,1,5,1],[4],6,[3]],[[0]],[10],[[5,7],[5,1,1,4,7],[]]],[[[9,7,5,7],[5,1,7,3,1],[8,4,2]],5,[[8,9,3,4,4],4,[2,4,2],3,[6,10,5,7]],9],[[1]]]
|
||||
|
||||
[[[[2,7,2],2],[],[[5],[8,3],3],8]]
|
||||
[[7,1,[0,2],[[1,8,2,0]],[[3],[5,2,5,3,6]]],[3,[6,[4,4,5],[8],1,4]],[]]
|
||||
|
||||
[9,3,3,10,7]
|
||||
[9,3,3,10]
|
||||
|
||||
[[7,3,10,[6,2]],[[]]]
|
||||
[[[[3,2,0,8],8,1]]]
|
||||
|
||||
[[[[6],0,[10]],7],[1,[[3,7,4]]],[[0]],[[],[]],[[[10,8,4,4,2]]]]
|
||||
[[[5,10,0,8],8,10,[[8,9,8,7,7]]],[6],[[6],[5,8,8],1,[4,[6,2]],9],[[[],[9,0],10,[7,1],5],[8,8,[8,6]]],[[[2,2],10],2,3]]
|
||||
|
||||
[[],[3],[],[[4,10,[6]]],[3,[[8,1,10,6],[],[9],4]]]
|
||||
[[9,[4],7,10,1],[[0,[1,3,9,1],[9,5,3,3,0]],2,3],[4,10,[[7,8,6,10,1],9,[0,2,1],5]],[[[5],2],[[4,2,1,9],[4]]]]
|
||||
|
||||
[[[[7,2],[8,2,1]],9,[],9,4]]
|
||||
[[4,8,10],[[[4,7],9,[0,7,3,9,0],7],[10,5],4]]
|
||||
|
||||
[[],[],[[],[[9,7,5,2],[4,4,7,4],1,10,[10,10,4,9,5]],1],[8,[],2,[10,3,[],[]]]]
|
||||
[[[[5,7,3],2]],[[[6,4],6],[],8],[8,[[10,3],[7,1,9],[3,7,7],[6,10,1,6],3],[],3],[[[10,0]],4,6,[6]],[[[10,8,7,1],[],2],[[4,7,9,4],7,2],0,0]]
|
||||
|
||||
[[5,[[],[10,7,1]],2,9,7],[[[3],[4,7,1,0,0],4,[8,9,4],7],[[8,10,4,5,3],[2,3,0,4,10],0],[[6,3,10,8],9,3,[4,6],[0]],8,10]]
|
||||
[[],[[[4,10,6],[],[3,5],10],9,[0,[],[],[5],3],6]]
|
||||
|
||||
[[10,[1,[4,10,0,6],3],2],[2,[4,4,4,7],[4,4,2,[2,4],[1,2,8,3]],[]],[[[5],3],5,[]],[],[[],3]]
|
||||
[[10,[6,9,[1,1],[4,3,5,3,3],[]],8,5],[[6,0],1],[[1],[[4]],5],[[2],[5,[8],[6,5,0,2,10],[7,3],[5,5,5,2]],[8,3,2],0],[6,[]]]
|
||||
|
||||
[[],[],[0,4,[[3],1,10],[8,7,5]]]
|
||||
[[],[[2,5,3],[[10,6,4,1]],1,5]]
|
||||
|
||||
[[[],8,[0,[1,0,1,8],5],[]],[10,[[6,6,8,2,5],[5,8,4,5,8],[],9,8]],[],[],[[[0,5,5,9,0],5],6,[]]]
|
||||
[[1,7],[[],9,3,[6,4,[3],7,[]]],[[0,1],0,10,7]]
|
||||
|
||||
[[[[9,2,3,2,3],[7,7,4],[4],9,3]],[6,0,[2,1]],[0,0],[[3],6],[]]
|
||||
[[[[7,3],3,[8,2,3,5,2]],7],[6,[[6,7],[],[],0,[0,1,5,7]],[[],3,4],4,[]],[[8,8,3,10,[2,5,5,6,3]],1,3],[9,10]]
|
||||
|
||||
[[[],[],[9],[],4],[6,3,6,7],[[0,[8,7],8,7],4,[2],[],2],[[4,10,5,7,[3,6,8,2]],[[],[3],7,[3,1,0,0,4]]]]
|
||||
[[3,6,[[1],[8],[8,0],[0,5,5,3,7]],9,7]]
|
||||
|
||||
[[3,5,[],2,3]]
|
||||
[[[[4,3,4,10,1],[4,0,9],5,8,[4,2]],9,[9,9],1,[4,3,[7,3,5,7]]],[6,[],[],6],[[10,[],[4],[],[2,0,9,5,5]]],[[5],[4,5,[0,1],4],3],[[[],8],3]]
|
||||
|
||||
[[[],[9],[],[],[]]]
|
||||
[[[[6,0,8,1],2,[5,0,3,9],[0],9],4]]
|
||||
|
||||
[[[]],[[[5,10,1,7],[4,3,2,9,10],[4,10],10]],[6],[4,1,[5,[8,8,9,10]]]]
|
||||
[[[7,[6,1,9,6],[2,3,8,8]],10,[[],[6,2],10,7,[6,10,9]]],[[1]],[[6,[5,1,2,4],3]],[[8,9],4,8,10,[9,8,10]],[[3,9,2,[2,5,1]],1]]
|
||||
|
||||
[[1,[8,6,[0,7,3,10,6]],6],[8,[[1,4],1],7,6],[],[[]],[[[1,5,7,2],8,0],[]]]
|
||||
[[9],[10],[[[9],9,2,[0,3,4,5]]],[[4,9,[9,2]],[]]]
|
||||
|
||||
[[[4],8,[3,[6,9],[7,9,4]],[3,0,[]],[]]]
|
||||
[[],[9,[[6],[2,4],[],[3,0,0,6],9],[[2,4,0,3]]]]
|
||||
|
||||
[[8,[[1,7,5,9,6],7],9],[9,5,[2,3,[]],[7,6,[10,1,1,4,1]],[]],[[[8,0,2,6,4],5],[[2,5,0],[2,10,4],2,2],1],[1,[[7,6,6],[10,10,2,9,10],[2,3,7,10,9],[10,5],[3,3,9,5,6]],[[6,8]],[],[5,4,0,[]]],[9]]
|
||||
[[3,[[4],[]]],[],[8,[1],1,3],[[1,7,7,3],[[3],2],2,[8]]]
|
||||
|
||||
[[8,[9,[10]],7,[[1,0]],[[4,8,5],[9],0,9]],[[8,[8,7,7],0,0,1],0]]
|
||||
[[],[[0],[]],[[[5,4,3],[0],6,[4],3],6],[3,1]]
|
||||
|
||||
[[[[0,5],[7],[2,4,7,8,0],2]],[],[],[3,4,7],[]]
|
||||
[[5,[[4]],9,5,5]]
|
||||
|
||||
[[[[6,7],9,9,8,2]]]
|
||||
[[2],[[],[[1],10,[6],10],[1,[9,4,8,7,10],[8,10,8,5]],[1,7,9,5]]]
|
||||
|
||||
[[5,2,[7],[4]]]
|
||||
[[0,[[5],4,9,1,[0,5,5,6,2]],[5],9,[6,0,10,[10,8]]],[],[[8,5,[8],[5,9,6],[4,4]],[3],[[4,5],[1,9,10]],[7,1,7]],[0]]
|
||||
|
||||
[[[],[0,9],2,7,9]]
|
||||
[[[],[10,4,2,[3,9]],[[7,7,7,1],[2,2,0],[6,10],[10,1,7,9]],9],[],[3,[[0,9],3,[8,10,6,4]],[[5,3,3,10,5],[8,4],9],[[],0,9]],[2,10,7,[[5,1,1],3]],[]]
|
||||
|
||||
[[[5,[4,5,2,2,8]]],[4]]
|
||||
[[],[0],[]]
|
||||
|
||||
[[7,[]],[3,[2,[0,6],2,[10,5,10,3],[4]]]]
|
||||
[[1,6,[[9],9,2,[1,4,4,3,4]],[[8,2],[10,3,1],[4,9,4],[6,8],[0]]],[9,[1,[],0,2,0],[[6,7],4,1,[3,10,0,7,1],[]],3,[8,[9],1,3,9]],[10,[10],9],[[9],[[0,5,8,2],[],4,10,[10,7,2,8]],[5],[],[[2,8,9,3]]],[]]
|
||||
|
||||
[[9,3,[[],[],[1,4,7],[10,2,10,3,1],[]],5,[[5,3,3,0,7],6,9]],[5,[[],9,9,[1,10,5,7],3],[[6],[],[10,3,2],7],10]]
|
||||
[[4],[3,[0,[],[8,10,8],8,[3,5,5,2]]],[[9,7,[],[5,7,2,9],[]]],[[9,[4,8,4,10],4,2,7],9,10,5,[9,6,7,6,6]]]
|
||||
|
||||
[[],[5,6,[3],4,3],[[8,6,[],8],5],[8,[8,2]]]
|
||||
[[8,[],[2]],[[[10,8,3,1],5,[2,7],7,8],3,0,6,9]]
|
||||
|
||||
[[[[3,9,5,8,1]],[7,[],[4],[],[]]],[7,10,9,[[8,8,2,3],4]],[[10,[3,2,2],10,9],2,4,[8],1],[[1,2,3,[]]],[[10,8,[7,9,6,2]],[3,4,[1,10,5,3,9],6],[7],2]]
|
||||
[[[[7,0],6],[4,[10,6,9,8,1]],[0,4,9,8,0],[[]]],[]]
|
||||
|
||||
[[],[]]
|
||||
[[8,0,9,[[2]],[]]]
|
||||
|
||||
[[[],[[10,1,8,10,1],6,8],10,[[9],[],0],[[9,5],7,[10,7],6]]]
|
||||
[[],[],[7,[],[],[[1,8],7,6],[[2,1,1],9,[4,9,2,9,6],[3]]],[[[6,5],[2,10,3],6,[8]],[[7,2],[5,9],[],2,1],[[3],9,[0]]],[[[],6,9],[],[[7,3],5],[[]]]]
|
||||
|
||||
[[],[9,[[4,6,9],[9,1,9,1,10],[0,0,5,10]]],[[],[[7],[7,6,4,1,4],7,[0],[10,3,5,0]],[]],[5]]
|
||||
[[[]],[],[[2,[0,8],9,6,[4]],[7,[3,7],[1,7,6,7,7],[6,9,7,3,8],[2]],[10,[5,3,1,8,8],2,8,[]],0],[4,[7,0,[]],6]]
|
||||
|
||||
[[[9,9,7],[[8,0,3,0],6,[],10,2],1],[8,[],[[6,4],1],10],[2,[4],[2,2],8],[4,[[],[2,10,4,1,10],3],5,9]]
|
||||
[[4]]
|
||||
|
||||
[[[[10,6,6,10],[],[],8,5],[[8,10],10],10],[6,[5,8,[],[]]],[[0],1]]
|
||||
[[[6],[2,[8,2],8,5,[6,9,4]],[[],10,[9,1,9,9]]],[8,[],10,[[0]],[[]]],[],[4]]
|
||||
|
||||
[[[],[1]],[[10,[]],[[5,6,8,4],[0],[5,6],0,[10]]],[],[[4,6,[8,9,7],0],[],[[3],1,8,6],[[8],10,5,[7,0,10,8,9]],[[10,3],10,[0,6],[],[0,10,2,3]]],[]]
|
||||
[[9,10,8,0,3],[5],[5,5,5],[[1,8],1,5]]
|
||||
|
||||
[[[[7,1,7],1,[1,9,6,9,1]],[10,[0,9,3,6]]]]
|
||||
[[5],[[[],2,[9],2,4],5],[]]
|
||||
|
||||
[[],[[],2]]
|
||||
[[0,10,[6,[7],8]],[],[6,1,6]]
|
||||
|
||||
[[[6,[],1,6,[2,5]],7,[[7,0,5],[2,8,3,7,7],5,0],[2,[7,4,8],0,5,1],3],[3,[1],[8,1,[10,5,7,2,5],3,[1,5,10]],[9,[1,6],4,[]],10]]
|
||||
[[[10,6,7],10,[[2,2],2,[],[6,0],[10,10,7,7,5]]]]
|
||||
|
||||
[[[[2,3,8,2],[],6],9,[],[0,[0,2,6,9]],[6,[],5,[3,4,3,4,8]]]]
|
||||
[[10,[[3,2]],[7],3],[[[2],[3,5,8,7,2]],[10,1,10,[10,9,6,7],8],[[0,5,5,9],0,[]],4],[[7],7,4,[]]]
|
||||
|
||||
[[],[],[1,[],[]],[[4,[4,9],10,1,[4,8,2,5,7]],[[1,6,3,4,0],2,[9],4],[[3,3,6,8],10],1,[8]],[8]]
|
||||
[[6],[[1,8,[0]]],[[],1,[[4,3,7,8],[8,0],2,[4,8,2,3],[10]],2],[10,3,8,[0,[7,4,2,8,1],[10,4,6,8,7]]],[[10],[4,10,7,0],10,[[9,1,7,7],6]]]
|
||||
|
||||
[[6,[]]]
|
||||
[[],[[],[6,[],10,[]],3,10],[],[10]]
|
||||
|
||||
[[[],0,[],[[4],[3,2,6,4]],[6,6,7]]]
|
||||
[[1,0,8,[[9],8,[],[1,6,2,6,6],2]],[],[[9,2,[9]],9,[1,4,[7,7,10,10,3],2,[7]]],[],[]]
|
||||
|
||||
[[[8]],[]]
|
||||
[[[]],[3,9],[],[0,[8,[10,6,4,1,8]],2,4,8],[6,5,7,[3],[0,10,3,[9,0,2,0],2]]]
|
||||
|
||||
[[[[0,9],5],10,10]]
|
||||
[[],[],[3,7,[],0],[7,5],[9]]
|
||||
|
||||
[[[],9,[]],[3,[],[0,2,[5,5]]],[10,6],[8,[[2,6,2,9],[0,4],10,[6,5]],[3],2],[]]
|
||||
[[8,7],[4,7,1],[[7,0,0,3],4,[[5,2,10]]],[1,1]]
|
||||
|
||||
[[7,[[],[8,0],1,8],4,[3,[4,7,0,9,8],[7,4,10,3],3,3]],[[8],6],[0,[[9,2,8,1,9],[10,5,2,2],[7,1,2,4,3],6,[6]]],[[[2,7,2,5,8],8],[3,5,8,[4,8,6]],[8],[[8,0,9,7,10],7,[0,1,10,8,1],5],[]]]
|
||||
[[5,8,0],[],[[[7,1,5,1],[9,8,8],7]],[[10,2,[0,0,7,7,5],5],[0,[1,9,1,0,5],2,[0,2,6,8],[2,1,2,10]],[],[[]],[[1,0,8],[2,7]]]]
|
||||
|
||||
[[[[7,10,7,8,3],[5,3,8,4,4]],[6,[2,4,5],[0]]],[[[3,0],[10,4,8],1]]]
|
||||
[[6],[1],[[[7,10,4,5]],9,8,6],[]]
|
||||
|
||||
[[7],[6],[2,[],7]]
|
||||
[[[8,10]]]
|
||||
|
||||
[[7,9,[5,1],[[],2],[2,[10,10,3,0],[],[3,10,6,9]]],[9,1],[7,[[0,6,2],4,8,[10,3]],2],[]]
|
||||
[[[[],[2,4,6,2,9],[0,10,7],[],4]],[[8,[0,8,6,8],8],6,1,2],[],[[[8,7,10,4,1],[10,5]],[],2,[8,[9,3,6],1,0,[4,8,4,5]]]]
|
||||
|
||||
[[],[[[9,9,10,4],[6,6,1,9,0],3,7],7,[[9,2,0],3,10,0],7,[7,2,2,8]],[9,9,0,[]],[[[10,7,7,2,3],[1,7,10,8],[3,1,6,0],1,[9,4,6]],[4,[]]]]
|
||||
[[[8,[9,0,10,4,5],[2,6,0,4,9],7,2]],[2,[[6,1],[10,2,5,1],[9,0,0,3,4]]],[[1,[3],0,[]],1,[],2,[9,5]],[[6,[1,5,7,8,7],[]],[]],[[2,[6]],10,4,[2,9,[3,2,3],[8,6,6,0,8]]]]
|
||||
|
||||
[[[[5,8],8,[4,7],[10,8,5],8],[],[1,[10]],[]],[[[10,7,1,3]],[4,1,[7,6,7],[2,2,3],4],7],[9,10,4]]
|
||||
[[[2,1,[10,5],[5,10],3],[[4,4,6,1]],10,2,[6,3]],[[[1,2,0,5,5],1,9]],[[],[[5,7,0,4,9],4,[9],3],[],[[8,1,10,6,8]]],[[[8,9,1,2]],[],1,[[0,0]],7]]
|
||||
|
||||
[[9,[[3]],[[2,5,1,4],[1,2,1,5]],[9,[7,7]],9]]
|
||||
[[],[[0,[5],2,[],[4,3,0,2,3]],3,1,1]]
|
||||
|
||||
[[[4,3,[3,10,9],[7,7]],[6,4,7],1,10,1],[],[],[],[7]]
|
||||
[[[0,[2,8,3],7,[4,9,4,2,7],2],7,[[],[10],1,0],[0]],[8,[],[[6,6]],[[8,9,6,1,3],4,[2]],10],[[[5,0],2,[4,8,4,9,10]]],[[3,1,0,5,4],[[8,10],[10,8,5,8]]]]
|
||||
|
||||
[[[[4,6,8,4]],[[8,2,8,1],[1],[5,10],[],[2,3,7,8]],0,[[6,2,1,7,9],[1,1,1,4],0,8]],[8,7,[7,2,5],[[3,1,8,0,3],[]]],[[[7,1,10,0]],3,[[10],4],[9,2,[7]]],[7,3]]
|
||||
[[[[1,9,2]],8]]
|
||||
|
||||
[[6,6,[8,4,8],[[0,7]],[[3,2],[6,2,5,10],2,10]]]
|
||||
[[[5,6,[],0],[6],[],[9,3,1,3,[]]],[1,[4,[8]],[2,[4,1,0,5],8,[7,0],5],3,0],[1]]
|
||||
|
||||
[[[[4,1,2],0,9,[6],[0,5,2,7]],7,[[5,10,2,1],[3],1,1]],[[7],[6,[3,8,0],[0]],9,[1,[1,5],[10,9,0,6,0],2],10]]
|
||||
[[],[1,4],[8,[[6,3,10],9],[[7],4,4,[4,0]],[[9,3,10,8]],7],[7,6]]
|
||||
|
||||
[[5],[[7,1,1,8,[5,0,3,6,3]],0,[7,2,4],[7,[7,8,3],0,10,[6,0,6]]],[[[1],2,3,4]]]
|
||||
[[8,2],[2,8],[1,3,[8]]]
|
||||
|
||||
[[[[8,2,4,0,1],[3],[4,8,9],7,2]]]
|
||||
[[3,[],[[9,9,4]],[2],5],[[0,[2,9,4,1],2,[],1],[[10,8,2,4],[],2,10,[3,1]],4,6]]
|
||||
|
||||
[[10,[[3,8,2,1,1]]],[1,[[6,6,5,3],[]],[[0,1,5,6,6],10,0,[0,5,6,1]]],[1],[[],1],[8,[],[[1,7,2],10,7,[0,0,1,6,9]]]]
|
||||
[[[2,[5,6,9],[3,1,9,5],[5,7,3,4,9],1],[0,[1,1,9,0,5],4],[1,6,[3,8,8,10,1],[0,9,6,7],4],[[7,2],7]],[[[8,3,6]]],[0,[[9,5]]]]
|
||||
|
||||
[[[[10]],[],[[0,4,8,8,6],9,[6],[10,3,6],[]]],[[[2,9,4,10,10],9],8,[[2,5,5,8]],[[1],1,[0,10,5]]],[[[],9,3,10],8],[[]]]
|
||||
[[0,[0,6,[3,0,10,3],3,[1,10]]],[8]]
|
||||
|
||||
[[[10,[6],1],[9],8,[],1]]
|
||||
[[[2,5,[10]],8,[3,6,[8],[4]]],[4,1,[10,[4]]],[8,7,2],[[6,[],10],[9,[4],8],[],[[4,7,6],0]],[4,[[2],[7],[7,5,2,7,7],4],[9,[0,8,10,6]],[],5]]
|
||||
|
||||
[[[[9],[4],[],[0]]]]
|
||||
[[[],9,2],[],[[3,2],2,[8,6,10,1]]]
|
||||
|
||||
[[4,7],[5,9,[],[[3,9,2],[3],9]],[[],[[0],5,[6,2],9,8],2,6,10],[4,10,3,10]]
|
||||
[[9,3,1,5,2],[]]
|
||||
|
||||
[[[[2],[7,0,9],[0,2,5,8],4],3,[],2],[[5,4],0],[],[[],[[0,10,3,5,7],[8,8,4],[]]],[[8,[],[]]]]
|
||||
[[[10,0],[[1,3],[]],[2]],[5,1,[],[[5,2,2]],[[2,7],[],[5]]],[]]
|
||||
|
||||
[[[[10,5,6,1,1]],4,7,4,[[6,4,7],[6,5]]],[[[7,9],[3]],4,[3],0],[]]
|
||||
[[2,[],1],[[8,1,6,[4,7]],[8],3,[[],[4,1,2,0]],2],[[1],[],8,4]]
|
||||
|
||||
[[8,[]]]
|
||||
[[[[0,10],[1,0],[2,7],4,[]],1],[5,[[],[4,6,3],[0,5,4,5],2,[]],[[7,10],[4,3,4],2,[]],9,9],[4,[[8,8],3,8,10,[7,0,0,1]],[[1,5,2,9,9],[0,1,0,0,4],4,[3,5,1],8],7],[1,2,9,[5,[10,7,9,5,0],[3],3],0]]
|
||||
|
||||
[[9,6,1],[[3,8,10,[],[4,1,10,6,2]],[]],[[4,8,8,10,[2,7,0,1,6]],2,8,[[7,3,5]]],[[[2,4],[],[5,9,0],[2,1,6]]],[[[3,7,3],[1,2,2],8],[],7,[[2],[1,6,3],[1,6,6],2],5]]
|
||||
[[1,8,1,[],[[8,2,6,0,8],10]],[5,[[7,9,0],[5,6,5,4],[3],3],4,[[],0,[4]],3]]
|
||||
|
||||
[[[[],8],5,7,[[5,5,2,2],1],7],[4,7,[9,[3,2,7,2,0],[],[9],10],10,[7]],[1,[10,9,4],[3,5,[3,5,1,8,0]]]]
|
||||
[[[7,[4,10,7],[1,6],9],[],5,1,[[3,2],[0,9,0,1],[0],9,4]]]
|
||||
|
||||
[[1]]
|
||||
[[[],3,5,[[7,3,1,8,5],7],[6,[0,8,2]]],[7,[[10],[6],1,5],[],[]],[5,[[1,2,9,1],[1,6,6,10,0],1],8],[10,6,5,[[5,0,2,10]]],[]]
|
||||
|
||||
[[10,[[4,1,1,0],[4,9,1,1,6],[7,7],[5,7,9,0,4],[10]],5,[[4]]]]
|
||||
[[4,2,3],[9,[],[[],[0,8,9],[3,6],6],9],[[4,[8,9,5]],6,[6,[4],[9,9,7,9,8],[9,3,6,9,5],[4,6,2]]],[[[1,0,8,4],[6,3,4],6,[9,9,6]]],[0,[4],[],9,0]]
|
||||
|
||||
[[[7,5,10],1,[10],1],[[[1,3,4,10],[2,6,5,5],5,3],[[7,10],[8,8],9,7,0],7,0],[]]
|
||||
[[[[5,7],8],[],[8,[9]]],[0]]
|
||||
|
||||
[[[10],6,[10],[[],1],8],[[[1,3],1,[3,2,6]],[10,9,9,0],[[0,6,8]],[[],[3],[6,6],1,[]],[[0,7,3,3,2],[9,6,6,6],7]],[[8,6],[[0,1,0,3,2],[8,7,6,0,5],9,[8,9,7]],2],[5,[10,3,[2,3],[4,0,8,5],[4,8,4,0,8]]]]
|
||||
[[4,8,[1,3,[]],[[],[4],[],8,7],5],[8,4,[]]]
|
||||
|
||||
[[[[10,4,6,9,6],3,[3,2],9,[9,3,10,4,3]],2,0,[6,[8,1,3,2]],[3,9,1,0]]]
|
||||
[[[0,[5],7],[[]],[2,9,7],2],[8,[[2,0,9,0,1]],8],[[[3,6,8,2],[],1,[3,7]],0]]
|
||||
|
||||
[[[[1,9,2,6,6],[6],[7,3,3,4,3],1,[9,3,0,3]],2,[[5,8,0,3,5]],[[7,0],[9,8],[6,5]]]]
|
||||
[[[8],8,8],[1],[9,9,[],[8,1]]]
|
||||
|
||||
[[5,1,[3,6,[5,4]],[[6,8,10,4]],[[10],[2],[],2]],[6],[2,6,3]]
|
||||
[[7,9],[[[4,3,3]]]]
|
||||
|
||||
[[10,3,4,8]]
|
||||
[[[[2,10,4]],[[]]],[],[7,8,0],[6,[5],7,6,[[10,7,0,7,4],[4,2,9,3,7],[]]],[9,[7]]]
|
||||
|
||||
[[6],[[8,[9],[3,6,0,8,6],7],9,4],[[],[[10,0],[9,3,8,10,1],[10,4]]]]
|
||||
[[6,[2,[0,0,0,5,5],[7,1,2,9],7],[],0,[8]],[],[6,9,6],[8,4,[[7,3,3],[3],6],0,0],[]]
|
||||
|
||||
[[6,[[6,9],5,5],[8],10,[[4,2,8,1,10]]],[[5,[]],10],[6,9,9,3]]
|
||||
[[[8,9],[[8],6],5,[[10,3,9]]],[[[1,7,3]],[9],6,5],[[[]],2,[],[[4,5,7],0,6,[10],7]]]
|
||||
|
||||
[[],[[4],[[5],[9,7],[4,8,9]],6,3],[0]]
|
||||
[[1,[[7,5,1,8],[6],[0,8,9]],[[5,0,4],[1,3,4,9],8,[7,4,4,7]]]]
|
||||
|
||||
[[3]]
|
||||
[[[],[3,[5,10],2,[6,3,0,0,4]]],[9,[1,[0,5],[8]],2],[[[4,2,9],2,[4,0],8,[]],[1,[],[8,2]],9,[],[]],[[2,[0],[7,7,8],4],8,[3,[8,10,1,9],[8],[1,6,7,3]],8,[0,[2,0,6,5,10],[],8]],[7,[7],5,6]]
|
||||
|
||||
[[],[4],[]]
|
||||
[[[7],7]]
|
||||
|
||||
[[],[3,7,3]]
|
||||
[[[7,[9,9,2]],10],[]]
|
||||
|
||||
[[[5,[0,8]],6,[[5],6,[6,7,9,8,1]]]]
|
||||
[[[9,0,0,6,[5,1,2]],[[7],[2,4,3,7,2],1,[9,2]]],[10,[4,[3,6,3,5,2],5],8],[]]
|
||||
|
||||
[[],[10]]
|
||||
[[5],[]]
|
||||
|
||||
[[[1,1,6,10],[[],3,[8,1,0],[4,10,10,6],[10,4,2,2,7]],5,[[8,6,2],[],[1,4,3,5,3],[4,4,0,10],10],1],[[],5,8],[[3,[],10,6,[8,1]],1,2],[1],[[[0,5,2,4],[4,10,9,2,2]]]]
|
||||
[[],[2,[[10,9,1],[10,4,9],4,[2,9,10,7,5],[2,9,0,9]],4,[6,0]]]
|
||||
|
||||
[[[],1,7],[6,[2,1,6,5],[[5,6]],6],[[2,5,3,6],[],7],[]]
|
||||
[[0,6,[5],[[],4]],[0,9,3,[[7,0,8]]]]
|
||||
|
||||
[[[[9],[4,5,0,10,10]],[6,8,[3]],[],[4],[7]],[1,[4,[1,10,7,5,10],[],[]],[[1],8,5,[5]],8,[[4,8,2,10],0,1,[6]]]]
|
||||
[[[],4,0,[[2,0,3,5],4,[10,2,3]],4]]
|
||||
|
||||
[[8,[],4,1,[]],[],[[1,[4]],0,[10,[5,5,7],[6,6]]],[[[]],[[8]],5]]
|
||||
[[[],0,[[10,7,9,6],3,10,6],[]]]
|
||||
|
||||
[[[0],6,10],[[[0,0,1,10,7],[0,0,6],8,7],1,[[5,9,4,9]],[[6,2,1,3],[2,9,9,7]]],[[3,4,2,10,[5]],[8],9],[5,1,8,[4]]]
|
||||
[[[[10,4,5],[6,1],[9,4,9,5,5],[10]]],[[10],7,[10,[4,4],[8,4,2]],5,9],[7,6,4],[[5,1,9,[1,2,9,10]],3,7],[9,5,[5,[],[],7],[[8,10],6,10,8],10]]
|
||||
|
||||
[[[[4,8,9,0,2],[7,7],6,7,0],[7,[7,6],10,2,[]],[9],[2,[7,8,4]],[9,[1,7,6],[0,6],9]]]
|
||||
[[6,1,[[],[6,10,1,5,9],7,[4,4,0],[]],[[2,7,5],[],3,[2,0]]],[],[[[],3,9,[6,8]],7],[1]]
|
||||
|
||||
[[],[6,[],9,9,[[8],[],9,10]]]
|
||||
[[8,[[8,4,0,7,9],3],[[9,9,9]]]]
|
||||
|
||||
[[[],3,3,1],[],[6,6,8,[3,[10,3,7,2],1]],[[[2,0,2,1],9,[7,10,10,4],[0,1,6,9],[7,3,8,7]],7,9]]
|
||||
[[[0,10,6,4,9],5,8,[]],[[6,9]],[[],[[2,9,9,7,9],[5,2],5],0],[[[2,4,0],[4,8,2,3,1]],5,[1,[1,5,0,10,4],10,9],[[0,7],[9,2,2,6],4],[8,[],[]]]]
|
||||
|
||||
[[[[0,1],[6,1,3,3,3],0,10],8,2,7,3]]
|
||||
[[2,[4,[4]],4,9],[8,[6],6,8,[6,1]],[]]
|
||||
|
||||
[[10],[[],6],[],[],[2,[[9,3,2],[5,3,0,0,6],[6,2],1],[[3,8,2],[10,10,0,0],[5,10,6],[8,5,0]]]]
|
||||
[[[[],3,8,2,[2,6]],[[],5,1,[1,5,6,0,9],[10,4]],2,3,[[1,4,10,6],[1],9,[8,4,9]]],[3,2,[[6,4,6,9,8],5],[1,[3,0,6,7,2]],10],[]]
|
||||
|
||||
[[[[6,2,2,6],[5,8,5],5,5,0],[],6,[4],[2,9,[9],[2,8,6],6]],[],[[3,[5,8,5]],6,[[9,4],[6,4,10,1,2],[7]],[10,2,[4,3,6],2],6],[[],1,[0,[4,2,4,7],4,[7,2],2],[],[[8,0,8,1,2]]],[[8,8,[]],[[3,4,3,2,0]]]]
|
||||
[[[[9,2,1,9],10,[7],[5,8],[1,4,0]],[[],2,[8,5]],7]]
|
||||
|
||||
[[[[],[5],0,[5,1,8,10],8],10,2,8],[[]],[[7,4,10,4,[2]]],[[[3],[9],10],[7,6],3,[9,[9,4,5],[4,0],2],2]]
|
||||
[[8,[[3,9,8]]],[9],[],[]]
|
||||
|
||||
[[[1],[[7,0,9,6]],[2,[5,10],[],0,[10,7,10,4,9]],[[10,4],[7,7,6]]]]
|
||||
[[[2,[],[0,6]],[[7,3]],[[]],0],[4,[5,10,[],[7,4,0,1,5]],5,10],[[],[[]]],[8,[[10,3,10,8],2,[8,0],[4,2,7,2,0],5],10,10]]
|
||||
|
||||
[[2,[],[]],[[[2,1,10],0,6]],[[[8,9,0],0,[],0,[10]],[[],10,2,4],6,[]]]
|
||||
[[[[],9,8,[6,6,7],[4,9,3,3]]],[[5],[[9,1,0],[],[6,1,1,5,2],8],[[5,10,2],1,[0]],[5]],[10,5]]
|
||||
|
||||
[[7,1,4,3,[7]],[]]
|
||||
[[[7,7],3,[3,[9,3,0,1],[0,1,0,9,9],3,2]],[]]
|
||||
|
||||
[[9],[3,[],[6,1,[1,10,7],8],0]]
|
||||
[[3],[8,4,[[],[0,7,9,8],10],1],[],[]]
|
||||
|
||||
[[7],[],[6,7],[[[9,0,4,10],[4,0,10,9,2],0,[4,2],[]],9,[[0,2,10,2,1]]],[[]]]
|
||||
[[[1,8,6,8,[]],[],5],[1],[4,[[2,3,2],[8,7],[2,4,0,2],[6,7,1,8]]],[5,0,10,[5,5,10],[]]]
|
||||
|
||||
[[9,[7],8],[0],[6,[0],[1,[7,8]],[6,[5,7],4]],[[[4,5,5,10],[6,6,9,8],[7,9,9,1],3,[6]],[[9,9,1],[9,3,8,4]],[[],[1,10]],[[6,10,1,10,5]]],[[[]],[[]],5,[0,2,7,8,8]]]
|
||||
[[[[3,9],[3,8,4,9],[1,7],[10,0,2],[2,3,2]],[[3],[7,10,1],10,[5,1,6]]],[1]]
|
||||
|
||||
[[],[8,2,3,10,[[2,0,2,8,1],[],[3,6,3],10,[5]]],[[]],[[],[1,10,3]],[8]]
|
||||
[[10,10]]
|
||||
|
||||
[[3,[[],[8,8],9,1,[1,5,9,7,4]]],[2,[[3,0,8],[5]],[8],[[5,1,6],8,5],6],[[10,8,3,7,[6,3,4]],[],6,10,3]]
|
||||
[[[3,1,5,3,[6]],6,[[9],5,6]],[[[1,10,6,2],[0,10,0,7],[9,4,1,2,9]],1,9],[]]
|
||||
|
||||
[[[],9,6],[[[2]],7,[9]],[[4,[1]],10,[[],5,[8,1,6,0]],[4,9,3,[9]],[8,[10],[4]]],[3,[2],[4,2]],[]]
|
||||
[[9,6,[[2]]],[[9],[],[9],9,[0,[7,3,0,3],0,[1,6]]],[[5,1],7],[[[5,7],[7,0,4],[]],3,7,[]]]
|
||||
|
||||
[[],[4,[6],2,[[8,4],[],8,[8,1,0,5],4],[[9],[]]],[1],[6,[[4,1,6,8],4],[],[],[]],[[8,[9,5,3,3,4],[2]],10,5,[],[7]]]
|
||||
[[[[3,0,6],[4,3,6,4]],6,[[8,1]],[[],[0,1,1,4,0]]],[8]]
|
||||
|
||||
[[[[0,7,3,7],8,[5]]],[],[8],[[],7,[6],[5,2,1,[9,6,7,3,5]],[[9,8,4,8],0,[4,4]]]]
|
||||
[[[],5,2,[],3],[[10,8,[5,8,1,2]],[[0,7],6,4]],[],[3],[6,3,[[]],[8]]]
|
||||
|
||||
[[[10,0,9,0],1],[7,[[6,6,0],2,9,3,2]]]
|
||||
[[0,[6,2,[8,9,1,3],[1,4,4,4]]]]
|
||||
|
||||
[[[[4,7,7,5]],[[6,10],[4,2,5,7,6],1,10,7],[]]]
|
||||
[[[10,8,[8,10,1,4],[0],[1,7,0,1]],6,[3,0,0,[3],1]],[1,5,6,[[],2],8],[10,10,[]]]
|
||||
|
||||
[[2,7,7,[2,[3,6,1,1]],[5,3,[6]]],[10,9],[],[[[],[3,9,7]]]]
|
||||
[[[],[[4,8,8],[9,6,0,10],[6,8,4,7,1]],8,[[],[9,6,6,8],[1]]],[],[5,0,[[4],8,9],9]]
|
||||
|
||||
[[0,[10,10]],[[6,9,[5,1],6],10],[10,[[8],0,[4,2,1]],[7,[5,0,10,7],10,1],[8]]]
|
||||
[[7,[[5,0,8,1,0],[3]],2,7],[10,[2,6,[8]],[[],7,[],9,[7,6]],8],[[[2,5,2],[2,3,4,0]],4,[[6],[]]],[[[5,0,6,3,2],4,[3],[5],[2,8]]]]
|
||||
|
||||
[[0,[[],6,6,[1,10,0]],10,6],[[[4,5,4,6],[1,8],[4,6,5]],4,[5,2]]]
|
||||
[[6,7,8,[4,2],6]]
|
||||
|
||||
[[[5,[5,4,3,1,10]],[10,4],7,[[6,6,2],1,[2,6,4,4],[7,9,2]]],[[[10,4]],9,6,2,2],[[]]]
|
||||
[[[],1,0],[2],[],[[6],6,0,[]],[[],2]]
|
||||
|
||||
[[],[[9,[1,4,5],8,3],[[],[2,9,5,3],10,4,8],[2],7],[4]]
|
||||
[[[[5]]],[8,[],5,[[7,3,9,5]],[6,10]],[8,4,[[1,0,2,0,4]],[6,6,[5]]],[[[6,7,4,2,4]]]]
|
||||
|
||||
[[[2],6]]
|
||||
[[4,4,6,[[0,3,9,5],10,[8,4],[9,6]]],[10,6,6,0,[[],4]],[],[[5,9,0,[5],8]]]
|
||||
|
||||
[[10,7,4],[3,[],0,[3,1]],[],[5,[1,[6,4]],1,10],[]]
|
||||
[[[1,6],3]]
|
||||
|
||||
[9,3,1,7]
|
||||
[9,3,1,7,6]
|
||||
|
||||
[[6,10,[[10,9,2],[2],2]]]
|
||||
[[[],[6,[2,3,7,1,9]],[[7,7,6]],[[],8,[8,2,5]],[6,[5],[5,7,8,3],[0,7,9]]]]
|
||||
|
||||
[[5,[7,[2,10,5],1],[[],[],[]],[[],1,3],4],[4,[[],[10,2,4],10,9],[7,[9,0,9,7],[8,8,9],[],[1,4,6]],[[4,6,2],[],2,[],5]],[3,8,[0,7,[6],[6]]],[1,[10,9,[3,5]],5]]
|
||||
[[9,[0,[3],[9,10,9,9]],10,5,10],[0,6,4,[[3,6,0,0,6],10,0]],[10,9,9,6],[]]
|
||||
|
||||
[[0,8],[[[0]],[8],0],[[[]],9,[8]],[1,9,[9,4,7,[5,3,8],7],[7,[7,1],[10,1,6,8]],[]],[[[],[10,6,5,9]],0,2,[],[]]]
|
||||
[[[],0,[[4,9,3,8],1,4,6],[5]],[[7],[[],9,[],[5,3,8,10,8],[3]],2,10,[5]],[[[],[9,8,0,10,7]]],[]]
|
||||
|
||||
[[4,7],[],[4],[3,9,[[1,6,1,0],1,[2,9,2],4,[10,7,4,4,0]]]]
|
||||
[[[9],[1,[2,9,9],[3,8],1,5],2],[],[[[5,0],[4],7,2],[9],2,[[],[0,8]],9],[3],[4,8,[4]]]
|
||||
|
||||
[[8,5,4]]
|
||||
[[3,[],8,6,6],[],[[],10,1,[0,[1]],[[3,8,5],[1,7,6],[],1]]]
|
||||
|
||||
[[7,10,2,[[4,1,2,0],[5,8,2,7,5],[1,7,3,1]],[[10],7,5,8,1]],[[1]],[[10],6],[9],[10,[[8],[9,8],10,[2,9,8,0,10]],[3,0,6]]]
|
||||
[[[[6,10],[2,8,7,6,2]],3,[1,6,4,[8,10,0,2,5]],[4,6,4],[[2],2,[2],[0,4,5,0,10]]],[[[],[9],[6,6,3,1,10],1]]]
|
||||
|
||||
[[[5],5,6,8],[[0,[1,8,9],4,[9,3,3,2],[4,7]]],[7,[[8,8,4,7,6]]]]
|
||||
[[10,6,[2,1,8,0,7],4],[[]]]
|
||||
|
||||
[[],[1,[3,[10,8,0,6]],3,[10,3,5,[10,6,1]]],[1,[[8,3,5,1],0,1,0],[[],[1,4,0]],[[5,5,5,10],[],[1],[],10]],[[[0],[],8,4,[0]],[3,9],5,10]]
|
||||
[[0],[3,[6],[[10,4,6],[4,5]],3,[]],[[],2],[9],[]]
|
||||
|
||||
[[8]]
|
||||
[]
|
||||
|
||||
[[3,[6,[3],1,8],8,10,10],[2,[3,0,[1,8,2]]]]
|
||||
[[5],[9,[2,[5,3,8,8,3]]],[[[6,3],[4,2,1,6],[0],9],[4],[[9],5,7,5,9],3,6]]
|
||||
|
||||
[[10,8,[[]],[[9,10],10,[10,7,10,3]]]]
|
||||
[[[]],[0],[]]
|
||||
|
||||
[[[[8,5],2,0,5,[2,8,10,10]],[8],5,4],[4,9,10],[2,[[9,6],[6,10,2]],[[4,4,5,4]],2,0],[[9,[7,3,6],1,[]],[[5,3,3,5,5],8],[[5,4],[],[6,1]],[],[10,2,[],[]]]]
|
||||
[[4],[[10],[]]]
|
||||
|
||||
[[[[10,7,4,5]],9,4],[[[3]],[2,2],[4],[[],4,[10,7],4],[5,5,[9,10,4,3],0]],[8],[[[6,0,3],[8,2,10,0,2],[8,2,10]],9,2,9,2],[[8],2,[9,[3,2,8,7,3],10],[[9,7],4,[3,5,6],6,7],[[9,9,6],[]]]]
|
||||
[[[[3,7],[5,1,2,8],4,0]]]
|
||||
|
||||
[[8,[[8,4,8,5]],6,[[]],[6,[]]],[4,[1,[4,8,9],[]]],[[],10,[6,[],[7,3,7],[]],3],[[]]]
|
||||
[[[[5],[],8]],[10,4,1]]
|
||||
|
||||
[[10,[4,7],[9,[],2,7],9,10],[2,3,4],[1,[1,3,[2,4],10],[[1,6,7,4,4],5,4,8],5]]
|
||||
[[2,9]]
|
||||
|
||||
[[[[7,7,8,3,5],0,10,10],[1,7,[6,4,6,0,7],[9]],[],2],[],[[],2,[9,[9,10],9,[6],[5,7,7,6]]],[[],4,5]]
|
||||
[[3,2,8,[2,4,[7,6],[3,5]],4]]
|
||||
|
||||
[[3,8,10,[[7]]],[3],[]]
|
||||
[[5],[8]]
|
||||
|
||||
[[[[7,10,9,1],3]],[[[6,6,10],[]],3],[4,5,[[]]],[[],[],[[5,3],[4,6,6],[6,3,6]]]]
|
||||
[[[[9,3,8,5,6],2,[8],2]],[[],4],[[6,[2,10,1],7,6]]]
|
||||
|
||||
[[4,6]]
|
||||
[[5,[],7,9,8]]
|
||||
|
||||
[[5,[],2],[4,[0,[9,10],[3,3,5,10],[4,5,0,0],[9,8,3,7]]],[[[10],[5,2,6],[1,9,2,3,5],[6,8,10,9,8],8],0,4],[1,1,[2,1,2,[2,4,8,1],[1,8,4]],[7,[2,0],4,[9,10,2]],7],[4,6,[[8,5],7,8,8],[1]]]
|
||||
[[[],3,8,10,[[]]],[[[9,2,10,10]],[6,[0,3],[5],9,[2]],[6,3,6,9],[]],[[[7,8,7,7],[4],9,1,3],10,[8,7],5,0],[],[[[7,0,2,1,6],4],10]]
|
||||
|
||||
[[],[[2,8,3,3,10],[[7,4,10,8],10,[5,9]],[[2],7,9,1],[[],[7,8],[10],[8]],[]],[[[],[],[9,9,4,6,10],[6,5,2],[]]]]
|
||||
[[],[[]],[[[4,6],[],[9,5,5]],3,[7,4,0],[8,8],[0,[4,4,3],[],9,4]],[[6,[9,6,1],[4]]]]
|
||||
|
||||
[[[2,[],[8,4,8,7],3,[1]],3,6,2],[]]
|
||||
[[[],[[],1,6],0],[10,8,7,[[6,3],[3,7],4,10,8]]]
|
||||
|
||||
[[],[1,10,5,[4,[0,9,1,1]],[[9,3,6,1],10,4,3,5]],[10,8,[5]],[1,[6]],[1,[[5,9],[],5,[]]]]
|
||||
[[]]
|
||||
|
||||
[[[[1],6,[9,1,10],[7]],[[10,8,10,4,7],1]],[8,[7,1]],[[[2,3,10],4,8,2],[[5,10,0,6],[1,2,6,9],[]],[[],[3,10],[1,2,3],2],10],[]]
|
||||
[[5,[0,[7]],[],[[9]]],[],[10,[5,[7]],[[10,7,4,0]],1]]
|
||||
|
||||
[[1],[[4,5,6,[]],[],[[7,7]],[10,[1,10],[0],7],6],[10],[[],[[7],6,[7,0,6,6,5],[4,2,8,4,7],[10]],8,2,10],[1,0,5,3]]
|
||||
[[8,[2,[6,8,7]],6,2,7],[1,2]]
|
||||
|
||||
[[[[4,8,9,7,2],[],9,[6,9,10]]]]
|
||||
[[1,1],[],[0],[[[],[4,1,7],[1,8,3]],9,[7,[],[3,9,8]],2],[[]]]
|
||||
|
||||
[[6],[7],[9,[0,[8,6]],[9]]]
|
||||
[[[[6],[],[2,10],0],[8,[4,10],[4,5,8,0,0]]],[3,1],[[10]]]
|
||||
|
||||
[[9,[[4,0,7,6,1],3,4,[2,10,6,8,8],[2]]],[[],[],[[8,2,10,7,10],[10,8,1,0],1],[]]]
|
||||
[[4,2,4,3,6],[[7,[7,6,5,8,7],[0,4]]],[],[8,5,[3,[1,9,5],[2,8,8,8,3],4,7],7,5]]
|
||||
|
||||
[[[3,9,[7,10,2,1]],[]],[[6],2,6],[10],[],[[],6]]
|
||||
[[[[10,2]],2,[[8,6,0,8]],3],[8,7],[]]
|
||||
|
||||
[[],[3,9,7,[10,5,[6],[]]],[[[2],[3,3,3,2],[4,5,0],[]],[],4,2]]
|
||||
[[[1,9,8,[5,7]],0,4],[[5,[0,6,4,6,4],6,[4,1,5,3,4]],0,[[7,0,0,9],[9,5,4,1]],[]],[[8,9,6,0,3],[],[0,[]],[]],[[[],[1,4,4]],8,[6]]]
|
||||
|
||||
[[[],4,[[10],6,0,3],[[7,5,1,2],[],3,1]],[2,[],2],[2,[7,[8,7,4,8],2,10],[],4],[9,[[4,4,5,9],0,4,7,6],[[]],[8],10]]
|
||||
[[9,0,[[],1,3,2],[3,[],[1,4,0,2],5,8]],[],[[1,2,0,2,0],[[]],[[0]],8,7]]
|
@ -1,3 +1,138 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{cmp::Ordering, fs::read_to_string, str::Lines};
|
||||
|
||||
#[derive(Debug, Clone, Eq)]
|
||||
enum Node {
|
||||
Number(i32),
|
||||
List(Vec<Node>),
|
||||
}
|
||||
|
||||
impl PartialEq for Node {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.partial_cmp(other) == Some(Ordering::Equal)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for Node {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Node {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
match (self, other) {
|
||||
(Self::Number(n1), Self::Number(n2)) => n1.partial_cmp(n2),
|
||||
(Self::Number(n), Self::List(_)) => {
|
||||
Self::List(vec![Self::Number(*n)]).partial_cmp(other)
|
||||
}
|
||||
(Self::List(_), Self::Number(n)) => {
|
||||
self.partial_cmp(&Self::List(vec![Self::Number(*n)]))
|
||||
}
|
||||
(Self::List(l1), Self::List(l2)) => {
|
||||
for i in 0..l1.len().min(l2.len()) {
|
||||
let n1 = &l1[i];
|
||||
let n2 = &l2[i];
|
||||
match n1.partial_cmp(&n2) {
|
||||
None | Some(Ordering::Equal) => (),
|
||||
ord => return ord,
|
||||
}
|
||||
}
|
||||
Some(l1.len().cmp(&l2.len()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Node {
|
||||
fn from(line: &str) -> Self {
|
||||
match line.split_once('[') {
|
||||
None => Self::Number(line.parse().unwrap()),
|
||||
Some(("", "]")) => Self::List(vec![]),
|
||||
Some(("", r)) => match r.rsplit_once(']') {
|
||||
Some((r, "")) => {
|
||||
let mut indentation = 0;
|
||||
Self::List(
|
||||
r.split(|c| match c {
|
||||
'[' => {
|
||||
indentation += 1;
|
||||
false
|
||||
}
|
||||
']' => {
|
||||
indentation -= 1;
|
||||
false
|
||||
}
|
||||
',' if indentation == 0 => true,
|
||||
_ => false,
|
||||
})
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
_ => panic!("missing closing parenthesis"),
|
||||
},
|
||||
_ => panic!("invalid input"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_pair(lines: &mut Lines) -> Option<(Node, Node)> {
|
||||
let [first, second] = &lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.map(Node::from)
|
||||
.collect::<Vec<_>>()[..] else {return None;};
|
||||
Some((first.clone(), second.clone()))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = "[1,1,3,1,1]
|
||||
[1,1,5,1,1]
|
||||
|
||||
[[1],[2,3,4]]
|
||||
[[1],4]
|
||||
|
||||
[9]
|
||||
[[8,7,6]]
|
||||
|
||||
[[4,4],4,4]
|
||||
[[4,4],4,4,4]
|
||||
|
||||
[7,7,7,7]
|
||||
[7,7,7]
|
||||
|
||||
[]
|
||||
[3]
|
||||
|
||||
[[[]]]
|
||||
[[]]
|
||||
|
||||
[1,[2,[3,[4,[5,6,7]]]],8,9]
|
||||
[1,[2,[3,[4,[5,6,0]]]],8,9]"
|
||||
.to_owned();
|
||||
let input = read_to_string("input.txt").unwrap_or(input);
|
||||
let mut input = input.lines();
|
||||
let mut pairs = vec![];
|
||||
while let Some(pair) = parse_pair(&mut input) {
|
||||
pairs.push(pair);
|
||||
}
|
||||
let correct: usize = pairs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, pair)| if pair.0 < pair.1 { Some(i + 1) } else { None })
|
||||
.sum();
|
||||
println!("{correct}");
|
||||
let mut packets: Vec<_> = pairs.into_iter().flat_map(|p| [p.0, p.1]).collect();
|
||||
packets.push("[[2]]".into());
|
||||
packets.push("[[6]]".into());
|
||||
packets.sort();
|
||||
let decoder_key = (packets
|
||||
.iter()
|
||||
.position(|e| *e == Node::from("[[2]]"))
|
||||
.unwrap()
|
||||
+ 1)
|
||||
* (packets
|
||||
.iter()
|
||||
.position(|e| *e == Node::from("[[6]]"))
|
||||
.unwrap()
|
||||
+ 1);
|
||||
println!("{decoder_key}");
|
||||
}
|
||||
|
7
day14/Cargo.lock
generated
Normal file
7
day14/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day14"
|
||||
version = "0.1.0"
|
164
day14/input.txt
Normal file
164
day14/input.txt
Normal file
@ -0,0 +1,164 @@
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
513,69 -> 513,71 -> 511,71 -> 511,76 -> 522,76 -> 522,71 -> 517,71 -> 517,69
|
||||
520,87 -> 524,87
|
||||
480,121 -> 480,122 -> 498,122 -> 498,121
|
||||
520,56 -> 520,60 -> 517,60 -> 517,66 -> 528,66 -> 528,60 -> 523,60 -> 523,56
|
||||
484,147 -> 484,149 -> 483,149 -> 483,153 -> 489,153 -> 489,149 -> 488,149 -> 488,147
|
||||
493,24 -> 498,24
|
||||
496,22 -> 501,22
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
508,79 -> 512,79
|
||||
486,104 -> 486,105 -> 493,105 -> 493,104
|
||||
497,129 -> 502,129
|
||||
474,34 -> 478,34
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
508,87 -> 512,87
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
499,20 -> 504,20
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
496,125 -> 501,125
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
511,26 -> 516,26
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
520,56 -> 520,60 -> 517,60 -> 517,66 -> 528,66 -> 528,60 -> 523,60 -> 523,56
|
||||
520,56 -> 520,60 -> 517,60 -> 517,66 -> 528,66 -> 528,60 -> 523,60 -> 523,56
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
502,83 -> 506,83
|
||||
496,87 -> 500,87
|
||||
483,26 -> 488,26
|
||||
487,131 -> 492,131
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
499,85 -> 503,85
|
||||
480,34 -> 484,34
|
||||
474,38 -> 478,38
|
||||
486,104 -> 486,105 -> 493,105 -> 493,104
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
494,90 -> 494,92 -> 489,92 -> 489,100 -> 504,100 -> 504,92 -> 497,92 -> 497,90
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
513,69 -> 513,71 -> 511,71 -> 511,76 -> 522,76 -> 522,71 -> 517,71 -> 517,69
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
520,56 -> 520,60 -> 517,60 -> 517,66 -> 528,66 -> 528,60 -> 523,60 -> 523,56
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
480,38 -> 484,38
|
||||
489,40 -> 493,40
|
||||
483,36 -> 487,36
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
508,131 -> 513,131
|
||||
517,85 -> 521,85
|
||||
494,131 -> 499,131
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
494,90 -> 494,92 -> 489,92 -> 489,100 -> 504,100 -> 504,92 -> 497,92 -> 497,90
|
||||
514,87 -> 518,87
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
494,90 -> 494,92 -> 489,92 -> 489,100 -> 504,100 -> 504,92 -> 497,92 -> 497,90
|
||||
507,24 -> 512,24
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
471,40 -> 475,40
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
511,81 -> 515,81
|
||||
514,83 -> 518,83
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
465,40 -> 469,40
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
480,29 -> 490,29 -> 490,28
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
493,127 -> 498,127
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
504,26 -> 509,26
|
||||
492,20 -> 497,20
|
||||
477,36 -> 481,36
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
505,81 -> 509,81
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
513,69 -> 513,71 -> 511,71 -> 511,76 -> 522,76 -> 522,71 -> 517,71 -> 517,69
|
||||
480,121 -> 480,122 -> 498,122 -> 498,121
|
||||
494,90 -> 494,92 -> 489,92 -> 489,100 -> 504,100 -> 504,92 -> 497,92 -> 497,90
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
490,26 -> 495,26
|
||||
504,129 -> 509,129
|
||||
484,147 -> 484,149 -> 483,149 -> 483,153 -> 489,153 -> 489,149 -> 488,149 -> 488,147
|
||||
484,147 -> 484,149 -> 483,149 -> 483,153 -> 489,153 -> 489,149 -> 488,149 -> 488,147
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
513,69 -> 513,71 -> 511,71 -> 511,76 -> 522,76 -> 522,71 -> 517,71 -> 517,69
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
503,22 -> 508,22
|
||||
495,18 -> 500,18
|
||||
490,129 -> 495,129
|
||||
477,40 -> 481,40
|
||||
520,56 -> 520,60 -> 517,60 -> 517,66 -> 528,66 -> 528,60 -> 523,60 -> 523,56
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
511,85 -> 515,85
|
||||
502,87 -> 506,87
|
||||
513,69 -> 513,71 -> 511,71 -> 511,76 -> 522,76 -> 522,71 -> 517,71 -> 517,69
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
500,127 -> 505,127
|
||||
489,22 -> 494,22
|
||||
499,14 -> 499,15 -> 508,15
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
483,40 -> 487,40
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
484,147 -> 484,149 -> 483,149 -> 483,153 -> 489,153 -> 489,149 -> 488,149 -> 488,147
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
497,26 -> 502,26
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
501,131 -> 506,131
|
||||
468,38 -> 472,38
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
486,24 -> 491,24
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
471,36 -> 475,36
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
494,90 -> 494,92 -> 489,92 -> 489,100 -> 504,100 -> 504,92 -> 497,92 -> 497,90
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
484,147 -> 484,149 -> 483,149 -> 483,153 -> 489,153 -> 489,149 -> 488,149 -> 488,147
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
486,38 -> 490,38
|
||||
513,69 -> 513,71 -> 511,71 -> 511,76 -> 522,76 -> 522,71 -> 517,71 -> 517,69
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
508,83 -> 512,83
|
||||
512,53 -> 512,43 -> 512,53 -> 514,53 -> 514,48 -> 514,53 -> 516,53 -> 516,44 -> 516,53 -> 518,53 -> 518,50 -> 518,53 -> 520,53 -> 520,46 -> 520,53
|
||||
486,104 -> 486,105 -> 493,105 -> 493,104
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
484,147 -> 484,149 -> 483,149 -> 483,153 -> 489,153 -> 489,149 -> 488,149 -> 488,147
|
||||
480,29 -> 490,29 -> 490,28
|
||||
484,147 -> 484,149 -> 483,149 -> 483,153 -> 489,153 -> 489,149 -> 488,149 -> 488,147
|
||||
480,121 -> 480,122 -> 498,122 -> 498,121
|
||||
500,24 -> 505,24
|
||||
520,56 -> 520,60 -> 517,60 -> 517,66 -> 528,66 -> 528,60 -> 523,60 -> 523,56
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
494,90 -> 494,92 -> 489,92 -> 489,100 -> 504,100 -> 504,92 -> 497,92 -> 497,90
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
480,118 -> 480,111 -> 480,118 -> 482,118 -> 482,116 -> 482,118 -> 484,118 -> 484,111 -> 484,118 -> 486,118 -> 486,110 -> 486,118 -> 488,118 -> 488,117 -> 488,118
|
||||
475,166 -> 475,159 -> 475,166 -> 477,166 -> 477,156 -> 477,166 -> 479,166 -> 479,165 -> 479,166 -> 481,166 -> 481,156 -> 481,166 -> 483,166 -> 483,163 -> 483,166 -> 485,166 -> 485,156 -> 485,166 -> 487,166 -> 487,159 -> 487,166
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
499,14 -> 499,15 -> 508,15
|
||||
513,69 -> 513,71 -> 511,71 -> 511,76 -> 522,76 -> 522,71 -> 517,71 -> 517,69
|
||||
494,90 -> 494,92 -> 489,92 -> 489,100 -> 504,100 -> 504,92 -> 497,92 -> 497,90
|
||||
477,32 -> 481,32
|
||||
471,144 -> 471,134 -> 471,144 -> 473,144 -> 473,140 -> 473,144 -> 475,144 -> 475,143 -> 475,144 -> 477,144 -> 477,142 -> 477,144 -> 479,144 -> 479,137 -> 479,144 -> 481,144 -> 481,134 -> 481,144 -> 483,144 -> 483,136 -> 483,144 -> 485,144 -> 485,134 -> 485,144
|
||||
505,85 -> 509,85
|
||||
520,56 -> 520,60 -> 517,60 -> 517,66 -> 528,66 -> 528,60 -> 523,60 -> 523,56
|
@ -1,3 +1,191 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::fs::read_to_string;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
struct Map {
|
||||
min_x: usize,
|
||||
width: usize,
|
||||
height: usize,
|
||||
map: Vec<bool>,
|
||||
}
|
||||
|
||||
impl Map {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
min_x: 500,
|
||||
width: 0,
|
||||
height: 0,
|
||||
map: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn print(&self) {
|
||||
for y in 0..self.height {
|
||||
for x in 0..self.width {
|
||||
print!(
|
||||
"{}",
|
||||
if self.map[x + y * self.width] {
|
||||
'#'
|
||||
} else {
|
||||
'.'
|
||||
}
|
||||
);
|
||||
}
|
||||
println!();
|
||||
}
|
||||
}
|
||||
|
||||
fn at(&self, position: (usize, usize)) -> bool {
|
||||
if !self.is_inside(position) {
|
||||
return false;
|
||||
}
|
||||
let x = position.0 - self.min_x;
|
||||
self.map[x + position.1 * self.width]
|
||||
}
|
||||
|
||||
fn is_inside(&self, position: (usize, usize)) -> bool {
|
||||
position.0 >= self.min_x && position.0 < self.min_x + self.width && position.1 < self.height
|
||||
}
|
||||
|
||||
fn add_obstacle(&mut self, position: (usize, usize)) {
|
||||
while self.min_x > position.0 {
|
||||
self.extend_left();
|
||||
}
|
||||
while self.min_x + self.width <= position.0 {
|
||||
self.extend_right();
|
||||
}
|
||||
while self.height <= position.1 {
|
||||
self.extend_down();
|
||||
}
|
||||
let x = position.0 - self.min_x;
|
||||
self.map[x + position.1 * self.width] = true;
|
||||
}
|
||||
|
||||
fn extend_down(&mut self) {
|
||||
self.map.append(&mut vec![false; self.width]);
|
||||
self.height += 1;
|
||||
}
|
||||
|
||||
fn extend_left(&mut self) {
|
||||
self.map.append(&mut vec![false; self.height]);
|
||||
for y in (0..self.height).rev() {
|
||||
for x in (0..self.width).rev() {
|
||||
self.map[(x + 1) + y * (self.width + 1)] = self.map[x + y * self.width];
|
||||
}
|
||||
}
|
||||
self.width += 1;
|
||||
self.min_x -= 1;
|
||||
for y in 0..self.height {
|
||||
self.map[y * self.width] = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn extend_right(&mut self) {
|
||||
self.map.append(&mut vec![false; self.height]);
|
||||
for y in (0..self.height).rev() {
|
||||
for x in (0..self.width).rev() {
|
||||
self.map[x + y * (self.width + 1)] = self.map[x + y * self.width];
|
||||
}
|
||||
}
|
||||
self.width += 1;
|
||||
for y in 0..self.height {
|
||||
self.map[self.width - 1 + y * self.width] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_sand(map: &Map) -> Option<(usize, usize)> {
|
||||
let mut sand = (500, 0);
|
||||
while map.is_inside(sand) {
|
||||
let x = sand.0;
|
||||
let y = sand.1;
|
||||
if !map.at((x, y + 1)) {
|
||||
sand.1 += 1;
|
||||
continue;
|
||||
}
|
||||
if !map.at((x - 1, y + 1)) {
|
||||
sand.1 += 1;
|
||||
sand.0 -= 1;
|
||||
continue;
|
||||
}
|
||||
if !map.at((x + 1, y + 1)) {
|
||||
sand.1 += 1;
|
||||
sand.0 += 1;
|
||||
continue;
|
||||
}
|
||||
return Some(sand);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn add_sand_floor(map: &Map, floor: usize) -> Option<(usize, usize)> {
|
||||
let mut sand = (500, 0);
|
||||
while !map.at((500, 0)) {
|
||||
let x = sand.0;
|
||||
let y = sand.1;
|
||||
if y + 1 == floor {
|
||||
return Some(sand);
|
||||
}
|
||||
if !map.at((x, y + 1)) {
|
||||
sand.1 += 1;
|
||||
continue;
|
||||
}
|
||||
if !map.at((x - 1, y + 1)) {
|
||||
sand.1 += 1;
|
||||
sand.0 -= 1;
|
||||
continue;
|
||||
}
|
||||
if !map.at((x + 1, y + 1)) {
|
||||
sand.1 += 1;
|
||||
sand.0 += 1;
|
||||
continue;
|
||||
}
|
||||
return Some(sand);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = "498,4 -> 498,6 -> 496,6
|
||||
503,4 -> 502,4 -> 502,9 -> 494,9"
|
||||
.to_owned();
|
||||
let input = read_to_string("input.txt").unwrap_or(input);
|
||||
let mut map = Map::new();
|
||||
for line in input.lines() {
|
||||
let points = line.split(" -> ").map(|coord| {
|
||||
let [x, y] = coord.split(',').map(|n| n.parse::<usize>().unwrap()).collect::<Vec<_>>()[..] else {panic!()};
|
||||
(x, y)
|
||||
}).collect::<Vec<_>>();
|
||||
for line in points.windows(2) {
|
||||
let (x1, y1) = line[0];
|
||||
let (x2, y2) = line[1];
|
||||
let x_min = x1.min(x2);
|
||||
let x_max = x1.max(x2);
|
||||
let y_min = y1.min(y2);
|
||||
let y_max = y1.max(y2);
|
||||
for x in x_min..=x_max {
|
||||
for y in y_min..=y_max {
|
||||
map.add_obstacle((x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("printing map:");
|
||||
map.print();
|
||||
let mut num_sand = 0;
|
||||
while let Some(sand) = add_sand(&map) {
|
||||
map.add_obstacle(sand);
|
||||
num_sand += 1;
|
||||
}
|
||||
println!();
|
||||
map.print();
|
||||
println!("needed {num_sand} sand particles");
|
||||
let floor = map.height + 1;
|
||||
println!("floor: {floor}");
|
||||
while let Some(sand) = add_sand_floor(&map, floor) {
|
||||
map.add_obstacle(sand);
|
||||
num_sand += 1;
|
||||
}
|
||||
println!();
|
||||
map.print();
|
||||
println!("needed {num_sand} sand particles");
|
||||
}
|
||||
|
7
day15/Cargo.lock
generated
Normal file
7
day15/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day15"
|
||||
version = "0.1.0"
|
32
day15/input.txt
Normal file
32
day15/input.txt
Normal file
@ -0,0 +1,32 @@
|
||||
Sensor at x=2832148, y=322979: closest beacon is at x=3015667, y=-141020
|
||||
Sensor at x=1449180, y=3883502: closest beacon is at x=2656952, y=4188971
|
||||
Sensor at x=2808169, y=1194666: closest beacon is at x=3015667, y=-141020
|
||||
Sensor at x=1863363, y=2435968: closest beacon is at x=2166084, y=2883057
|
||||
Sensor at x=3558230, y=2190936: closest beacon is at x=3244164, y=2592191
|
||||
Sensor at x=711491, y=2444705: closest beacon is at x=617239, y=2988377
|
||||
Sensor at x=2727148, y=2766272: closest beacon is at x=2166084, y=2883057
|
||||
Sensor at x=2857938, y=3988086: closest beacon is at x=2968511, y=4098658
|
||||
Sensor at x=1242410, y=2270153: closest beacon is at x=214592, y=2000000
|
||||
Sensor at x=3171784, y=2523127: closest beacon is at x=3244164, y=2592191
|
||||
Sensor at x=2293378, y=71434: closest beacon is at x=3015667, y=-141020
|
||||
Sensor at x=399711, y=73420: closest beacon is at x=1152251, y=-158441
|
||||
Sensor at x=3677529, y=415283: closest beacon is at x=3015667, y=-141020
|
||||
Sensor at x=207809, y=2348497: closest beacon is at x=214592, y=2000000
|
||||
Sensor at x=60607, y=3403420: closest beacon is at x=617239, y=2988377
|
||||
Sensor at x=3767729, y=3136725: closest beacon is at x=4171278, y=3348370
|
||||
Sensor at x=3899632, y=3998969: closest beacon is at x=4171278, y=3348370
|
||||
Sensor at x=394783, y=1541278: closest beacon is at x=214592, y=2000000
|
||||
Sensor at x=1193642, y=642631: closest beacon is at x=1152251, y=-158441
|
||||
Sensor at x=122867, y=2661904: closest beacon is at x=214592, y=2000000
|
||||
Sensor at x=551012, y=3787568: closest beacon is at x=617239, y=2988377
|
||||
Sensor at x=3175715, y=2975144: closest beacon is at x=3244164, y=2592191
|
||||
Sensor at x=402217, y=2812449: closest beacon is at x=617239, y=2988377
|
||||
Sensor at x=879648, y=1177329: closest beacon is at x=214592, y=2000000
|
||||
Sensor at x=1317218, y=2978309: closest beacon is at x=617239, y=2988377
|
||||
Sensor at x=3965126, y=1743931: closest beacon is at x=3244164, y=2592191
|
||||
Sensor at x=2304348, y=3140055: closest beacon is at x=2166084, y=2883057
|
||||
Sensor at x=3380135, y=3650709: closest beacon is at x=2968511, y=4098658
|
||||
Sensor at x=49224, y=1914296: closest beacon is at x=214592, y=2000000
|
||||
Sensor at x=3096228, y=2457233: closest beacon is at x=3244164, y=2592191
|
||||
Sensor at x=1415660, y=6715: closest beacon is at x=1152251, y=-158441
|
||||
Sensor at x=2616280, y=3548378: closest beacon is at x=2656952, y=4188971
|
@ -1,3 +1,95 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{collections::HashSet, fs::read_to_string, io::Write, ops::RangeInclusive};
|
||||
|
||||
struct Sensor {
|
||||
x: i64,
|
||||
y: i64,
|
||||
x_beacon: i64,
|
||||
y_beacon: i64,
|
||||
distance: u64,
|
||||
}
|
||||
|
||||
impl From<&str> for Sensor {
|
||||
fn from(value: &str) -> Self {
|
||||
let [x_sensor, y_sensor, x_beacon, y_beacon] = value
|
||||
.chars()
|
||||
.filter(|c| c.is_ascii_digit() || c.is_whitespace() || *c == '-')
|
||||
.collect::<String>()
|
||||
.split_whitespace()
|
||||
.map(|n| n.parse::<i64>().unwrap())
|
||||
.collect::<Vec<_>>()[..] else {panic!()};
|
||||
Self {
|
||||
x: x_sensor,
|
||||
y: y_sensor,
|
||||
x_beacon,
|
||||
y_beacon,
|
||||
distance: x_sensor.abs_diff(x_beacon) + y_sensor.abs_diff(y_beacon),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = (
|
||||
"Sensor at x=2, y=18: closest beacon is at x=-2, y=15
|
||||
Sensor at x=9, y=16: closest beacon is at x=10, y=16
|
||||
Sensor at x=13, y=2: closest beacon is at x=15, y=3
|
||||
Sensor at x=12, y=14: closest beacon is at x=10, y=16
|
||||
Sensor at x=10, y=20: closest beacon is at x=10, y=16
|
||||
Sensor at x=14, y=17: closest beacon is at x=10, y=16
|
||||
Sensor at x=8, y=7: closest beacon is at x=2, y=10
|
||||
Sensor at x=2, y=0: closest beacon is at x=2, y=10
|
||||
Sensor at x=0, y=11: closest beacon is at x=2, y=10
|
||||
Sensor at x=20, y=14: closest beacon is at x=25, y=17
|
||||
Sensor at x=17, y=20: closest beacon is at x=21, y=22
|
||||
Sensor at x=16, y=7: closest beacon is at x=15, y=3
|
||||
Sensor at x=14, y=3: closest beacon is at x=15, y=3
|
||||
Sensor at x=20, y=1: closest beacon is at x=15, y=3"
|
||||
.to_owned(),
|
||||
10,
|
||||
20,
|
||||
);
|
||||
let (input, line, xy_max): (_, i64, i64) = read_to_string("input.txt")
|
||||
.map(|input| (input, 2_000_000, 4_000_000))
|
||||
.unwrap_or(input);
|
||||
let sensors = input.lines().map(Sensor::from).collect::<Vec<_>>();
|
||||
let mut covered: HashSet<_> = sensors
|
||||
.iter()
|
||||
.flat_map(|s| {
|
||||
let diff = line.abs_diff(s.y);
|
||||
if diff > s.distance {
|
||||
return RangeInclusive::new(1, 0);
|
||||
}
|
||||
let d = s.distance - diff;
|
||||
(s.x - d as i64)..=(s.x + d as i64)
|
||||
})
|
||||
.collect();
|
||||
for sensor in &sensors {
|
||||
if sensor.y_beacon == line {
|
||||
covered.remove(&sensor.x_beacon);
|
||||
}
|
||||
}
|
||||
println!("{} positions can't contain a beacon", covered.len());
|
||||
'outer: for y in 0..=xy_max {
|
||||
let mut ranges = vec![];
|
||||
for sensor in &sensors {
|
||||
let diff = y.abs_diff(sensor.y);
|
||||
if diff > sensor.distance {
|
||||
continue;
|
||||
}
|
||||
let d = sensor.distance - diff;
|
||||
ranges.push((sensor.x - d as i64)..=(sensor.x + d as i64));
|
||||
}
|
||||
ranges.sort_unstable_by(|r1, r2| r1.start().cmp(r2.start()));
|
||||
let mut max_x = 0;
|
||||
for range in ranges {
|
||||
if max_x + 1 < *range.start() {
|
||||
let x = max_x + 1;
|
||||
println!(
|
||||
"found beacon at {x},{y} with frequency {}",
|
||||
x * 4_000_000 + y
|
||||
);
|
||||
break 'outer;
|
||||
}
|
||||
max_x = max_x.max(*range.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,9 @@ enum Symbol {
|
||||
impl From<char> for Symbol {
|
||||
fn from(value: char) -> Self {
|
||||
match value {
|
||||
'A' => Self::Rock,
|
||||
'B' => Self::Paper,
|
||||
'C' => Self::Scissors,
|
||||
'X' => Self::Rock,
|
||||
'Y' => Self::Paper,
|
||||
'Z' => Self::Scissors,
|
||||
'A' | 'X' => Self::Rock,
|
||||
'B' | 'Y' => Self::Paper,
|
||||
'C' | 'Z' => Self::Scissors,
|
||||
_ => panic!("invalid input"),
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ use std::{collections::HashSet, fs::read_to_string};
|
||||
use color_eyre::{eyre::*, Result};
|
||||
use itertools::Itertools;
|
||||
|
||||
fn priority(item: &char) -> usize {
|
||||
fn priority(item: char) -> Result<usize> {
|
||||
('a'..='z')
|
||||
.position(|c| *item == c)
|
||||
.position(|c| item == c)
|
||||
.map(|i| i + 1)
|
||||
.or_else(|| ('A'..='Z').position(|c| *item == c).map(|i| i + 27))
|
||||
.unwrap_or(0)
|
||||
.or_else(|| ('A'..='Z').position(|c| item == c).map(|i| i + 27))
|
||||
.ok_or_else(|| eyre!("invalid character '{}'", item))
|
||||
}
|
||||
|
||||
fn initial(input: &str) -> (usize, usize) {
|
||||
@ -20,7 +20,7 @@ fn initial(input: &str) -> (usize, usize) {
|
||||
let compartment2 = compartment2.chars().collect::<HashSet<_>>();
|
||||
compartment1
|
||||
.intersection(&compartment2)
|
||||
.map(priority)
|
||||
.filter_map(|v| priority(*v).ok())
|
||||
.sum::<usize>()
|
||||
})
|
||||
.sum();
|
||||
@ -32,7 +32,7 @@ fn initial(input: &str) -> (usize, usize) {
|
||||
group
|
||||
.map(|line| line.chars().collect::<HashSet<_>>())
|
||||
.coalesce(|a, b| Ok(a.intersection(&b).copied().collect()))
|
||||
.map(|set| set.iter().map(priority).sum::<usize>())
|
||||
.map(|set| set.iter().filter_map(|v| priority(*v).ok()).sum::<usize>())
|
||||
.sum::<usize>()
|
||||
})
|
||||
.sum();
|
||||
|
243
day4/Cargo.lock
generated
Normal file
243
day4/Cargo.lock
generated
Normal file
@ -0,0 +1,243 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
|
||||
dependencies = [
|
||||
"gimli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "color-eyre"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"color-spantrace",
|
||||
"eyre",
|
||||
"indenter",
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-spantrace"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-core",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "day4"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"color-eyre",
|
||||
"itertools",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||
|
||||
[[package]]
|
||||
name = "eyre"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb"
|
||||
dependencies = [
|
||||
"indenter",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
|
||||
|
||||
[[package]]
|
||||
name = "indenter"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.138"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"pin-project-lite",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-error"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
|
||||
dependencies = [
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
|
||||
dependencies = [
|
||||
"sharded-slab",
|
||||
"thread_local",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
@ -6,3 +6,5 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
color-eyre = "0.6.2"
|
||||
itertools = "0.10.5"
|
||||
|
1000
day4/input.txt
Normal file
1000
day4/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,52 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::fs::read_to_string;
|
||||
|
||||
use color_eyre::Result;
|
||||
use itertools::Itertools;
|
||||
|
||||
fn initial(input: &str) -> (usize, usize) {
|
||||
let ranges = input.lines().map(|line| {
|
||||
line.split_terminator(',')
|
||||
.map(|range| {
|
||||
let (lower, upper): (usize, usize) = range
|
||||
.split_terminator('-')
|
||||
.map(|number| number.parse::<usize>().unwrap())
|
||||
.take(2)
|
||||
.collect_tuple()
|
||||
.unwrap();
|
||||
lower..=upper
|
||||
})
|
||||
.take(2)
|
||||
.collect_tuple()
|
||||
.unwrap()
|
||||
});
|
||||
let containing = *ranges
|
||||
.clone()
|
||||
.map(|(first, second)| {
|
||||
first.contains(second.start()) && first.contains(second.end())
|
||||
|| second.contains(first.start()) && second.contains(first.end())
|
||||
})
|
||||
.counts()
|
||||
.get(&true)
|
||||
.unwrap_or(&0usize);
|
||||
let overlaping = *ranges
|
||||
.map(|(first, second)| {
|
||||
first.contains(second.start())
|
||||
|| first.contains(second.end())
|
||||
|| second.contains(first.start())
|
||||
|| second.contains(first.end())
|
||||
})
|
||||
.counts()
|
||||
.get(&true)
|
||||
.unwrap_or(&0usize);
|
||||
(containing, overlaping)
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let input = read_to_string("input.txt")?;
|
||||
let (containing, overlaping) = initial(&input);
|
||||
println!(
|
||||
"{} pairs have containing ranges, {} ranges overlap",
|
||||
containing, overlaping
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
243
day5/Cargo.lock
generated
Normal file
243
day5/Cargo.lock
generated
Normal file
@ -0,0 +1,243 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
|
||||
dependencies = [
|
||||
"gimli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "color-eyre"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"color-spantrace",
|
||||
"eyre",
|
||||
"indenter",
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color-spantrace"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"owo-colors",
|
||||
"tracing-core",
|
||||
"tracing-error",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "day5"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"color-eyre",
|
||||
"itertools",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||
|
||||
[[package]]
|
||||
name = "eyre"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb"
|
||||
dependencies = [
|
||||
"indenter",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
|
||||
|
||||
[[package]]
|
||||
name = "indenter"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.138"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"pin-project-lite",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-error"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
|
||||
dependencies = [
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
|
||||
dependencies = [
|
||||
"sharded-slab",
|
||||
"thread_local",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
@ -6,3 +6,5 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
color-eyre = "0.6.2"
|
||||
itertools = "0.10.5"
|
||||
|
511
day5/input.txt
Normal file
511
day5/input.txt
Normal file
@ -0,0 +1,511 @@
|
||||
[G] [P] [M]
|
||||
[V] [M] [W] [S] [Q]
|
||||
[N] [N] [G] [H] [T] [F]
|
||||
[J] [W] [V] [Q] [W] [F] [P]
|
||||
[C] [H] [T] [T] [G] [B] [Z] [B]
|
||||
[S] [W] [S] [L] [F] [B] [P] [C] [H]
|
||||
[G] [M] [Q] [S] [Z] [T] [J] [D] [S]
|
||||
[B] [T] [M] [B] [J] [C] [T] [G] [N]
|
||||
1 2 3 4 5 6 7 8 9
|
||||
|
||||
move 2 from 4 to 2
|
||||
move 6 from 9 to 7
|
||||
move 4 from 7 to 2
|
||||
move 2 from 4 to 1
|
||||
move 2 from 6 to 7
|
||||
move 1 from 3 to 8
|
||||
move 4 from 7 to 1
|
||||
move 2 from 3 to 2
|
||||
move 3 from 8 to 5
|
||||
move 3 from 1 to 4
|
||||
move 12 from 2 to 5
|
||||
move 2 from 6 to 8
|
||||
move 12 from 5 to 8
|
||||
move 3 from 7 to 9
|
||||
move 18 from 8 to 9
|
||||
move 2 from 8 to 6
|
||||
move 3 from 2 to 3
|
||||
move 14 from 9 to 4
|
||||
move 1 from 1 to 3
|
||||
move 7 from 9 to 3
|
||||
move 1 from 2 to 1
|
||||
move 8 from 4 to 5
|
||||
move 5 from 6 to 3
|
||||
move 2 from 7 to 9
|
||||
move 3 from 4 to 9
|
||||
move 4 from 9 to 6
|
||||
move 4 from 6 to 1
|
||||
move 8 from 4 to 6
|
||||
move 10 from 1 to 2
|
||||
move 13 from 3 to 2
|
||||
move 17 from 5 to 9
|
||||
move 2 from 5 to 1
|
||||
move 9 from 9 to 7
|
||||
move 1 from 3 to 6
|
||||
move 2 from 1 to 8
|
||||
move 11 from 2 to 4
|
||||
move 5 from 6 to 8
|
||||
move 1 from 6 to 3
|
||||
move 1 from 1 to 4
|
||||
move 3 from 8 to 6
|
||||
move 3 from 2 to 8
|
||||
move 9 from 7 to 9
|
||||
move 4 from 4 to 7
|
||||
move 1 from 9 to 5
|
||||
move 15 from 9 to 7
|
||||
move 7 from 8 to 3
|
||||
move 1 from 5 to 6
|
||||
move 2 from 6 to 9
|
||||
move 8 from 2 to 6
|
||||
move 3 from 4 to 3
|
||||
move 1 from 2 to 5
|
||||
move 4 from 9 to 3
|
||||
move 1 from 3 to 4
|
||||
move 13 from 6 to 2
|
||||
move 1 from 5 to 1
|
||||
move 4 from 4 to 9
|
||||
move 6 from 3 to 2
|
||||
move 11 from 2 to 7
|
||||
move 6 from 3 to 4
|
||||
move 3 from 3 to 2
|
||||
move 1 from 3 to 4
|
||||
move 1 from 1 to 3
|
||||
move 3 from 9 to 2
|
||||
move 1 from 3 to 1
|
||||
move 4 from 7 to 1
|
||||
move 1 from 9 to 5
|
||||
move 5 from 1 to 4
|
||||
move 11 from 2 to 4
|
||||
move 1 from 5 to 3
|
||||
move 1 from 2 to 3
|
||||
move 12 from 4 to 2
|
||||
move 2 from 7 to 2
|
||||
move 7 from 4 to 3
|
||||
move 5 from 4 to 1
|
||||
move 7 from 7 to 6
|
||||
move 4 from 1 to 8
|
||||
move 1 from 8 to 5
|
||||
move 8 from 3 to 2
|
||||
move 4 from 7 to 4
|
||||
move 13 from 7 to 1
|
||||
move 2 from 8 to 6
|
||||
move 5 from 4 to 9
|
||||
move 1 from 3 to 6
|
||||
move 1 from 5 to 8
|
||||
move 1 from 2 to 9
|
||||
move 4 from 2 to 6
|
||||
move 2 from 8 to 6
|
||||
move 10 from 1 to 3
|
||||
move 4 from 9 to 4
|
||||
move 2 from 1 to 3
|
||||
move 5 from 2 to 9
|
||||
move 4 from 9 to 2
|
||||
move 1 from 1 to 2
|
||||
move 13 from 2 to 4
|
||||
move 15 from 4 to 5
|
||||
move 3 from 6 to 8
|
||||
move 8 from 3 to 8
|
||||
move 1 from 4 to 2
|
||||
move 14 from 5 to 1
|
||||
move 1 from 5 to 4
|
||||
move 1 from 4 to 2
|
||||
move 8 from 6 to 7
|
||||
move 3 from 6 to 2
|
||||
move 2 from 9 to 1
|
||||
move 8 from 8 to 7
|
||||
move 9 from 1 to 5
|
||||
move 7 from 5 to 3
|
||||
move 14 from 7 to 9
|
||||
move 2 from 2 to 3
|
||||
move 7 from 2 to 1
|
||||
move 1 from 6 to 1
|
||||
move 4 from 9 to 2
|
||||
move 8 from 3 to 6
|
||||
move 2 from 4 to 3
|
||||
move 4 from 3 to 5
|
||||
move 5 from 5 to 7
|
||||
move 2 from 6 to 9
|
||||
move 6 from 6 to 2
|
||||
move 4 from 2 to 3
|
||||
move 1 from 6 to 2
|
||||
move 2 from 7 to 8
|
||||
move 13 from 9 to 5
|
||||
move 2 from 7 to 1
|
||||
move 14 from 1 to 5
|
||||
move 15 from 5 to 7
|
||||
move 3 from 8 to 7
|
||||
move 5 from 3 to 5
|
||||
move 6 from 5 to 7
|
||||
move 4 from 1 to 7
|
||||
move 1 from 2 to 5
|
||||
move 3 from 2 to 8
|
||||
move 11 from 5 to 2
|
||||
move 10 from 7 to 1
|
||||
move 1 from 3 to 4
|
||||
move 10 from 2 to 9
|
||||
move 1 from 5 to 8
|
||||
move 6 from 7 to 3
|
||||
move 1 from 4 to 6
|
||||
move 2 from 3 to 8
|
||||
move 1 from 2 to 1
|
||||
move 4 from 3 to 9
|
||||
move 3 from 1 to 6
|
||||
move 2 from 7 to 1
|
||||
move 1 from 5 to 6
|
||||
move 1 from 3 to 8
|
||||
move 4 from 1 to 4
|
||||
move 5 from 2 to 9
|
||||
move 3 from 1 to 4
|
||||
move 18 from 9 to 7
|
||||
move 4 from 8 to 4
|
||||
move 3 from 1 to 2
|
||||
move 1 from 9 to 7
|
||||
move 1 from 4 to 7
|
||||
move 1 from 6 to 2
|
||||
move 1 from 2 to 5
|
||||
move 25 from 7 to 3
|
||||
move 7 from 4 to 2
|
||||
move 8 from 7 to 9
|
||||
move 4 from 8 to 6
|
||||
move 1 from 8 to 5
|
||||
move 4 from 6 to 5
|
||||
move 2 from 9 to 5
|
||||
move 3 from 5 to 8
|
||||
move 4 from 6 to 4
|
||||
move 12 from 3 to 5
|
||||
move 11 from 3 to 2
|
||||
move 13 from 5 to 8
|
||||
move 4 from 9 to 6
|
||||
move 7 from 4 to 9
|
||||
move 2 from 6 to 2
|
||||
move 12 from 2 to 7
|
||||
move 1 from 6 to 3
|
||||
move 1 from 5 to 6
|
||||
move 2 from 5 to 3
|
||||
move 15 from 8 to 6
|
||||
move 4 from 6 to 7
|
||||
move 1 from 5 to 1
|
||||
move 10 from 2 to 8
|
||||
move 8 from 8 to 3
|
||||
move 8 from 6 to 8
|
||||
move 2 from 7 to 6
|
||||
move 9 from 9 to 7
|
||||
move 8 from 8 to 9
|
||||
move 1 from 1 to 3
|
||||
move 1 from 2 to 7
|
||||
move 7 from 3 to 1
|
||||
move 3 from 8 to 5
|
||||
move 3 from 1 to 6
|
||||
move 7 from 9 to 2
|
||||
move 2 from 3 to 7
|
||||
move 5 from 7 to 9
|
||||
move 17 from 7 to 5
|
||||
move 2 from 7 to 6
|
||||
move 10 from 6 to 3
|
||||
move 1 from 1 to 3
|
||||
move 6 from 9 to 3
|
||||
move 1 from 2 to 9
|
||||
move 2 from 7 to 9
|
||||
move 2 from 9 to 7
|
||||
move 1 from 5 to 8
|
||||
move 1 from 8 to 5
|
||||
move 6 from 2 to 5
|
||||
move 1 from 6 to 1
|
||||
move 5 from 3 to 5
|
||||
move 1 from 6 to 8
|
||||
move 1 from 7 to 9
|
||||
move 2 from 9 to 3
|
||||
move 15 from 5 to 2
|
||||
move 2 from 1 to 8
|
||||
move 2 from 3 to 7
|
||||
move 2 from 8 to 3
|
||||
move 3 from 5 to 9
|
||||
move 1 from 8 to 6
|
||||
move 1 from 9 to 6
|
||||
move 3 from 7 to 6
|
||||
move 17 from 3 to 4
|
||||
move 1 from 1 to 2
|
||||
move 6 from 2 to 9
|
||||
move 16 from 4 to 1
|
||||
move 4 from 6 to 8
|
||||
move 9 from 5 to 6
|
||||
move 8 from 6 to 2
|
||||
move 2 from 9 to 5
|
||||
move 2 from 3 to 5
|
||||
move 1 from 6 to 2
|
||||
move 1 from 4 to 8
|
||||
move 14 from 1 to 3
|
||||
move 8 from 5 to 3
|
||||
move 20 from 3 to 1
|
||||
move 1 from 8 to 2
|
||||
move 1 from 9 to 6
|
||||
move 1 from 6 to 7
|
||||
move 1 from 7 to 3
|
||||
move 22 from 1 to 2
|
||||
move 3 from 3 to 6
|
||||
move 27 from 2 to 8
|
||||
move 2 from 2 to 8
|
||||
move 2 from 6 to 9
|
||||
move 2 from 9 to 4
|
||||
move 2 from 4 to 8
|
||||
move 1 from 1 to 3
|
||||
move 14 from 8 to 5
|
||||
move 1 from 3 to 9
|
||||
move 3 from 9 to 2
|
||||
move 5 from 2 to 8
|
||||
move 10 from 2 to 9
|
||||
move 1 from 6 to 7
|
||||
move 1 from 7 to 5
|
||||
move 7 from 5 to 2
|
||||
move 2 from 9 to 2
|
||||
move 1 from 6 to 2
|
||||
move 2 from 9 to 5
|
||||
move 3 from 5 to 6
|
||||
move 6 from 5 to 3
|
||||
move 1 from 5 to 6
|
||||
move 4 from 3 to 9
|
||||
move 2 from 9 to 8
|
||||
move 3 from 9 to 5
|
||||
move 23 from 8 to 1
|
||||
move 2 from 6 to 1
|
||||
move 1 from 5 to 7
|
||||
move 2 from 3 to 5
|
||||
move 2 from 9 to 5
|
||||
move 4 from 9 to 7
|
||||
move 2 from 9 to 4
|
||||
move 1 from 5 to 4
|
||||
move 5 from 8 to 5
|
||||
move 2 from 6 to 2
|
||||
move 3 from 7 to 3
|
||||
move 1 from 3 to 4
|
||||
move 3 from 2 to 8
|
||||
move 4 from 1 to 6
|
||||
move 2 from 6 to 3
|
||||
move 4 from 1 to 2
|
||||
move 3 from 8 to 1
|
||||
move 13 from 2 to 5
|
||||
move 4 from 3 to 2
|
||||
move 14 from 5 to 7
|
||||
move 5 from 2 to 7
|
||||
move 18 from 7 to 9
|
||||
move 4 from 4 to 7
|
||||
move 2 from 5 to 4
|
||||
move 17 from 9 to 5
|
||||
move 1 from 9 to 1
|
||||
move 1 from 7 to 2
|
||||
move 5 from 7 to 2
|
||||
move 18 from 1 to 4
|
||||
move 1 from 7 to 3
|
||||
move 1 from 3 to 6
|
||||
move 2 from 1 to 3
|
||||
move 1 from 6 to 5
|
||||
move 2 from 6 to 8
|
||||
move 1 from 8 to 9
|
||||
move 1 from 8 to 3
|
||||
move 13 from 4 to 5
|
||||
move 1 from 1 to 6
|
||||
move 3 from 2 to 4
|
||||
move 1 from 6 to 1
|
||||
move 3 from 2 to 9
|
||||
move 3 from 3 to 1
|
||||
move 5 from 4 to 5
|
||||
move 30 from 5 to 3
|
||||
move 1 from 4 to 6
|
||||
move 1 from 9 to 8
|
||||
move 1 from 9 to 6
|
||||
move 21 from 3 to 7
|
||||
move 3 from 1 to 6
|
||||
move 1 from 1 to 4
|
||||
move 1 from 9 to 6
|
||||
move 1 from 8 to 2
|
||||
move 1 from 3 to 6
|
||||
move 1 from 9 to 3
|
||||
move 5 from 4 to 8
|
||||
move 1 from 2 to 4
|
||||
move 9 from 5 to 7
|
||||
move 2 from 5 to 9
|
||||
move 2 from 8 to 2
|
||||
move 2 from 6 to 3
|
||||
move 1 from 4 to 1
|
||||
move 4 from 3 to 8
|
||||
move 2 from 9 to 2
|
||||
move 4 from 2 to 6
|
||||
move 1 from 1 to 4
|
||||
move 2 from 6 to 9
|
||||
move 2 from 5 to 4
|
||||
move 1 from 3 to 1
|
||||
move 1 from 1 to 3
|
||||
move 2 from 9 to 1
|
||||
move 5 from 3 to 5
|
||||
move 1 from 1 to 8
|
||||
move 4 from 6 to 4
|
||||
move 5 from 5 to 6
|
||||
move 18 from 7 to 5
|
||||
move 1 from 3 to 4
|
||||
move 12 from 7 to 5
|
||||
move 15 from 5 to 6
|
||||
move 1 from 5 to 8
|
||||
move 1 from 3 to 7
|
||||
move 1 from 1 to 2
|
||||
move 1 from 2 to 4
|
||||
move 1 from 7 to 9
|
||||
move 2 from 8 to 2
|
||||
move 1 from 2 to 4
|
||||
move 4 from 4 to 2
|
||||
move 1 from 2 to 1
|
||||
move 1 from 9 to 8
|
||||
move 4 from 6 to 4
|
||||
move 3 from 2 to 6
|
||||
move 1 from 2 to 6
|
||||
move 8 from 4 to 3
|
||||
move 1 from 1 to 3
|
||||
move 6 from 6 to 1
|
||||
move 1 from 3 to 6
|
||||
move 5 from 1 to 7
|
||||
move 10 from 5 to 9
|
||||
move 3 from 9 to 8
|
||||
move 7 from 6 to 2
|
||||
move 1 from 7 to 8
|
||||
move 3 from 5 to 8
|
||||
move 3 from 6 to 2
|
||||
move 6 from 8 to 9
|
||||
move 1 from 5 to 3
|
||||
move 2 from 3 to 1
|
||||
move 2 from 4 to 8
|
||||
move 6 from 6 to 9
|
||||
move 1 from 1 to 4
|
||||
move 17 from 9 to 2
|
||||
move 1 from 4 to 1
|
||||
move 2 from 7 to 8
|
||||
move 1 from 9 to 8
|
||||
move 3 from 8 to 4
|
||||
move 3 from 1 to 4
|
||||
move 9 from 8 to 2
|
||||
move 1 from 8 to 4
|
||||
move 12 from 2 to 7
|
||||
move 4 from 7 to 4
|
||||
move 1 from 8 to 1
|
||||
move 10 from 4 to 2
|
||||
move 3 from 3 to 2
|
||||
move 1 from 9 to 7
|
||||
move 11 from 7 to 3
|
||||
move 1 from 3 to 1
|
||||
move 2 from 3 to 9
|
||||
move 1 from 3 to 7
|
||||
move 2 from 1 to 9
|
||||
move 1 from 6 to 5
|
||||
move 7 from 3 to 6
|
||||
move 1 from 7 to 3
|
||||
move 3 from 3 to 4
|
||||
move 1 from 5 to 7
|
||||
move 2 from 4 to 3
|
||||
move 2 from 4 to 8
|
||||
move 1 from 7 to 6
|
||||
move 2 from 6 to 8
|
||||
move 1 from 9 to 2
|
||||
move 1 from 9 to 5
|
||||
move 1 from 5 to 1
|
||||
move 1 from 8 to 6
|
||||
move 1 from 3 to 2
|
||||
move 4 from 6 to 1
|
||||
move 5 from 1 to 4
|
||||
move 11 from 2 to 4
|
||||
move 2 from 8 to 2
|
||||
move 1 from 8 to 9
|
||||
move 27 from 2 to 5
|
||||
move 4 from 6 to 3
|
||||
move 3 from 2 to 4
|
||||
move 2 from 5 to 9
|
||||
move 1 from 5 to 7
|
||||
move 2 from 9 to 5
|
||||
move 14 from 4 to 7
|
||||
move 2 from 4 to 7
|
||||
move 3 from 4 to 8
|
||||
move 4 from 3 to 1
|
||||
move 4 from 1 to 8
|
||||
move 2 from 3 to 9
|
||||
move 2 from 9 to 3
|
||||
move 7 from 8 to 9
|
||||
move 1 from 3 to 8
|
||||
move 2 from 3 to 2
|
||||
move 25 from 5 to 9
|
||||
move 1 from 5 to 8
|
||||
move 1 from 8 to 7
|
||||
move 26 from 9 to 1
|
||||
move 23 from 1 to 5
|
||||
move 7 from 9 to 7
|
||||
move 1 from 9 to 8
|
||||
move 1 from 9 to 2
|
||||
move 5 from 7 to 1
|
||||
move 20 from 5 to 6
|
||||
move 1 from 7 to 6
|
||||
move 2 from 5 to 3
|
||||
move 1 from 8 to 6
|
||||
move 21 from 6 to 8
|
||||
move 1 from 6 to 4
|
||||
move 1 from 1 to 7
|
||||
move 2 from 1 to 6
|
||||
move 1 from 1 to 3
|
||||
move 1 from 2 to 5
|
||||
move 1 from 2 to 6
|
||||
move 2 from 7 to 6
|
||||
move 6 from 7 to 9
|
||||
move 3 from 1 to 2
|
||||
move 17 from 8 to 1
|
||||
move 1 from 4 to 1
|
||||
move 2 from 6 to 9
|
||||
move 3 from 8 to 9
|
||||
move 2 from 3 to 7
|
||||
move 2 from 9 to 8
|
||||
move 4 from 7 to 3
|
||||
move 4 from 3 to 4
|
||||
move 2 from 5 to 8
|
||||
move 4 from 8 to 4
|
||||
move 3 from 6 to 8
|
||||
move 18 from 1 to 5
|
||||
move 1 from 3 to 4
|
||||
move 3 from 2 to 4
|
||||
move 5 from 9 to 1
|
||||
move 10 from 7 to 5
|
||||
move 5 from 1 to 3
|
||||
move 5 from 3 to 5
|
||||
move 5 from 4 to 3
|
||||
move 2 from 4 to 2
|
||||
move 5 from 8 to 3
|
||||
move 25 from 5 to 2
|
||||
move 3 from 3 to 6
|
||||
move 1 from 1 to 3
|
||||
move 3 from 6 to 7
|
||||
move 1 from 4 to 2
|
||||
move 1 from 5 to 8
|
||||
move 2 from 4 to 9
|
||||
move 1 from 8 to 1
|
||||
move 20 from 2 to 7
|
||||
move 10 from 7 to 1
|
||||
move 1 from 1 to 7
|
||||
move 4 from 7 to 8
|
||||
move 5 from 5 to 4
|
||||
move 4 from 8 to 6
|
||||
move 1 from 1 to 3
|
||||
move 5 from 7 to 4
|
||||
move 2 from 1 to 5
|
||||
move 4 from 9 to 1
|
||||
move 3 from 2 to 5
|
||||
move 5 from 5 to 1
|
||||
move 1 from 9 to 1
|
||||
move 11 from 1 to 3
|
||||
move 1 from 6 to 2
|
||||
move 7 from 3 to 5
|
||||
move 11 from 3 to 7
|
||||
move 1 from 2 to 6
|
||||
move 7 from 7 to 8
|
||||
move 1 from 9 to 1
|
||||
move 2 from 3 to 1
|
||||
move 1 from 5 to 3
|
||||
move 4 from 1 to 6
|
||||
move 4 from 6 to 3
|
||||
move 9 from 4 to 5
|
||||
move 2 from 8 to 2
|
||||
move 4 from 6 to 9
|
||||
move 3 from 2 to 4
|
||||
move 1 from 8 to 6
|
100
day5/src/main.rs
100
day5/src/main.rs
@ -1,3 +1,99 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{fs::read_to_string, str::Lines};
|
||||
|
||||
use color_eyre::Result;
|
||||
use itertools::Itertools;
|
||||
|
||||
fn parse_stacks(input: &mut Lines) -> Vec<Vec<char>> {
|
||||
let horizontal_stack = input
|
||||
.map(|line| {
|
||||
line.chars()
|
||||
.skip(1)
|
||||
.step_by(4)
|
||||
.map(|c| if c.is_whitespace() { None } else { Some(c) })
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.take_while(|line| line.first().unwrap_or(&None) != &Some('1'))
|
||||
.collect::<Vec<_>>();
|
||||
let num_stacks = horizontal_stack.last().map(|v| v.len()).unwrap_or(0);
|
||||
let mut vertical_stack: Vec<Vec<char>> = Vec::with_capacity(num_stacks);
|
||||
for _ in 0..num_stacks {
|
||||
vertical_stack.push(vec![]);
|
||||
}
|
||||
|
||||
for v in horizontal_stack.iter().rev() {
|
||||
for (i, c) in v.iter().enumerate() {
|
||||
if let Some(ch) = c {
|
||||
vertical_stack[i].push(*ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
vertical_stack
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
struct Move {
|
||||
pub amount: usize,
|
||||
pub from: usize,
|
||||
pub to: usize,
|
||||
}
|
||||
|
||||
impl Move {
|
||||
fn play9000(&self, stacks: &mut [Vec<char>]) {
|
||||
for _ in 0..self.amount {
|
||||
if let Some(element) = stacks[self.from].pop() {
|
||||
stacks[self.to].push(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn play9001(&self, stacks: &mut [Vec<char>]) {
|
||||
let i = stacks[self.from].len() - self.amount;
|
||||
let mut moving = stacks[self.from].split_off(i);
|
||||
stacks[self.to].append(&mut moving);
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_move(line: &str) -> Move {
|
||||
let (amount, from, to) = line
|
||||
.split_whitespace()
|
||||
.skip(1)
|
||||
.step_by(2)
|
||||
.map(|s| s.parse::<usize>().unwrap_or(0))
|
||||
.take(3)
|
||||
.collect_tuple()
|
||||
.unwrap_or((0, 0, 0));
|
||||
Move {
|
||||
amount,
|
||||
from: from - 1,
|
||||
to: to - 1,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let input = read_to_string("input.txt")?;
|
||||
let mut lines = input.lines();
|
||||
let mut stacks9000 = parse_stacks(&mut lines);
|
||||
let mut stacks9001 = stacks9000.clone();
|
||||
let moves = lines.skip(1).map(parse_move);
|
||||
for m in moves {
|
||||
m.play9000(&mut stacks9000);
|
||||
m.play9001(&mut stacks9001);
|
||||
}
|
||||
let top9000 = stacks9000
|
||||
.iter()
|
||||
.map(|stack| stack.last().unwrap_or(&' '))
|
||||
.fold(String::new(), |mut s, v| {
|
||||
s.push(*v);
|
||||
s
|
||||
});
|
||||
let top9001 = stacks9001
|
||||
.iter()
|
||||
.map(|stack| stack.last().unwrap_or(&' '))
|
||||
.fold(String::new(), |mut s, v| {
|
||||
s.push(*v);
|
||||
s
|
||||
});
|
||||
println!("top crates 9000: {top9000}");
|
||||
println!("top crates 9001: {top9001}");
|
||||
Ok(())
|
||||
}
|
||||
|
7
day6/Cargo.lock
generated
Normal file
7
day6/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day6"
|
||||
version = "0.1.0"
|
1
day6/input.txt
Normal file
1
day6/input.txt
Normal file
@ -0,0 +1 @@
|
||||
mvwvrwvwbblffmvmhmllmzmqzzbhbnnvrnvnmvvqrqrccpsstvvshvvpvvpddzwwjddfzzgbbzcchrrtzzmfffzqqsjjbfbjfjwffhrhrgrfrsfrsffbwwphwhgwgmgnggzwzhwzzpggnccdbcbssgccqgcgcvgccwffrqfqtqmqppwphhlbblnnwhwfhwhmhzhmmzbmbbjjmcjcggwlgltldttpccjlccbjccvfcvvdbvdvndvvmbmcbmmhphpbhhgjgllmljlqlwlclzlccrvrdvdzvzzzbrbrnbblplrplpsstdtjddgjgjgwjwzwbzwwrhwwbzwbwpwssvgvnnwnvvjqqswwsccwctwtntdndffjzfzmfzmfzmfzzhjzhzssdsgsnggbbqdqlqbllmglgddqppjjtzttlflrrczcmzzsppvfpvffcfrccvvvhjvhvfhfbbwdwrwswqqftfbfcfdfnfpnfflbbcmcqqsqwqqccmwmvwvffvdvlvtvqttnllqslsnllzplldmmzczhzmzzhllpfpqpnnqwwwrzzdpzzhccfvcvclcnnrjrmjrjlrlflqqtpqqdgqghhwdwdttlztttwmmvfmftfptphhddswdsdpdvpvpcpjjnvjvqvhvqqqfgqqgwqgwghwwmmvmvfmvvnvsslcclzlslppztzfzbzllcgllcsllvgvqvtqtsstztwwgjgghnhnhdnnqgnntqqtccdmcmhmpphpmmmbpbptpnnnmnppwlpwwfpwfwmfwfssbspslsflljpppbsspwptpwttfbtfftltvlttdmttllmggfcgfccvwcvczvvgvsgswsrrwppgcpggpgnngfnndrrdjrdrfdfmmjmsmbmmwjjjfzfdfbdbbtgbbcsbccgbbrvvrqrwqwmmhrhhbcbdbvdvzdvdjvvnwntwwdfwwrhrmhhnghhncccfttmpmrrjhhqddrsrvvssmrrgvgdgmmfqqhttspswpwlplpjljcjmjmvmdvvhbvvtqvqccczwwtlllztlzzpnnqznzddqsqvsshrrmccnppgrrjcjpccrvcvnvcncllffvnnbsbhhrmhmzzzhrhchjccgjcjwwhddmfmhhmrrrbccqddmjdmjdjtdjjmttzstsctssvvgghgbbhmhzmmjqqqqjgjfjpffpmpzmzszfzgzcggpmpnnqjqffgpghhszzvlzzdgzggqmggqlllcwwtzwwcfwccpjpggtqgtttzffdpffjzfzddzppprnprpqqbppvjpjzppbzpbzppwzzcnndsdzszbssqwqggnhggnzggpcpnndssghsggmfmrffvddvwvssjmjrmrmnndwdwhdhwwfjfjwjmwwqssmdsmdmssqzzrgzzjttnqnfqfcccvvmsvsvffccdjdccgtgqqjwqqnbqqnhqhrqrmrgmrrzjzrznzllwrlrbbcppctptwtfttlntnltnlnzzhrzhrzrtzzvsvfvjffsbsnbbfpphtptjjmffqgqnggnqnsshffslflggtlggmpggnfgfbgbfbcbbtdbdjqwfggzsfmzflttgdfqchhtjfwlmdnsbvmqcrhsrtwtjlmnlwbvjvqdzswdthbjslqzgmtzfjfcrgbhrrjtzgljbqfrzzqszhddnmzpnbgnflghnflwdmjdhgpnvwvnltcngwggqdznrpdtwsrclwwlfzhnjtpqcgzjqjnhcwbhndwvgrczhzwfjrdvjztdbjshmhrrqctjwpcdnpnvrtggrmhzhdtlntjphcddplgfvvmjzcbbpjbqbjwmnwqgftbmchghwvrlptvnfbffvgtdbtnfzwdmdlgzjbrvffvbrfwgjzzpbpcdzhcjbhfwnmqqwvjvnpgdqdjsmwdmrgfqrwhhqqjpfmvlncfdjchrccwpbptccdchqwvbcqzlhbfgrdzgncbwrzqpfszrcwtmnvbztjlzjlrqqfrnplhnmdjljcpnqssthhmjqrrlwdvsjswdwtfstmbvwhbptjnphjmnllbwffppzmdpchbcwcmgqzfmdqvhcmrvtgtjwlzfpnjnjtfvdhtjlqsdjwrrnflnsqrtfsnbjfdllhqslltsjqzdfqthqjjgrtqjwmlqqlhvszqswmdcbnwqgshpvfjdtvsqjvcnrnvtpfsgqszhtmcdlsqjwmttcqsdlvssrgwhtmtqwmttptnmgzpwzzrbwtsrjhmjpblztgftppcwwrjppvwlvdhwwdlfcdvhwpvhqpwrqsczvlmtghrrvqbphljcmcrfmwltlmnzchzrlbgspdjwfbhrmnfhvjwlgtghcpbfgdvrmwbqbprfvwpzqzrgqbhjtztwhjcjtncmbgjphsgdfvjwjljlwzhsdldqtdvgtzpwtmrbnpvqrmfdwngzqtsdjjztslrwdnfwgbnsjblcjzvmgbqllmdvvvdcvplgbzmhcrpbbjbfzhjgfpmjtrpmgvshzvqhcbcjzfcsvqggjcllcnjlrwqfpzldswzjgzvqwvszhrntnvlcpdcfqhqrtmhbdjqpfblrsbrhdfdwfgbhsnnjpgjvfpssfmhdbdncfrqbzpbttrhfzqnrttltqbvmhglbdpwmdbmgwcdsdsflmcnphwvbbhgqpqmwbdsmqwhcdftdlcfnstlfnzzsjhqzlsdmhpvlcqvhhlpdtzlqzlvbbwhhdsqhntbtpjjvnjlrncfmvnqmzwpldgrbfcfgdtlmrfzcbqfhvhpmsrrlnqwfggwrjsmnpnqhvvcfsfspfrmhwmbpqfhprzsswrczttlczhcqvgqqsnbhhfszqbswgtcjgddhngtcvlwqqmqzntrcwgwjhmhlgclpgtmqnpgwwhnjfdvvjgmqjlzsmwztpsdzrjlshswzljlmdzfqmqbtgtzlsfwqvwrdchjvrdnwdbprfvdvczstvnzfzzfmzbwjhtflbmhlgmfzrdfrqwfbltwqlqrghlprppvlqwggvczdcnmrmblhcfmpzdmqppgwhbbrjlzsvmsfzlrdljftcrdfdgmvrccwszpjmvdnbmfdnsgmgzsdpbrlsqvsmcwwqlwtwbgfvwtsmpqlnhjchnzrpncgtcqgwqrmqmrwsbmdvqcpggpzcjgtrhvnbpprlwfnjlvrgrdjjvncjmmflrpczqnlbqczggssqfcjcrghqlsztpdjpbbfcdjzzdjbljlsczdmrgshdscvhnltrwchjcmjzmjbhldnqzwwpswsnsldcbdcdpdgpjgwrnfbcpjtvzlhvgggldcfqcwwppvltsvsmwzwdgmhnfggtgtwldmrglcvmstgmbgbjhwwhgdhfrbjlwfhjfppdmffblbbzrplhlhqlsrnsthvjtglqntzcncmvhqnlsvvrscrhlncgncjswfgcvgjlwsndzmsbhbdqsggdgrsfqtzwnjpsdlbsqjrrjwwlbptwqpfqwvpsrtrmstddzdbjjlwvfqcpfczpsnmcgbfpbwcpljdhrgsqftbnplccjphwsdbprqfqqfcvtcdznnhrbdqpccphvdgtspmzzdbnslnrvtfrtbhcfzfgmhrttmdpwftvccjbllhqgtmpgwvbdjgtvtfbfnnsfgzqjmrpbcmqhpfbstznbvgtbhnwbbnjfsthdgdrpfdtvrtmgbwzqqpnlltbshjvnhsmqhqwzgbsfqqccfznjtnnzdrgcvwnlffdgvvqzvwhwfswdmqlrsglntzsnwjzgrhhwzzshwsfmlmrbnmrqlptmjgmtqctrmddzghsgtrbbcsmhtcnrzwmvrjmrnmhbjmflrclvlbzwbgmtnmwqgfmbbnnrdvhqcflglvzbmjzjtvnmrbgghnccfrphjshsgtrhfmmghhpwgclfvzfbdccsfrlfwtsjjnhlndpwcjdtlllhcsvwrwsbppqwhfcvnsnrvthrsbgmgjhpmjdndmdqdgzfvbqfmgfjrnrjchstrjprfwfnjqblhjdgsstvtpcsvmpbhggnwzncpjdhrcllcghhprhwhfgsqpfzphrdlcbrccglsb
|
@ -1,3 +1,29 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{collections::HashSet, fs::read_to_string};
|
||||
|
||||
fn find_nonrecuring_sequence(input: &[char], length: usize) -> Option<usize> {
|
||||
input
|
||||
.windows(length)
|
||||
.enumerate()
|
||||
.find(|(_, chars)| {
|
||||
for i in 1..chars.len() {
|
||||
if chars[..i].contains(&chars[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
})
|
||||
//.find(|(_, chars)| chars.iter().collect::<HashSet<_>>().len() == length)
|
||||
.map(|(i, _)| i + length)
|
||||
}
|
||||
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
const PACKET_START_LENGTH: usize = 4;
|
||||
const MESSAGE_START_LENGTH: usize = 14;
|
||||
let input = read_to_string("input.txt")?;
|
||||
let input = input.chars().collect::<Vec<_>>();
|
||||
let packet_marker = find_nonrecuring_sequence(&input, PACKET_START_LENGTH);
|
||||
println!("first packet marker at {packet_marker:?}");
|
||||
let message_marker = find_nonrecuring_sequence(&input, MESSAGE_START_LENGTH);
|
||||
println!("first message marker at {message_marker:?}");
|
||||
Ok(())
|
||||
}
|
||||
|
56
day7/Cargo.lock
generated
Normal file
56
day7/Cargo.lock
generated
Normal file
@ -0,0 +1,56 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "blanket"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b04ce3d2372d05d1ef4ea3fdf427da6ae3c17ca06d688a107b5344836276bc3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "day7"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"blanket",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
blanket = "0.2"
|
||||
|
1015
day7/input.txt
Normal file
1015
day7/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
184
day7/src/main.rs
184
day7/src/main.rs
@ -1,3 +1,183 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{collections::HashMap, fs::read_to_string, iter::Peekable, str::Lines};
|
||||
|
||||
/*
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct File {
|
||||
name: String,
|
||||
size: usize,
|
||||
}
|
||||
|
||||
impl File {
|
||||
fn size(&self) -> usize {
|
||||
self.size
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct Directory {
|
||||
path: String,
|
||||
files: Vec<File>,
|
||||
}
|
||||
|
||||
fn size_of_dir(dirs: &[Directory], dir: &str) -> usize {
|
||||
dirs.iter()
|
||||
.filter_map(|d| {
|
||||
if d.path.contains(dir) {
|
||||
Some(d.files.iter().map(File::size).sum::<usize>())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
|
||||
fn parse_command(
|
||||
lines: &mut Peekable<Lines>,
|
||||
cwd: &str,
|
||||
directorys: &mut Vec<Directory>,
|
||||
) -> Result<String, String> {
|
||||
let command = lines.next().unwrap().split_whitespace().collect::<Vec<_>>();
|
||||
if command.len() < 2 || command[0] != "$" {
|
||||
return Err("first line is not a command".to_owned());
|
||||
}
|
||||
match command[1] {
|
||||
"cd" => {
|
||||
if command.len() != 3 {
|
||||
return Err("cd needs exactly 1 argument".to_owned());
|
||||
}
|
||||
match command[2] {
|
||||
"/" => Ok("/".to_owned()),
|
||||
".." => {
|
||||
if cwd == "/" {
|
||||
Ok(cwd.to_owned())
|
||||
} else {
|
||||
let dirs = cwd.split_inclusive('/').collect::<Vec<_>>();
|
||||
let nwd = dirs[..(dirs.len() - 1)]
|
||||
.iter()
|
||||
.fold(String::new(), |s, v| s + v);
|
||||
Ok(nwd)
|
||||
}
|
||||
}
|
||||
dir => Ok(cwd.to_owned() + dir + "/"),
|
||||
}
|
||||
}
|
||||
"ls" => {
|
||||
while let Some(line) = lines.peek() {
|
||||
if line.split_whitespace().collect::<Vec<_>>().first() == Some(&"$") {
|
||||
break;
|
||||
}
|
||||
let line = lines.next().unwrap();
|
||||
let node = line.split_whitespace().collect::<Vec<_>>();
|
||||
if node.len() != 2 {
|
||||
return Err("ls needs two inputs per line".to_owned());
|
||||
}
|
||||
match node[0] {
|
||||
"dir" => directorys.push(Directory {
|
||||
path: cwd.to_owned() + node[1] + "/",
|
||||
files: vec![],
|
||||
}),
|
||||
size => directorys
|
||||
.iter_mut()
|
||||
.find(|d| d.path == cwd)
|
||||
.unwrap()
|
||||
.files
|
||||
.push(File {
|
||||
name: node[1].to_owned(),
|
||||
size: size.parse().expect("invalid Size"),
|
||||
}),
|
||||
}
|
||||
}
|
||||
Ok(cwd.to_owned())
|
||||
}
|
||||
_ => Err("unknown command".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
const TOTAL_SPACE: usize = 70000000;
|
||||
const NEEDED_FREE: usize = 30000000;
|
||||
let input = read_to_string("input.txt").unwrap();
|
||||
let mut lines = input.lines().peekable();
|
||||
let mut dirs = vec![Directory {
|
||||
path: "/".to_owned(),
|
||||
files: vec![],
|
||||
}];
|
||||
let mut cwd = "/".to_owned();
|
||||
while lines.peek().is_some() {
|
||||
cwd = parse_command(&mut lines, &cwd, &mut dirs).expect("invalid input");
|
||||
}
|
||||
let sizes = dirs.iter().map(|d| size_of_dir(&dirs, &d.path));
|
||||
let sol1: usize = sizes.clone().filter(|s| s < &100_000).sum();
|
||||
println!("{sol1}");
|
||||
let used = size_of_dir(&dirs, "/");
|
||||
let free = TOTAL_SPACE - used;
|
||||
let additional = NEEDED_FREE - free;
|
||||
println!("{used} Bytes used, {free} Bytes free, {additional} Bytes need to be freed");
|
||||
let sol2 = sizes.filter(|s| s >= &additional).min().unwrap();
|
||||
println!("Deleting Directory with size {sol2}");
|
||||
}
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
let input = read_to_string("input.txt").unwrap();
|
||||
let mut cwd = "/".to_owned();
|
||||
let mut files = HashMap::new();
|
||||
for line in input.lines() {
|
||||
let line = line.split_whitespace().collect::<Vec<_>>();
|
||||
match line.len() {
|
||||
3 => match line[2] {
|
||||
"/" => cwd = "/".to_owned(),
|
||||
".." => {
|
||||
cwd = {
|
||||
if cwd == "/" {
|
||||
cwd
|
||||
} else {
|
||||
let dirs = cwd.split_inclusive('/').collect::<Vec<_>>();
|
||||
let nwd = dirs[..(dirs.len() - 1)]
|
||||
.iter()
|
||||
.fold(String::new(), |s, v| s + v);
|
||||
nwd
|
||||
}
|
||||
}
|
||||
}
|
||||
dir => cwd = cwd + dir + "/",
|
||||
},
|
||||
2 => {
|
||||
if (line[0] != "$") && (line[0] != "dir") {
|
||||
let size = line[0].parse::<usize>().unwrap();
|
||||
let path = cwd.clone() + line[1];
|
||||
files.insert(path, size);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
let mut directories = HashMap::new();
|
||||
for (path, size) in files {
|
||||
let mut folders = path
|
||||
.split_terminator('/')
|
||||
.map(|s| s.to_owned())
|
||||
.collect::<Vec<String>>();
|
||||
folders.pop();
|
||||
for (index, folder) in folders.clone().iter().enumerate() {
|
||||
let previus = if index > 0 { &folders[index - 1] } else { "" };
|
||||
folders[index] = previus.to_owned() + folder + "/";
|
||||
}
|
||||
for folder in folders {
|
||||
*directories.entry(folder).or_insert(0) += size;
|
||||
}
|
||||
}
|
||||
let result1: usize = directories.values().filter(|&&size| size < 100_000).sum();
|
||||
const TOTAL_SPACE: usize = 70000000;
|
||||
const NEEDED_FREE: usize = 30000000;
|
||||
let used = *directories.entry("/".to_owned()).or_insert(0);
|
||||
let free = TOTAL_SPACE - used;
|
||||
let additional = NEEDED_FREE - free;
|
||||
let result2: usize = directories
|
||||
.values()
|
||||
.filter(|&&size| size >= additional)
|
||||
.min()
|
||||
.map(|size| *size)
|
||||
.unwrap_or(0);
|
||||
println!("{result1} bytes used by directories smaller than 100000. {result2} Bytes removed by the smallest directory");
|
||||
}
|
||||
|
7
day8/Cargo.lock
generated
Normal file
7
day8/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day8"
|
||||
version = "0.1.0"
|
99
day8/input.txt
Normal file
99
day8/input.txt
Normal file
@ -0,0 +1,99 @@
|
||||
200120010031113332213034140102430141241124321111512323442304040044220141342121012210022220211111200
|
||||
111021120230012003124233312003010303204555454332453445353125225214221214442214301113012111020220220
|
||||
010000112330232223210123331341111021455213441355415452453433542411022110033014112420103200010200112
|
||||
210220131023203033023421012411405531115123145115445215311422135252541100222231431331003220231121021
|
||||
020112210133112114444340100410411231114131452544155151415233415312511222041221113442132231003203100
|
||||
121210122332301142321211440441113455552434332511455325315545354524142541534411112013143013120333022
|
||||
002022223332143323320030004111431434153352153321414154453442552321332341355132444030442110103203212
|
||||
212130023213100232130230411132244242133251435525323326611211534441513532233340420321144212221332012
|
||||
112201210213131241203033341411115513233426453426433653356253533133113511115222441140433214102332200
|
||||
212012000101044144022321521321444445566546646625625665232323663631331412343532242340023204432003233
|
||||
101233132121222100241254211542133266356326564552445466322626353633223221135151311240430411433022011
|
||||
200132020222314334333551152431232424524623645555522366665322366466545513112135535223102441334310202
|
||||
023113000020114221524122422222662645435544455234636242322656464245462233555511334411233402112203303
|
||||
323212301014434412315252233452332225554646452654545433445553336343544664455435323243510303023142200
|
||||
310022200424121333144123222262332322343322244646667564465544426245466232342143412141451122001041322
|
||||
212301111322001335441132334525635254352425553354565445643472236236266635446421522132452121404230333
|
||||
222212444300345211222512256444456624535343536756355746664436374344346652444335121144422222340114403
|
||||
133103420101433344253425324366444265345745457464444766674564476573243345254266312555221132304022243
|
||||
104024111323421413115464433455553477333456354575666765646757774776752425462423244113225443242031103
|
||||
102001244212344453145353232652647556546465453563544776667356374453675332254663444121345213131024201
|
||||
224444241243433331136646422564367344447534333336573546336576477746463642222264422255444411444213332
|
||||
111102440221143134255523244546456346745346547453543465664363545634575433436342252431313443241200434
|
||||
134231321331555233423635635366465473563535535586445888474374535544636375425246452265522242444124430
|
||||
234112414314111344422243544643454775656784865866884848444877466476364476356322553554245224411411221
|
||||
034400114351525345222546546744637535635657575787587675474664764764736443646462322222525151425423322
|
||||
200214241324215322354446653764777674587466544685754678446567884767437556756324542252661541311422130
|
||||
343144113253113264625454456777333344687566876677476786864558645875776364454562645333232242321313142
|
||||
343024121143435322432236376444777668467756646886688564457885758774655565674476525265433235351133020
|
||||
403402124545255442342535445764457654765745674556784877787445455686478773563733543423236235255444144
|
||||
103322531152132266562676355566367676848756788886766967585484486646776553753344443262466623351341241
|
||||
310355244513624552353465735465555764667556575665597778969594858667646774744555337236256442514154340
|
||||
023311451112523462333545544537465688645559988688956997665697964748587858337347363225646321434554144
|
||||
320135522136342345436443367666564847488558589757575579796688785767645678467555334323622425311134113
|
||||
302355525243323546577736555686874886486985688686888898966978978668487864787645754566534465541511251
|
||||
334125312126266532347576536548547584696886997768569758698995755875465674754333433642553345425533431
|
||||
341111335132225635365534457665748575977867585959997886979957965558787465664637533766462255534332423
|
||||
332515314534343636736373478687676678865555895657977886779567677978977887466835476754353523355412552
|
||||
223554423243256435734467677444784886576856669787898778968956989875566754875777467667635224535114135
|
||||
155522522343322534364735656868875656687568869667769697877887796866975856457447636733764232364431215
|
||||
242345244424435673345476658556448689589759768689899966877768987857579874745884637474453634352133231
|
||||
415255446645436567674735664645455855996887768879976678686967768687868985856885736776326622253351232
|
||||
345511155426334655353457846578475998667966669787979667866969678557875668566464436456435236255355314
|
||||
142554534636264637437346664558867877978687978689679869967766679569789677485678377367342526223134543
|
||||
445152112563265336347774464854776998568899676687677797996796877777879786686845577654534235322155423
|
||||
333311452256452445537757558677965658888896678979799998788899698785896978877575444547572432544335251
|
||||
153342523322435374455644657476596955598987666997999878876686677879688676464687476363732553363413554
|
||||
144335145664565566437454557675966795686769969779977988878679878778787789465465637576634655354532332
|
||||
152415343652336664567566647557776598677998979889877998977867798897785759685544636646555455665423232
|
||||
233452324356364643433768554555595977968766779897887998898666688775789556775758843355374525244243434
|
||||
415514136342636535455644448567857957878867697988999887897878896698589669784466744746433345345355353
|
||||
232342145445335734443368474877857768999979889789879797978786868766697957448687837436437246435352325
|
||||
423142134652644455355368647749855698998886897798977997799867788779868756865564445675347463653623132
|
||||
221215125542657466763755887857659858677696867997877899797779899996787779754784846775376254442211254
|
||||
154531463524644747547747455647685566769977767978799879788898879798999996758665537564563322242224125
|
||||
114543323332546776763457675777969696978788779877889799879998997975759878686666834757774555334611241
|
||||
353441154256436766664748544445957885788777978878979877989798876799786999466647747557553324526153313
|
||||
433233236244364537664567776764977668967888876787887977898978679686668778764647857553662664333221513
|
||||
112335142543334473565677774456986769698869989679787999966877889796668798648474667745633463364123315
|
||||
113555236654542657737447854474695576987788777767987976776779677896568655666568777374452626625515123
|
||||
335535115334436455537766485588496998559679678997888767666867796988758985466776445675326242423551222
|
||||
113534446446435634464566878474597579966586699697988866966997787776788976778774466655756463456235323
|
||||
432234422656545375357656547448457656589888789768979867898878979959955468888683644466555336562315155
|
||||
313344415452422533675445775845665999956589788887986877769867786689888565577764433373633363624515141
|
||||
222432351346446453465663784584875977688789959977876966969658866777886544775874577535665532224311252
|
||||
225114233145352533344653757488874695566977756698769768695668575699668757584555454357642544414312222
|
||||
033415322244643242337557674678486867575857998965787859688788778777887745544746656765646262354135222
|
||||
244444135424622245536477356767676647596876888859989597677576756885858547856577434533266366252341111
|
||||
043422441154553466473376764757644888596669857975585975898957778585855575867574554436566563342243533
|
||||
331142132342425642446677456357664865566895568659588999997598897847485545576757377726563624233332331
|
||||
023252542543632422666654576368776445864568889675685656595757555564576478356355573264462564525315531
|
||||
401013153355343645357335364463874854866687865999886679877556446867474565563474773455256232432344241
|
||||
021145311524153334266573666344586785645787666877957988698886547444446737764473344255436645355133043
|
||||
343022114235145422524664767447348848745548778464684486768568675765556575337775543626443412212441440
|
||||
111402455441135334663624565477563468586767564584754776865658486876757446535673333342623334312243002
|
||||
300312451335434322222245676775746358685854756547745674447587647487533473336654232544332431554454412
|
||||
433111155454541556355524273356653577688858857767884847858548544877576457444762553325524214215402141
|
||||
131233333423335563265232427676636343767667757678865557657665545337553674363435662333422331253432142
|
||||
424110224332255444554444426563344537343587775787775766858448446366677553432226234426335534235001312
|
||||
333412002215124441543424366273747763767633456777658554454464446357566564765333524264253113145112300
|
||||
101110030515255434456252656567734365435643756543777575374763565634563366532624443621453215143234300
|
||||
303322412424455315323623364345353365376676743654344676735433644466637676342646445331232331222232310
|
||||
323112211415542144152522545435246756534467755554567676637543357465766366552324534423444455001240332
|
||||
104010010231221552145233456226456635564775656444567465773637433733444632663325561451234351230241312
|
||||
121411232340543435321316435636242655564355535365574763633547465475523553325562122152444444042300041
|
||||
131012210332331125512334254246234345354543573744464635755354544666345534262435114123351541032131413
|
||||
320204021134412321515435566234224352423426577577364457356445435455454244243342521425351312003010221
|
||||
323114214132034241313542544555435465334424654666346364554655422236635456436354122354410044244241323
|
||||
013302120424301452153353441245652435266525344656664634425626224355262362255351231351513443132401213
|
||||
320030122021334215313244242334523262333453263233364243362363226452453421344311524253311414201210001
|
||||
232000301112410134252124412414346224626463252363536262245565624425334453135542241232142142113023001
|
||||
023101113421202000305251552134255163452646652324334242436543224522235515444445314014323100240020120
|
||||
320223110031202012323335553432231212252653563665545464422324656333443431535442453303001103202231020
|
||||
102033222010100142203435155413125314311166645446465322244546532441244154143433143443342400201012012
|
||||
103310002120123402241302221241151441435355114335344522434421453552354154135223134443030043002000021
|
||||
112323110033212002113322411233332355223342424233213123445224135331545115152043042400020200022133330
|
||||
022111301200101044211214231433231311322554214331413543414521424255241531111410022413003020200231110
|
||||
012022111212202121003233141343155411314255551134343533133453252153433344441013011221420230021203220
|
||||
221101122202110034040022441212441254112211113355531534335143125434435312222200311411322330203331100
|
||||
210122210200133032213341213111433213432513121525124133544144433541201142230241123430213303001122221
|
@ -1,3 +1,84 @@
|
||||
use std::{collections::HashSet, fs::read_to_string};
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let input = read_to_string("input.txt").unwrap();
|
||||
let input = input
|
||||
.lines()
|
||||
.map(|line| {
|
||||
line.chars()
|
||||
.map(|c| String::from(c).parse::<i8>().unwrap())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let mut visible_trees = HashSet::new();
|
||||
println!("size: {}x{}", input.len(), input[0].len());
|
||||
if input.len() != input[0].len() {
|
||||
panic!("field not square");
|
||||
}
|
||||
let length = input.len();
|
||||
for i in 0..length {
|
||||
let rev_i = length - i - 1;
|
||||
let mut max_values = [-1; 4];
|
||||
for j in 0..length {
|
||||
let rev_j = length - j - 1;
|
||||
if input[i][j] > max_values[0] {
|
||||
max_values[0] = input[i][j];
|
||||
visible_trees.insert((i, j));
|
||||
}
|
||||
if input[j][i] > max_values[1] {
|
||||
max_values[1] = input[j][i];
|
||||
visible_trees.insert((j, i));
|
||||
}
|
||||
if input[rev_i][rev_j] > max_values[2] {
|
||||
max_values[2] = input[rev_i][rev_j];
|
||||
visible_trees.insert((rev_i, rev_j));
|
||||
}
|
||||
if input[rev_j][rev_i] > max_values[3] {
|
||||
max_values[3] = input[rev_j][rev_i];
|
||||
visible_trees.insert((rev_j, rev_i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let greatest_view = input
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(x, line)| {
|
||||
let input = &input;
|
||||
line.iter().enumerate().map(move |(y, tree)| {
|
||||
let mut view = [0; 4];
|
||||
for radius in 1..length {
|
||||
let left = x as isize - radius as isize;
|
||||
let right = x as isize + radius as isize;
|
||||
let up = y as isize - radius as isize;
|
||||
let down = y as isize + radius as isize;
|
||||
if view.iter().all(|v| *v != 0) {
|
||||
break;
|
||||
}
|
||||
if x != 0 && view[0] == 0 && (left == 0 || input[left as usize][y] >= *tree) {
|
||||
view[0] = radius;
|
||||
}
|
||||
if y != 0 && view[1] == 0 && (up == 0 || input[x][up as usize] >= *tree) {
|
||||
view[1] = radius;
|
||||
}
|
||||
if x != length - 1
|
||||
&& view[2] == 0
|
||||
&& (right == length as isize - 1 || input[right as usize][y] >= *tree)
|
||||
{
|
||||
view[2] = radius;
|
||||
}
|
||||
if y != length - 1
|
||||
&& view[3] == 0
|
||||
&& (down == length as isize - 1 || input[x][down as usize] >= *tree)
|
||||
{
|
||||
view[3] = radius;
|
||||
}
|
||||
}
|
||||
view.iter().fold(1, |p, v| p * v)
|
||||
})
|
||||
})
|
||||
.flatten()
|
||||
.max()
|
||||
.unwrap();
|
||||
println!("Greatest view is {}", greatest_view);
|
||||
}
|
||||
|
7
day9/Cargo.lock
generated
Normal file
7
day9/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day9"
|
||||
version = "0.1.0"
|
2000
day9/input.txt
Normal file
2000
day9/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
171
day9/src/main.rs
171
day9/src/main.rs
@ -1,3 +1,170 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
fs::read_to_string,
|
||||
mem::MaybeUninit,
|
||||
ops::{Add, AddAssign, Sub, SubAssign},
|
||||
};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
|
||||
enum Direction {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Direction {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
"U" => Ok(Self::Up),
|
||||
"D" => Ok(Self::Down),
|
||||
"L" => Ok(Self::Left),
|
||||
"R" => Ok(Self::Right),
|
||||
_ => Err("invalid Direction"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
|
||||
struct Movement {
|
||||
direction: Direction,
|
||||
steps: usize,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Movement {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
let words = value.split_whitespace().collect::<Vec<_>>();
|
||||
match &words[..] {
|
||||
[direction, steps] => Ok(Movement {
|
||||
direction: Direction::try_from(*direction)?,
|
||||
steps: match steps.parse::<usize>() {
|
||||
Ok(it) => it,
|
||||
Err(_) => return Err("unable to parse steps"),
|
||||
},
|
||||
}),
|
||||
_ => Err("Need 2 words in format [Direction] [Steps]"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Copy, Default, Hash)]
|
||||
struct Position {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
|
||||
impl Add for Position {
|
||||
type Output = Position;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
x: self.x + rhs.x,
|
||||
y: self.y + rhs.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for Position {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self.x += rhs.x;
|
||||
self.y += rhs.y;
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub for Position {
|
||||
type Output = Position;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
x: self.x - rhs.x,
|
||||
y: self.y - rhs.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SubAssign for Position {
|
||||
fn sub_assign(&mut self, rhs: Self) {
|
||||
self.x += rhs.x;
|
||||
self.y += rhs.y;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Default)]
|
||||
struct Link {
|
||||
head: Position,
|
||||
tail: Position,
|
||||
tail_positions: HashSet<Position>,
|
||||
}
|
||||
|
||||
impl Link {
|
||||
fn simulate_position(&mut self, head_position: &Position) {
|
||||
self.head = *head_position;
|
||||
let distance = self.head - self.tail;
|
||||
if distance.x.abs() > 1 || distance.y.abs() > 1 {
|
||||
self.tail.x += distance.x.signum();
|
||||
self.tail.y += distance.y.signum();
|
||||
}
|
||||
self.tail_positions.insert(self.tail);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
struct Rope<const N: usize> {
|
||||
links: [Link; N],
|
||||
}
|
||||
|
||||
impl<const N: usize> Rope<N> {
|
||||
fn simulate(mut self, movement: &Movement) -> Self {
|
||||
for _ in 0..movement.steps {
|
||||
let head_position = self.links[0].head
|
||||
+ match movement.direction {
|
||||
Direction::Up => Position { x: 0, y: -1 },
|
||||
Direction::Down => Position { x: 0, y: 1 },
|
||||
Direction::Left => Position { x: -1, y: 0 },
|
||||
Direction::Right => Position { x: 1, y: 0 },
|
||||
};
|
||||
self.links[0].simulate_position(&head_position);
|
||||
for i in 1..self.links.len() {
|
||||
let previous = self.links[i - 1].tail;
|
||||
self.links[i].simulate_position(&previous);
|
||||
}
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> Default for Rope<N> {
|
||||
fn default() -> Self {
|
||||
let mut links: [Link; N] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
links.fill(Default::default());
|
||||
Self { links }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = "R 5
|
||||
U 8
|
||||
L 8
|
||||
D 3
|
||||
R 17
|
||||
D 10
|
||||
L 25
|
||||
U 20";
|
||||
let input = read_to_string("input.txt").unwrap_or_else(|_| input.to_owned());
|
||||
|
||||
let rope = input
|
||||
.lines()
|
||||
.flat_map(Movement::try_from)
|
||||
.fold(Rope::<9>::default(), |rope, movement| {
|
||||
rope.simulate(&movement)
|
||||
});
|
||||
println!(
|
||||
"The second knot visited {} positions, the tail visited {} positions",
|
||||
rope.links[0].tail_positions.len(),
|
||||
rope.links[8].tail_positions.len()
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user