Ad
Code
Diff
  • #lang racket
    
    (provide factorial)
    
    (define (factorial n)
      (apply * (range 2 (add1 n))))
    
    • #lang racket
    • (provide factorial)
    • (define (factorial n)
    • (if (<= n 1)
    • 1
    • (* n (factorial (sub1 n)))))
    • (apply * (range 2 (add1 n))))
Code
Diff
  • def sum(arr):
        if not arr:
            return 0
        return arr[0] + sum(arr[1:])
    • def sum(arr):
    • result = 0
    • for i in arr:
    • result += i
    • return result
    • if not arr:
    • return 0
    • return arr[0] + sum(arr[1:])