Skip to content

Instantly share code, notes, and snippets.

@Joseph-Bake
Last active July 29, 2017 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Joseph-Bake/2f9cf2781507f3027a3f4482a961f0e9 to your computer and use it in GitHub Desktop.
Save Joseph-Bake/2f9cf2781507f3027a3f4482a961f0e9 to your computer and use it in GitHub Desktop.
ふぃっしゅ数ver.3の展開
type I = Integer
data F3 = S [I] | SS I
instance Show F3 where
show (S x) = show x
show (SS x) = show x
sss :: [F3] -> IO I -> IO I
sss [] x = do
x' <- x
appendFile "fish3.txt" ("リストがない ("++show x'++")\n")
return x'
sss (S []:ns) x =
sss ns x
sss (list@[S [1]]) x = do
x' <- x
let y = 2 * x'
appendFile "fish3.txt" (show list++" ("++show x'++") = "++show y++"\n")
return y
sss (list@(S (1:ns):nss)) x = do
x' <- x
appendFile "fish3.txt" (show list++" ("++show x'++")\n")
appendFile "fish3.txt" "Xn = "
fpow (sss (S ns:nss)) x' (return x')
sss (list@(S (n:ns):nss)) x = do
x' <- x
appendFile "fish3.txt" (show list++" ("++show x'++")\n")
let n'=replicate (fromIntegral x') (n-1)
sss (S (n'++ns):nss) (return x')
sss (list@(SS 1:nss)) x = do
x' <- x
appendFile "fish3.txt" (show list++" ("++show x'++")\n")
sss (S [x']:nss) (return x')
sss (list@(SS n:nss)) x = do
x' <- x
appendFile "fish3.txt" (show list++" ("++show x'++")\n")
let n' = replicate (fromIntegral x') (SS (n-1))
sss (n'++nss) (return x')
fpow :: (a->a) -> I -> (a->a)
fpow f 1 = f
fpow f n = f.fpow f (n-1)
main :: IO I
main = do
writeFile "fish3.txt" ""
let l632 = replicate 63 (SS 2)
sss l632 (return 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment