Created
August 9, 2012 02:17
-
-
Save nobsun/3300354 to your computer and use it in GitHub Desktop.
generic FizzBuzz
This file contains 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 characters
module GFizzBuzz (gFizzBuzz) where | |
import Data.List | |
gFizzBuzz :: (Int,Int) -- range | |
-> [(Int,String)] -- spec of fizzbuzz | |
-> [String] -- generic FizzBuzz strings | |
gFizzBuzz r = narrow r . zipWith (#) [0..] . map concat . transpose . map gfizzs | |
gfizzs :: (Int,String) -> [String] | |
gfizzs (n,s) = cycle $ take n $ s:repeat "" | |
(#) :: Int -> String -> String | |
(#) n "" = show n | |
(#) _ ss = ss | |
narrow :: (Int,Int) -> [String] -> [String] | |
narrow (f,t) = drop f . take (t+1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment