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.List (sortOn) | |
reorder :: [Char] -> [Int] -> [Char] | |
reorder a b = map fst . sortOn snd $ zip a b | |
a = ['C'..'H'] | |
b = [3, 0, 4, 1, 2, 5] | |
main = putStrLn $ reorder a b |
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
#!/bin/bash | |
tail -n+3 "$0" | gcc -xc - && ./a.out && rm ./a.out ; exit | |
//[2K[2D[A[2K[A[2K | |
#include <stdio.h> | |
int main() { | |
printf("C is a scripting language!\n"); | |
} |
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
Prelude Data.List> numChars s c = foldr (\x acc -> if x == c then acc+1 else acc) 0 s | |
Prelude Data.List> numChars "oh heavens" 'h' | |
2 |
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
*Main> moveZeros [1, 2, 0, 1, 0, 0, 3, 6] | |
[1,2,1,3,6,0,0,0] |
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.List | |
import Data.Ord | |
charNumSort :: [String] -> [String] | |
charNumSort = sortBy ((comparing $ length . nub) `mappend` (comparing $ Down . length)) |
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
/tmp | |
➜ ./a.out | |
0 | |
1 | |
2 | |
1 | |
8 | |
1 | |
32 |
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
/tmp | |
➜ ./a.out | |
0 | |
1 | |
0 | |
1 | |
0 | |
1 |
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
*Main> oneRow ["candy","doodle","pop","shield","lag","typewriter"] | |
["pop","lag","typewriter"] |
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
*Main> maxPointsOnLine [(1,1), (3,2), (5,3), (4,1), (2,3), (1,4)] | |
4 |
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.Monad | |
generateParens :: Int -> [String] | |
generateParens n = generateParens' n "" | |
generateParens' :: Int -> String -> [String] | |
generateParens' n xs | |
| n == o = [xs ++ replicate u ')'] | |
| u == 0 = generateParens' n (xs ++ "(") | |
| otherwise = [xs ++ "(", xs ++ ")"] >>= generateParens' n |
NewerOlder