Advertisement
Guest User

Untitled

a guest
May 2nd, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. (use srfi-1 numbers)
  2. (define (fizzbuzz n)
  3. (cond ((= (remainder n 15) 0) "FizzBuzz\\n")
  4. ((= (remainder n 5) 0) "Buzz\\n")
  5. ((= (remainder n 3) 0) "Fizz\\n")
  6. (else "%d\\n")))
  7. (with-output-to-file
  8. "fizzbuzz.c"
  9. (lambda ()
  10. (display "
  11. #include <stdio.h>
  12. #include <string.h>
  13. char * precomp[] = {
  14. ")
  15. (for-each (lambda (e) (printf "\"~A\", " (fizzbuzz e))) (iota 15))
  16. (display "NULL };")
  17. (display "
  18. int main(int argc, char ** argv) {
  19. if(argc != 2)
  20. return -1;
  21. unsigned long long m;
  22. sscanf(argv[1], \"%llu\", &m);
  23. unsigned long long mp = m - 15;
  24. unsigned long long x = 0;
  25. while(x < mp) {
  26. unsigned long long tmp = x;
  27. ")
  28. (for-each (lambda (e) (printf "printf(precomp[~A],tmp++);\n" e)) (iota 15))
  29. (display "
  30. x+=15;
  31. }
  32. int i = 0;
  33. while(x < m) {
  34. printf(precomp[i],x);
  35. ++i; ++x;
  36. }
  37. }
  38. ")))
  39. (system "gcc -o fizzbuzz fizzbuzz.c -O3 -march=native -std=c11")
  40. (system (sprintf "./fizzbuzz ~A" (- (expt 2 64) 1)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement