feature-random #1

Merged
bombinans merged 6 commits from feature-random into main 2025-12-24 03:23:53 +00:00
2 changed files with 30 additions and 22 deletions
Showing only changes of commit 3d80a6847d - Show all commits

View File

@ -18,21 +18,24 @@ ordinals = [
"twelfth"
]
signatures :: [ ( Int, Int, Int, Int) ]
signatures :: [ ( Int, Int, Int) ]
signatures = [
( 3, 6, 5, 0 ),
( 5, 6, 4, 1 ),
( 4, 7, 5, 1 ),
( 4, 4, 5, 5 ),
( 3, 5, 8, 8 ),
( 5, 5, 10, 5 ),
( 5, 5, 9, 20 ),
( 4, 6, 7, 10 ),
( 3, 5, 9, 23 ),
( 6, 6, 6, 3 ),
( 6, 8, 8, 3 )
( 3, 6, 5 ),
( 5, 6, 4 ),
( 4, 7, 5 ),
( 4, 4, 5 ),
( 3, 5, 8 ),
( 5, 5, 10 ),
( 5, 5, 9 ),
( 4, 6, 7 ),
( 3, 5, 9 ),
( 6, 6, 6 ),
( 6, 8, 8 )
]
offsets :: [ Int ]
offsets = [ 0, 1, 1, 5, 8, 5, 20, 10, 23, 3, 3 ]
cardinals :: [ String ]
cardinals = [
"Two",
@ -90,17 +93,17 @@ matchGifts ( i, j, k ) = filter match gifts
giftStr :: ( String, String, String ) -> String
giftStr (c, a, b) = c ++ " " ++ a ++ " " ++ b
wrapGift :: ( Int, Int, Int ) -> [ String ]
wrapGift (i, j, k) = map giftStr $ matchGifts (i, j, k)
wrapGifts :: ( Int, Int, Int ) -> [ String ]
wrapGifts (i, j, k) = map giftStr $ matchGifts (i, j, k)
allGifts :: [ [ String ] ]
allGifts map wrapGift $ reverse signatures
allGifts = map wrapGifts $ reverse signatures
tuples :: [ ( String, String ) ]
tuples = zip (reverse ordinals) allGifts
-- tuples :: [ ( String, String ) ]
-- tuples = zip (reverse ordinals) allGifts
concatLines :: [ String ] -> String
@ -125,16 +128,20 @@ recurseVerse (t:ts) = [ (makeVerse ord gs) ] ++ (recurseVerse ts)
randomOffsets :: StdGen -> [ String ]
randomOffsets gen gsets = map (\gs -> mod rs (length gs)) gsets
where rs = take (length gsets) . unfoldr (Just . random)
randomOffsets :: StdGen -> [ [ String ] ] -> [ Int ]
randomOffsets gen gsets = map (\t -> mod (fst t) (length (snd t))) ts
where rs = randomInts gen (length gsets)
ts = zip rs gsets
randomInts :: StdGen -> Int -> [ Int ]
randomInts gen n = take n $ randoms gen
main :: IO ()
main = do
gen <- newStdGen
let offsets = randomOffsets gen allGifts
print offsets
print allGifts
-- putStrLn $ foldr (\a b -> a ++ "\n\n" ++ b) "" $ reverse $ recurseVerse tuples

View File

@ -21,6 +21,7 @@ description: Please see the README on GitHub at <https://github.com/gith
dependencies:
- base >= 4.7 && < 5
- random
ghc-options:
- -Wall