warning: pointer not aligned at address
Andrew Edwards via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Apr 11 19:11:19 PDT 2017
Conveniently the site is down immediately after I posted that so
here is the code to which I was referring:
import std.stdio, std.algorithm, std.range;
enum DoorState : bool { closed, open }
alias Doors = DoorState[];
Doors flipUnoptimized(Doors doors) pure nothrow {
doors[] = DoorState.closed;
foreach (immutable i; 0 .. doors.length)
for (ulong j = i; j < doors.length; j += i + 1)
if (doors[j] == DoorState.open)
doors[j] = DoorState.closed;
else
doors[j] = DoorState.open;
return doors;
}
Doors flipOptimized(Doors doors) pure nothrow {
doors[] = DoorState.closed;
for (int i = 1; i ^^ 2 <= doors.length; i++)
doors[i ^^ 2 - 1] = DoorState.open;
return doors;
}
void main() {
auto doors = new Doors(100);
foreach (const open; [doors.dup.flipUnoptimized,
doors.dup.flipOptimized])
iota(1, open.length + 1).filter!(i => open[i -
1]).writeln;
}
More information about the Digitalmars-d-learn
mailing list