fork download
  1. ; homework
  2.  
  3. (define (f1 n)
  4. (do ((i 1 (+ i 1))) ((= i (* 2 n)))
  5. (display (if (< n i) (- (* 2 n) i) i)))
  6. (newline))
  7.  
  8. (display (f1 5)) (newline)
  9.  
  10. (define (f2 n)
  11. (do ((i 1 (+ i 1))) ((= n i)) (display i))
  12. (do ((i n (- i 1))) ((= 0 i)) (display i))
  13. (newline))
  14.  
  15. (display (f2 5)) (newline)
  16.  
  17. (define (f3 n)
  18. (define (f n s)
  19. (if (= n 1) (begin (display s) (newline))
  20. (f (- n 1) (string-append (number->string (- n 1)) s (number->string (- n 1))))))
  21. (f n (number->string n)))
  22.  
  23. (display (f3 5)) (newline)
  24.  
  25. (define (f4 n)
  26. (display (case n
  27. ((1) "1")
  28. ((2) "121")
  29. ((3) "12321")
  30. ((4) "1234321")
  31. ((5) "123454321")
  32. ((6) "12345654321")
  33. ((7) "1234567654321")
  34. ((8) "123456787654321")
  35. ((9) "12345678987654321")))
  36. (newline))
  37.  
  38. (display (f4 5)) (newline)
Success #stdin #stdout 0.01s 7856KB
stdin
Standard input is empty
stdout
123454321
#<unspecified>
123454321
#<unspecified>
123454321
#<unspecified>
123454321
#<unspecified>