Skip to content

Instantly share code, notes, and snippets.

@dtak1114
Created April 13, 2013 07:48
Show Gist options
  • Save dtak1114/5377508 to your computer and use it in GitHub Desktop.
Save dtak1114/5377508 to your computer and use it in GitHub Desktop.
#include "stdio.h"
#include "time.h"
int main(int argc, char const *argv[])
{
clock_t t1, t2;
t1 = clock();
tarai(13,5,0);
t2 = clock();
printf("finished in %d ms\n",(int)(t2-t1));
return 0;
}
int tarai(int x,int y,int z){
if (x <= y){
return y;
}else{
tarai(
tarai(x-1,y,z),
tarai(y-1,z,x),
tarai(z-1,x,y)
);
}
}
t1 = Time.now
def tarai(x, y, z)
if x <= y
return y
else
tarai(tarai(x-1,y,z),tarai(y-1,z,x),tarai(z-1,x,y))
end
end
tarai(13,5,0)
puts (Time.now - t1) + 'sec'
(define (tarai x y z)
(if (<= x y)
y
(tarai
(tarai (- x 1) y z)
(tarai (- y 1) z x)
(tarai (- z 1) x y))))
(print (time (tarai 13 5 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment