Add day 4 solutions
This commit is contained in:
14
day4.chpl
Normal file
14
day4.chpl
Normal file
@@ -0,0 +1,14 @@
|
||||
use IO;
|
||||
|
||||
iter pairs() {
|
||||
var low1, low2, high1, high2 : int;
|
||||
while readf("%i-%i,%i-%i", low1, high1, low2, high2) do
|
||||
yield (low1..high1, low2..high2);
|
||||
}
|
||||
|
||||
proc anyContains((r1, r2): 2*range) { return r1.contains(r2) || r2.contains(r1); }
|
||||
proc overlap((r1, r2): 2*range) { return !r1[r2].isEmpty(); }
|
||||
|
||||
var thePairs = pairs();
|
||||
writeln(+ reduce anyContains(thePairs));
|
||||
writeln(+ reduce overlap(thePairs));
|
||||
Reference in New Issue
Block a user