PASTEBIN
| #1 paste tool since 2002
create new paste
tools
api
archive
faq
PASTEBIN
create new paste
trending pastes
sign up
login
my alerts
my settings
my profile
Don't like ads?
PRO users
don't see any ads ;-)
Public Pastes
Untitled
42 sec ago
Untitled
15 sec ago
Free accounts
26 sec ago
Untitled
23 sec ago
Untitled
26 sec ago
Untitled
28 sec ago
Untitled
34 sec ago
Untitled
36 sec ago
snowbeard
By: a guest on
Aug 13th, 2009
| syntax:
Haskell
| size: 0.26 KB | hits: 212 | expires: Never
download
|
raw
|
embed
|
report abuse
|
print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
josephus
::
Int
->
Int
->
Int
josephus n m
=
josephus
_
helper
[
0
..
(
n
-
1
)
]
m
-
1
where
josephus
_
helper
[
a
]
m'
=
a
josephus
_
helper
(
a:
as
)
m'
|
m'
==
0
=
josephus
_
helper
as
m
-
1
|
otherwise
=
josephus
_
helper
(
as
++
[
a
]
)
m'
-
1
create a
new version
of this paste
RAW Paste Data
josephus :: Int -> Int -> Int josephus n m = josephus_helper [0..(n-1)] m-1 where josephus_helper [a] m' = a josephus_helper (a:as) m' | m' == 0 = josephus_helper as m-1 | otherwise = josephus_helper (as++[a]) m'-1