reduce lines of code

master
Peter Resch 5 years ago
parent 019382a865
commit 2404ee84b4

@ -6,9 +6,9 @@ class AOC20201203 extends AOCBase {
static const tree = '#';
int indexWrap({int index, int width}) => index % width;
int treeTest({int index, String line}) {
var width = line.length;
var testChar = line[indexWrap(index: index, width: width)];
var testChar = line[indexWrap(index: index, width: line.length)];
return testChar == tree ? 1 : 0;
}
@ -34,21 +34,11 @@ class AOC20201203 extends AOCBase {
var filename = (test ?? false) ? classStringTest : classString;
var mylist = await ReadData.readFileString(filename);
var slopes = <Point>[
Point(1, 1),
Point(3, 1),
Point(5, 1),
Point(7, 1),
Point(1, 2),
];
var slopes = <Point>[Point(1, 1), Point(3, 1), Point(5, 1), Point(7, 1), Point(1, 2)];
answerB = 0;
for (var slope in slopes) {
var trees = tobogganRide(hill: mylist, start: Point(0, 0), slope: slope);
if (answerB == 0) {
answerB = trees;
} else {
answerB *= trees;
}
answerB = (answerB == 0) ? trees : answerB * trees;
}
}
}

Loading…
Cancel
Save