Created
August 10, 2012 17:27
-
-
Save jadudm/3315932 to your computer and use it in GitHub Desktop.
"Chinese Whispers" in occam-pi (no timing)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#INCLUDE "useful.module" | |
VAL INT N IS 100000: | |
PROC whisper (CHAN INT left?, right!) | |
INT v: | |
SEQ | |
left ? v | |
right ! (v + 1) | |
: | |
PROC main (CHAN BYTE kyb?, scr!, err!) | |
SEQ | |
[N+1]CHAN INT whispers: | |
PAR | |
-- The first whisperer | |
whispers[0] ! 1 | |
-- N whisperers | |
PAR i = 0 FOR N | |
whisper (whispers[i]?, whispers[i+1]!) | |
-- The last whisperer | |
INT end: | |
SEQ | |
whispers[N] ? end | |
-- Print the end result. | |
out.int(end, 0, scr!) | |
out.string("*n", 0, scr!) | |
: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment