Skip to content

Instantly share code, notes, and snippets.

@danking
Created April 17, 2012 19:39
Show Gist options
  • Select an option

  • Save danking/2408499 to your computer and use it in GitHub Desktop.

Select an option

Save danking/2408499 to your computer and use it in GitHub Desktop.
Hyperoperators
#lang racket
(provide (all-defined-out))
(define (hyper n)
(cond
;; [(= n 0) add1]
[(= n 1) +]
[(= n 2) *]
[else (lambda (base r)
(foldl (hyper (sub1 n))
1
(make-list r base)))]))
(equal? ((hyper 1) 2 3) 5)
(equal? ((hyper 2) 2 3) 6)
(equal? ((hyper 3) 2 3) 8)
(equal? ((hyper 4) 2 3) 16) ; 2 ^ (2 ^ 2)
(equal? ((hyper 4) 2 4) 65536)
(equal? ((hyper 5) 2 0) 1)
(equal? ((hyper 5) 2 1) 2)
(equal? ((hyper 5) 2 2) 4)
(equal? ((hyper 5) 2 3) 65536)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment