diff --git a/aoc2020/lib/aoc20201203.dart b/aoc2020/lib/aoc20201203.dart index 38066ce..9ee841e 100644 --- a/aoc2020/lib/aoc20201203.dart +++ b/aoc2020/lib/aoc20201203.dart @@ -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(1, 1), - Point(3, 1), - Point(5, 1), - Point(7, 1), - Point(1, 2), - ]; + var slopes = [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; } } }