100 doors
Unoptimized
1
var doors = []
2
3
{ |pass|
4
{ |i|
5
if (pass `divides` i) {
6
doors[i] := false -> not!
7
}
8
} << 1..100
9
} << 1..100
10
11
{ |i|
12
say ("Door %3d is %s" % (i, doors[i] ? 'open' : 'closed'))
13
} << 1..100
Copied!
Optimized
1
{ |i|
2
"Door %3d is %s\n".printf(i, <closed open>[i.is_sqr])
3
} << 1..100
Copied!
Last modified 1yr ago
Copy link