Fairshare between two and more: Difference between revisions
m
→{{header|Haskell}}: Tidied
m (→{{header|Haskell}}: Tidied) |
|||
Line 753:
=={{header|Haskell}}==
<lang haskell>import Data.
import Data.List (intercalate, unfoldr)
import Data.Tuple (swap)
------------- FAIR SHARE BETWEEN TWO AND MORE ------------
thueMorse :: Int -> [Int]
Line 763 ⟶ 765:
baseDigitsSumModBase base n =
mod
( sum $
unfoldr
(unfoldr ((bool Nothing . Just . swap . flip quotRem base) <*> (0 <)) n))▼
( bool Nothing
. Just
. swap
<*> (0 <)
)
n
base
--------------------------- TEST
main :: IO ()
main =
putStrLn $
fTable
( "First 25 fairshare terms
<> "for a given number of players:\n"
▲ show
)
(('[' :) . (++ " ]") . intercalate "," . fmap (justifyRight 2 ' ' . show))▼
[2, 3, 5, 11]▼
. fmap (show)
)
(take 25 . thueMorse)
▲ [2, 3, 5, 11]
------------------------- DISPLAY
fTable ::
String ->
(a -> String) ->
(b -> String) ->
(a -> b) ->
[a] ->
String
fTable s xShow fxShow f xs =
unlines $
s :
fmap
<*> ((" -> " <>) . fxShow . f)
)
xs
where
w = maximum (length . xShow <$> xs)
justifyRight :: Int ->
justifyRight n c = (drop . length) <*> (replicate n c
{{Out}}
<pre>First 25 fairshare terms for a given number of players:
2 -> [
3 -> [
5 -> [
11 -> [
=={{header|J}}==
|