Last active
August 29, 2015 14:18
-
-
Save corytodd/4269f212de3ea3225f04 to your computer and use it in GitHub Desktop.
Version with some breathing room...
This file contains 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
proc s(x, y, b: var int)= | |
x = x div 2 | |
y = y div 2 | |
b *= 2 | |
proc n(x: var int): int = | |
return -(x+1) | |
proc a(x, y: var int): int = | |
var b = 1 | |
while x > 0 and y > 0: | |
if (x mod 2 + y mod 2) == 2: | |
result += b | |
s(x,y,b) | |
proc o(x, y: var int): int = | |
var b = 1 | |
while x + y > 0: | |
if (x mod 2 + y mod 2) >= 1: | |
result += b | |
s(x,y,b) | |
proc r(x, y: var int): int = | |
var b = 1 | |
while x + y > 0: | |
if (x mod 2 + y mod 2) == 1: | |
result += b | |
s(x,y,b) | |
# Test harness | |
proc test(i,j, exp: int; p: proc; op: string){.procvar.}= | |
var | |
act: int | |
var x = i | |
var y = j | |
act = p(x,y) | |
if(exp != act): | |
echo("Error! ", i, op, j," ", exp," ", act) | |
import threadpool | |
var | |
x, exp, act: int | |
for i in countup(0, 0xffffffff): | |
x = i | |
exp = not x | |
act = n(x) | |
if(exp != act): | |
echo("Error! ~", i) | |
parallel: | |
for j in countup(0,0xffffffff): | |
spawn test(i,j,i and j, a," & ") | |
spawn test(i,j,i or j, o," | ") | |
spawn test(i,j,i xor j, r," ^ ") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added test harness