aoc2020/day5/part1/main.d

25 lines
537 B
D
Raw Permalink Normal View History

2020-12-08 07:26:29 +01:00
import std;
void main()
{
File("input", "r").byLine.findHighestSeatID.writeln;
}
auto calculateSeatID(const char[] seat)
{
return seat.retro.enumerate.map!(it => "BR".canFind(it.value) ? 2 ^^ it.index : 0).sum;
}
unittest
{
assert("FBFBBFFRLR".calculateSeatID == 357);
assert("BFFFBBFRRR".calculateSeatID == 567);
assert("FFFBBBFRRR".calculateSeatID == 119);
assert("BBFFBBFRLL".calculateSeatID == 820);
}
auto findHighestSeatID(R)(R seats)
{
return seats.map!(seat => seat.calculateSeatID).maxElement;
}