tests/tcl/common/src/ackermann.tcl

#!/usr/local/bin/tclsh
# $Id: ackermann.tcl,v 1.2 2003/12/30 01:25:05 davidw Exp $
# http://www.bagley.org/~doug/shootout/

# Patched for dashot in order to avoid stack overflow (antirez)

# END COMMENT
interp recursionlimit {} 100000

set NUM [lindex $argv 0]
if {$NUM < 1} {
    set NUM 1
}

proc ack {m n} {
    if {$m == 0} {
	return [expr {$n + 1}]
    } elseif {$n == 0} {
	return [ack [expr {$m - 1}] 1]
    } else {
	return [ack [expr {$m - 1}] [ack $m [expr {$n - 1}]]]
    }
}

set ack [ack 3 $NUM]
puts "Ack(3,$NUM): $ack"

Generated by GNU enscript 1.6.3.