comparison 2017/day04/app.d @ 33:bc652fa0a645

Move all solutions to per-day subdirs
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Tue, 09 Jan 2018 21:50:37 -0500
parents 2017/day04.d@c7b6dfd6eba6
children
comparison
equal deleted inserted replaced
32:763c88851b91 33:bc652fa0a645
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 }