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

Loading…
Cancel
Save