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
{- | |
A program searching for solutions of a board puzzle | |
given by a friend. | |
The aim is to fill in a 8 by 8 square using the | |
given 8 pieces. Each piece has a particular shape and | |
can be rotated and flipped. | |
I am not satisfied with this program yet. The program |
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
{- | |
Richard Bird's quick algorithm for generating prime numbers. | |
Note that the usual "one-liner" Haskell definition of the | |
sieve is not an honest implementation of the sieve of Eratosthenes. | |
The following algorithm by Bird is a more faithful implementation | |
that is not asymptotically the best, but practically | |
fast enough. Further more, we can reuse the "union" function. | |
For more info see: Melissa E. O’Neill, The genuine sieve of |
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
import Control.Arrow ((&&&)) | |
import Data.String (unlines) | |
import Data.List (unfoldr,foldl') | |
histogram :: [Int] -> String | |
histogram = graph . histo | |
histo :: [Int] -> [Int] | |
histo = foldl' oplus [0,0,0,0,0,0,0,0,0,0] | |
where oplus xs i = zipWith ($) (replicate i id ++ [(1+)] ++ repeat id) xs |
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
import Data.Ord | |
import Data.List | |
nubSimple :: [Int] -> [Int] | |
nubSimple = map head . group . sort | |
nubStable :: [Int] -> [Int] | |
nubStable = map fst . sortBy (comparing snd). map head . | |
groupBy ((. fst).(==).fst) . sort . flip zip [0..] |