comparison 2017/day04.d @ 4:c7b6dfd6eba6

day 4
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Thu, 07 Dec 2017 11:44:52 -0500
parents
children
comparison
equal deleted inserted replaced
3:b5533de6ff5b 4:c7b6dfd6eba6
1 import std.stdio;
2 import std.algorithm: filter, map, sort;
3 import std.array: array;
4 import std.string: split;
5 import std.conv: to;
6
7 auto allUnique(string[] arr) {
8 bool[string] counter;
9 foreach(elt; arr) {
10 auto key = to!string(sort(elt.array));
11 counter[key] = true;
12 }
13 return counter.length == arr.length;
14 }
15
16 auto countUnique(string[][] passphrases) {
17 return passphrases.filter!(allUnique).array.length;
18 }
19
20 void main(string[] args) {
21 auto passphrases =
22 File(args[1])
23 .byLineCopy
24 .map!(split)
25 .array;
26 writeln(countUnique(passphrases));
27 }