Created
October 7, 2013 00:42
-
-
Save kennycason/6860992 to your computer and use it in GitHub Desktop.
Drop piece in Connect 4 column
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 characters
numEmpty :: [Int] -> Int | |
numEmpty board = length $ filter (\x -> x == 0) board | |
addToColumn :: Int -> [Int] -> [Int] | |
addToColumn val board = xs ++ [val] ++ ys | |
where | |
n = (numEmpty board) | |
xs = replicate (n - 1) 0 | |
ys = snd (splitAt n board) | |
-- simulate dropping a piece into a connect 4 column | |
main = do | |
let board = [0,0,0,0,0,1,-1,1] | |
print board | |
print $ addToColumn 1 board |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment