Skip to content

Instantly share code, notes, and snippets.

@nobsun
Created August 9, 2012 02:17
Show Gist options
  • Save nobsun/3300354 to your computer and use it in GitHub Desktop.
Save nobsun/3300354 to your computer and use it in GitHub Desktop.
generic FizzBuzz
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