Created
July 20, 2012 18:09
-
-
Save Idorobots/3152336 to your computer and use it in GitHub Desktop.
Complex Loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto random = randomStuff(); // Implemented elswhere. ;) | |
auto result = mixin(Loope!q{ | |
initially $$ writeln("Loop test:"); $$ | |
with isEven = $$ (uint x) => ((x&1) == 0) $$ | |
with updateAnalysis = $$ // A D function analysing our data. | |
(uint[] stats) { | |
static count = 0; | |
if(count++ % 10 == 0) | |
writeln("Analysis: ", stats); | |
} $$ | |
with max = 500 | |
with data = $$ // Yo dawg... | |
mixin(Loope!q{ | |
for i from 0.0 to max by 1.337 | |
collect i | |
}); $$ | |
for i from 0 to max | |
for datum in data | |
for r in $$ sort(random) $$ | |
if $$ isEven(i) $$ | |
minimize i into minEven and | |
maximize i into maxEven and | |
unless $$ i % 4 == 0 $$ | |
sum i into evenNotFoursTotal and | |
collect datum into floats | |
end | |
and sum i into evenTotal | |
else | |
minimize i into minOdd and | |
maximize i into maxOdd and | |
when $$ i % 5 == 0 $$ | |
sum i into fivesTotal and | |
collect r into randoms | |
end | |
and sum i into oddTotal | |
do $$ updateAnalysis([minEven, maxEven, minOdd, | |
maxOdd, evenTotal, oddTotal, | |
evenNotFoursTotal]) $$ | |
finally $$ writeln("Floats: ", floats); $$ | |
finally $$ writeln("Randoms: ", randoms); $$ | |
finally $$ return [minEven, maxEven, minOdd, | |
maxOdd, evenTotal, oddTotal, | |
evenNotFoursTotal]; $$ | |
}); | |
writeln("Result: ", result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment