File:  [CSRG BSD Unix] / 43BSDTahoe / new / B / ex / hanoi / 'HANOI
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:58 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43tahoe
BSD 4.3tahoe

HOW'TO HANOI n:
	INITIALISE
	FOR i IN {1..(2**n)-1}:
		SELECT'PROCESS
		WRITE 'Move piece', piece, 'from', from, 'to', to/
		RE'SCHEDULE
INITIALISE:
	PUT {} IN process
	FOR i IN {1..n}:
		INSERT 2**(i-1), i, 1, (-1)**(i+n), 2**i IN process
SELECT'PROCESS:
	PUT min process IN time, piece, from, direction, wait
	REMOVE min process FROM process
RE'SCHEDULE:
	INSERT time+wait, piece, to, direction, wait IN process
to:
	RETURN ((from+direction-1) mod 3) + 1

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.