Smap
SmapIE
New program
Curry
Prolog
Haskell
Open program by ID
Browser
Dashboard
Programs on Smap
Most recent
Most favorited
Tags on Smap
All tags
Sign in
Help
Source code
Language:
Curry
-- http://jaced.com/2005/05/31/the-u2-riddle/ data U2 = Adam | Bono | Edge | Larry pace Adam = 5 pace Bono = 1 pace Edge = 2 pace Larry = 10 -- 1. people on starting side -- 2. people on ending side (for convenience) -- 3. flash light on starting side -- 4. remaining time data State = State [U2] [U2] Bool Int initial = State [Adam, Bono, Edge, Larry] [] True 17 move :: State -> State -- start to end move (State (a++[x]++b++[y]++c) z True t) | nt >= 0 = State (a++b++c) (x:y:z) False nt where nt = t - max (pace x) (pace y) -- end to start move (State xs (a++[x]++b) False t) | nt >= 0 = State (x:xs) (a++b) True nt where nt = t - pace x -- if p:ps is a path and q=move p, then q:p:ps is a path type Path = [State] extend :: Path -> Path extend a@(State [] _ _ _ : _) = reverse a extend a@(b@(State (_:_) _ _ _) : _) = extend (move b : a) main = extend [initial]
Execution result
No execution result yet.
PAKCS 3.7 /all-values
PAKCS 3.7 /one-value
KiCS2 3.1 /all-values
KiCS2 3.1 /one-value
Reset
Clear
Options
New Curry program
Reload program 70
View in Browser
Program ID:
70
Title:
The U2 riddle
Language:
Curry
Author:
antoy
Version:
1
Program information