From d285938df257f8adbd15eb4fced13cd11ceaa9ed Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Tue, 17 Apr 2018 12:03:44 -0500 Subject: [PATCH 1/5] add 2048 --- 2048.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 2048.hs diff --git a/2048.hs b/2048.hs new file mode 100644 index 0000000..c407a26 --- /dev/null +++ b/2048.hs @@ -0,0 +1,10 @@ +update :: [[Int]] -> Int -> IO () +update board move = + +main = do + r1 <- getLine + r2 <- getLine + r3 <- getLine + r4 <- getLine + move <- readLn + update [r1, r2, r3, r4] (read move) From 6504b062a32ed31ee1a5b5e3f0420310d1251d49 Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Tue, 17 Apr 2018 12:03:56 -0500 Subject: [PATCH 2/5] add a1paper --- a1paper.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 a1paper.py diff --git a/a1paper.py b/a1paper.py new file mode 100644 index 0000000..90be0b7 --- /dev/null +++ b/a1paper.py @@ -0,0 +1,24 @@ +def gen_layout(a_n, fake_quant_a_n, layout): + if a_n == 1: + return (fake_quant_a_n, layout) + fake_quant_a_nm1 = papers[a_n] // 2 + fake_quant_a_nm1 += fake_quant_a_n // 2 + layout = [fake_quant_a_nm1 * 2].extend(layout) + return gen_layout(a_n - 1, fake_quant_a_nm1, layout) + +n = int(input()) +papers = [0, 0] +for paper_quantity in map(int, input().split()): + papers.append(paper_quantity) + +#total_area = sum(map(lambda p: p[1] * (0.5 / 2**(p[0] - 1)), enumerate(papers))) +#print(total_area) +#if total_area < 0.5: +# print("impossible") +# sys.exit(0) + +(a1s, layout) = gen_layout(n, papers[-1], []) +if a1s == 0: + print("impossible") +else: + print(a1s, "layout:", layout) From 17cb1404592f8e9f4e2fbf756aeb0aa10ff55b5e Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Tue, 17 Apr 2018 12:04:08 -0500 Subject: [PATCH 3/5] add karte --- karte.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 karte.hs diff --git a/karte.hs b/karte.hs new file mode 100644 index 0000000..af996bb --- /dev/null +++ b/karte.hs @@ -0,0 +1,14 @@ +multiSplit :: (a -> Bool) -> [a] -> [[a]] +multiSplit _ [] sublist = sublist +multiSplit f (x:xs) sublist + | f x = sublist ++ multiSplit f xs [x] + | otherwise = multiSplit f xs (sublist ++ [x]) + +main = do + line <- getLine + let cards = groupBy (!! 0) . filter (not null) . multiSplit isAlpha line [] + [p, k, h, t] = map (\g -> 13 - length g) cards + if length g > length $ nub g then + putStrLn "GRESKA" + else + print From bc4c0393a06759394409d6f470270059a544f8e7 Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Tue, 17 Apr 2018 12:04:22 -0500 Subject: [PATCH 4/5] add peragrams --- peragrams.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 peragrams.hs diff --git a/peragrams.hs b/peragrams.hs new file mode 100644 index 0000000..3f0cbff --- /dev/null +++ b/peragrams.hs @@ -0,0 +1,32 @@ +import Data.List +import qualified Data.Map.Lazy as Map + +isPalindrome :: String -> Bool +isPalindrome "" = True +isPalindrome (_:"") = True +isPalindrome (first:rest) = + -- 1. is the first character equal to the last, and + -- 2. is the middle of the string a palindrome + first == last rest && (isPalindrome $ init rest) + +isAnagramOf :: String -> String -> Bool +isAnagramOf anagram s = + -- tally the number of occurences of each character in `anagram` and compare + -- to that of `s` + charTally anagram == charTally s + where charTally s = foldl folder Map.empty s + folder map k = Map.insert k ((Map.findWithDefault 0 k map) + 1) map + +isPeragram :: String -> Bool +isPeragram s = + -- FIXME: generating all permutations is abysmally slow + let palindromes = [p | p <- permutations s, isPalindrome p] in + not . null $ palindromes + +minDeleteBecomePeragram :: String -> Int +minDeleteBecomePeragram s + | isPalindrome s = 0 + | otherwise = error "non-palindromes are unimplemented" + +main :: IO () +main = interact (show . minDeleteBecomePeragram) From f0ebbc09fbdb4ec4cb6a56fb4865e5bd97eb4231 Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Thu, 19 Apr 2018 13:56:59 -0500 Subject: [PATCH 5/5] Update peragrams.hs --- peragrams.hs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/peragrams.hs b/peragrams.hs index 3f0cbff..254aae3 100644 --- a/peragrams.hs +++ b/peragrams.hs @@ -1,6 +1,10 @@ import Data.List import qualified Data.Map.Lazy as Map +charTally :: String -> Map.Map Char Int +charTally s = foldl folder Map.empty s + where folder map k = Map.insert k ((Map.findWithDefault 0 k map) + 1) map + isPalindrome :: String -> Bool isPalindrome "" = True isPalindrome (_:"") = True @@ -14,14 +18,9 @@ isAnagramOf anagram s = -- tally the number of occurences of each character in `anagram` and compare -- to that of `s` charTally anagram == charTally s - where charTally s = foldl folder Map.empty s - folder map k = Map.insert k ((Map.findWithDefault 0 k map) + 1) map isPeragram :: String -> Bool -isPeragram s = - -- FIXME: generating all permutations is abysmally slow - let palindromes = [p | p <- permutations s, isPalindrome p] in - not . null $ palindromes +isPeragram s = not . Map.null $ Map.filter (\v -> v > 1 && isOdd) (charTally s) minDeleteBecomePeragram :: String -> Int minDeleteBecomePeragram s