Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/First-class-environments/D/first-class-environments.d
Normal file
28
Task/First-class-environments/D/first-class-environments.d
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import std.stdio, std.algorithm, std.range, std.array;
|
||||
|
||||
struct Prop {
|
||||
int[string] data;
|
||||
ref opDispatch(string s)() pure nothrow {
|
||||
return data[s];
|
||||
}
|
||||
}
|
||||
|
||||
immutable code = `
|
||||
writef("% 4d", e.seq);
|
||||
if (e.seq != 1) {
|
||||
e.cnt++;
|
||||
e.seq = (e.seq & 1) ? 3 * e.seq + 1 : e.seq / 2;
|
||||
}`;
|
||||
|
||||
void main() {
|
||||
auto envs = 12.iota.map!(i => Prop(["cnt": 0, "seq": i+1])).array;
|
||||
|
||||
while (envs.any!(env => env.seq > 1)) {
|
||||
foreach (e; envs) {
|
||||
mixin(code);
|
||||
}
|
||||
writeln;
|
||||
}
|
||||
|
||||
writefln("Counts:\n%(% 4d%)", envs.map!(env => env.cnt));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue