Skip to content

Commit ef6b4ed

Browse files
committed
Year 2019 Day 13 fix different sized game play area
1 parent 1483baa commit ef6b4ed

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/year2019/day13.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn parse(input: &str) -> Vec<i64> {
1616

1717
pub fn part1(input: &[i64]) -> usize {
1818
let mut computer = Computer::new(input);
19-
let mut tiles = [0; 44 * 20];
19+
let mut tiles = [0; 44 * 22];
2020

2121
loop {
2222
let State::Output(x) = computer.run() else {
@@ -39,7 +39,7 @@ pub fn part2(input: &[i64]) -> i64 {
3939
modified[0] = 2;
4040

4141
let mut computer = Computer::new(&modified);
42-
let mut tiles = [0; 44 * 20];
42+
let mut tiles = [0; 44 * 22];
4343
let mut score = 0;
4444
let mut blocks = score;
4545
let mut ball: i64 = 0;
@@ -97,14 +97,15 @@ fn draw(tiles: &[i64], score: i64, blocks: i64) {
9797
use std::time::Duration;
9898

9999
// Wait until the initial screen is complete
100-
if tiles[879] != 1 {
100+
let paddle = tiles.iter().rposition(|&t| t == 3).unwrap_or(tiles.len());
101+
if tiles[paddle..].iter().filter(|&&t| t == 1).count() < 3 {
101102
return;
102103
}
103104

104105
let s = &mut String::new();
105106
let _ = writeln!(s, "{WHITE}{BOLD}Blocks: {blocks}\tScore: {score} {RESET}");
106107

107-
for y in 0..20 {
108+
for y in 0..22 {
108109
for x in 0..44 {
109110
let _unused = match tiles[44 * y + x] {
110111
0 => write!(s, " "),

0 commit comments

Comments
 (0)