Last active
December 17, 2020 17:10
-
-
Save sroccaserra/67dbc3a01023eaa111b8678ae5ca1f48 to your computer and use it in GitHub Desktop.
Revisions
-
sroccaserra revised this gist
Dec 17, 2020 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,11 +19,11 @@ type Processed = [Int] type ToProcess = [Int] conway :: ToProcess -> Processed conway ns = recur [] ns recur :: Processed -> ToProcess -> Processed recur ps [] = ps recur ps ts = recur (ps++counted) rest where (counted, rest) = countSameNumbers ts countSameNumbers :: ToProcess -> (Processed,ToProcess) -
sroccaserra revised this gist
Dec 17, 2020 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,9 +22,9 @@ conway :: ToProcess -> Processed conway ns = step [] ns step :: Processed -> ToProcess -> Processed step ps [] = ps step ps ts = step (ps++counted) rest where (counted, rest) = countSameNumbers ts countSameNumbers :: ToProcess -> (Processed,ToProcess) countSameNumbers ns@(n:_) = ([length sameNs, n], rest) -
sroccaserra created this gist
Dec 17, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ module Conway where -- https://fr.wikipedia.org/wiki/Suite_de_Conway -- 1211 -- Il y a trois éléments : -- - la liste déjà traitée, -- - le chiffre en cours de comptage, -- - la liste restant à traiter -- ([],[],[1,2,1,1]) -- ([],[1,1][2,1,1]) -- ([1,1],[1,2],[1,1]) -- ([1,1,1,2],[1,1][1]) -- ([1,1,1,2],[2,1][]) -- ([1,1,1,2,2,1],[][]) type Processed = [Int] type ToProcess = [Int] conway :: ToProcess -> Processed conway ns = step [] ns step :: Processed -> ToProcess -> Processed step as [] = as step as bs = step (as++counted) rest where (counted, rest) = countSameNumbers bs countSameNumbers :: ToProcess -> (Processed,ToProcess) countSameNumbers ns@(n:_) = ([length sameNs, n], rest) where sameNs = takeWhile (== n) ns rest = dropWhile (== n) ns countSameNumbers _ = error "wrong state"