From 2404ee84b44fdd070de6552ae80c87c96e561637 Mon Sep 17 00:00:00 2001 From: Peter Resch Date: Sun, 6 Dec 2020 15:36:26 -0600 Subject: [PATCH] reduce lines of code --- aoc2020/lib/aoc20201203.dart | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) 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; } } }