Advent of Code 2020 - Day 3

preview_player
Показать описание
We solve todays challenge at the advent of code 2020. Come join and have some fun.

Git repository:

Unlock unlimited opportunities with 50% off your first month of Coursera Plus

Get on the fast track to a career in cybersecurity. In this certificate program, you'll learn in-demand skills, and get AI training from Google experts. Learn at your own pace, no degree or experience required.

Join the channel to get access to more perks:

Or visit my blog at:

Outro music: Sanaas Scylla

#aoc2020 #adventofcode #java
Рекомендации по теме
Комментарии
Автор

I didn't flatten my input map (nor convert to ints, but I think that's more of a style choice). Using a 2D map (list of strings or list of list of chars/int), I think the indexing becomes easier. Probably the problem is in the horizontal mapping. As StartElec said, with a 2D map it becomes a fairly simple modulo calculation.

aaronperl
Автор

Hello Daniel ! Excellent video, again.
I think horizontal movement should be understood as a modulo. Maybe the error is there. I don't know...

ZobiLaMoucheLeRetour
Автор

Since I'm curious, I modified your code to show what I mean :
public class Forest {
private int posx = 0;
private int posy = 0;
private final int maxx;
private final int maxy;
private List<String> inputs;

public Forest(List<String> inputs) throws Exception {
if(inputs.isEmpty()) throw new Exception("NO MAP!!");
maxx = inputs.get(0).length();
maxy = inputs.size();
this.inputs = inputs;
}

public boolean move(int x, int y) {
posx += x;
posy += y;
return posy < maxy;
}

public boolean hasTree() {
return inputs.get(posy).charAt(posx % maxx) == '#';
}
}

Maybe this work, i don't know, i do not have Advent Of Code account to test.

ZobiLaMoucheLeRetour