day 13 task 1
This commit is contained in:
1 parent
eb7467f615
commit
ad3b71b159
4 files changed
+56
-1
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
1,380,379,385,1008,2663,456801,381,1005,381,12,99,109,2664,1101,0,0,383,1101,0,0,382,20101,0,382,1,20102,1,383,2,21102,37,1,0,1105,1,578,4,382,4,383,204,1,1001,382,1,382,1007,382,44,381,1005,381,22,1001,383,1,383,1007,383,23,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1106,0,161,107,1,392,381,1006,381,161,1101,-1,0,384,1106,0,119,1007,392,42,381,1006,381,161,1102,1,1,384,21001,392,0,1,21102,1,21,2,21102,1,0,3,21102,138,1,0,1105,1,549,1,392,384,392,21001,392,0,1,21101,0,21,2,21102,1,3,3,21101,0,161,0,1106,0,549,1101,0,0,384,20001,388,390,1,20101,0,389,2,21102,1,180,0,1105,1,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,21001,389,0,2,21101,0,205,0,1106,0,393,1002,390,-1,390,1102,1,1,384,20102,1,388,1,20001,389,391,2,21102,1,228,0,1105,1,578,1206,1,261,1208,1,2,381,1006,381,253,20101,0,388,1,20001,389,391,2,21102,1,253,0,1105,1,393,1002,391,-1,391,1101,1,0,384,1005,384,161,20001,388,390,1,20001,389,391,2,21102,1,279,0,1105,1,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,0,304,0,1105,1,393,1002,390,-1,390,1002,391,-1,391,1102,1,1,384,1005,384,161,21001,388,0,1,20102,1,389,2,21102,1,0,3,21101,338,0,0,1105,1,549,1,388,390,388,1,389,391,389,20102,1,388,1,20102,1,389,2,21102,1,4,3,21101,0,365,0,1106,0,549,1007,389,22,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,315,20,18,1,1,22,109,3,22101,0,-2,1,21202,-1,1,2,21102,0,1,3,21101,0,414,0,1106,0,549,22102,1,-2,1,21202,-1,1,2,21101,429,0,0,1106,0,601,1202,1,1,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2105,1,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,21202,-3,1,-7,109,-8,2106,0,0,109,4,1202,-2,44,566,201,-3,566,566,101,639,566,566,2102,1,-1,0,204,-3,204,-2,204,-1,109,-4,2106,0,0,109,3,1202,-1,44,594,201,-2,594,594,101,639,594,594,20101,0,0,-2,109,-3,2106,0,0,109,3,22102,23,-2,1,22201,1,-1,1,21102,1,509,2,21101,264,0,3,21102,1012,1,4,21102,1,630,0,1106,0,456,21201,1,1651,-2,109,-3,2106,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,2,0,0,2,0,2,0,0,2,0,2,0,0,2,2,0,2,0,2,2,0,0,0,0,2,0,0,2,2,2,0,2,0,2,0,2,2,2,0,1,1,0,0,0,2,2,0,0,0,0,2,2,2,0,0,2,0,2,0,0,0,0,2,2,2,2,0,0,2,0,2,2,2,2,0,0,0,2,0,2,0,0,0,1,1,0,2,0,0,0,2,0,2,2,2,0,0,2,0,2,0,0,0,0,2,2,0,0,2,2,0,0,2,0,0,0,0,2,2,0,2,0,0,2,0,0,0,1,1,0,0,2,0,2,2,0,0,0,2,0,2,2,2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,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,78,97,10,89,31,40,53,97,63,60,92,10,54,27,53,42,36,34,79,30,8,70,22,20,18,67,79,30,81,50,67,46,39,15,72,26,35,61,6,36,2,26,65,94,82,27,37,6,71,66,84,19,69,5,62,89,57,49,1,9,59,67,30,74,71,37,66,77,43,4,59,42,85,4,87,1,24,64,85,25,29,67,97,15,22,6,34,97,97,47,22,19,40,89,45,36,93,77,26,85,30,40,65,21,45,91,18,77,45,13,74,18,47,67,79,1,31,22,1,96,94,60,44,56,79,64,74,56,91,79,41,23,9,57,9,86,63,82,55,92,63,63,94,73,76,40,88,18,26,66,29,27,20,1,94,90,43,11,67,33,27,47,34,73,65,67,77,54,92,84,6,29,41,8,8,38,83,36,74,29,26,70,68,57,54,38,75,37,24,64,30,89,43,61,6,4,65,81,39,85,91,22,28,17,47,95,52,40,76,77,81,52,59,19,37,90,23,33,5,82,3,64,46,70,22,24,9,96,97,69,48,66,58,97,51,15,8Line truncated
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
mod tasks;
|
mod tasks;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
tasks::day12::run();
|
tasks::day13::run();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
use super::day05::{IntCodeComputer, RAM};
|
||||||
|
use itertools::Itertools;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn run() {
|
||||||
|
let program: RAM = std::fs::read_to_string("input/day13.txt")
|
||||||
|
.unwrap()
|
||||||
|
.split(",")
|
||||||
|
.map(|it| it.parse::<i128>().unwrap())
|
||||||
|
.enumerate()
|
||||||
|
.collect();
|
||||||
|
task1(program.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
enum FieldType {
|
||||||
|
Empty,
|
||||||
|
Wall,
|
||||||
|
Block,
|
||||||
|
HorizontalPaddle,
|
||||||
|
Ball,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FieldType {
|
||||||
|
fn from(input: i128) -> Self {
|
||||||
|
match input {
|
||||||
|
0 => Self::Empty,
|
||||||
|
1 => Self::Wall,
|
||||||
|
2 => Self::Block,
|
||||||
|
3 => Self::HorizontalPaddle,
|
||||||
|
4 => Self::Ball,
|
||||||
|
_ => unreachable!("unexpected field type {}", input),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn task1(program: RAM) {
|
||||||
|
let mut pc = IntCodeComputer::new(vec![], program);
|
||||||
|
pc.run_until_end();
|
||||||
|
let field = pc.get_output().iter().tuples().fold(
|
||||||
|
HashMap::<(i128, i128), FieldType>::new(),
|
||||||
|
|mut map, (x, y, t)| {
|
||||||
|
map.insert((*x, *y), FieldType::from(*t));
|
||||||
|
map
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let block_count = field
|
||||||
|
.iter()
|
||||||
|
.filter(|(_, ftype)| **ftype == FieldType::Block)
|
||||||
|
.count();
|
||||||
|
println!("Task 1: There are {} blocks in the field", block_count);
|
||||||
|
}
|
||||||
@@ -9,3 +9,4 @@ pub mod day09;
|
|||||||
pub mod day10;
|
pub mod day10;
|
||||||
pub mod day11;
|
pub mod day11;
|
||||||
pub mod day12;
|
pub mod day12;
|
||||||
|
pub mod day13;
|
||||||
Reference in new issue
Block a user