File: hyper.scm

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (18 lines) | stat: -rw-r--r-- 528 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2009
; Placed in the Public Domain
;
; (hyper integer1 integer2 integer3)  ==>  integer
;
; Compute A hyper(N) B, where N=INTEGER1, A=INTEGER2, and B=INTEGER3.
;
; Example:   (hyper 4 3 3)  ==>  7625597484987

(define (hyper n a b)
  (cond ((= n 0) (+ 1 b))
        ((= n 1) (+ a b))
        ((= b 1) a)
        ((= n 2) (* a b))
        ((= n 3) (expt a b))
        ((= n 4) (expt a (hyper n a (- b 1))))
        ((> n 4) (hyper (- n 1) a (hyper n a (- b 1))))))