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) 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) 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 diff --git a/peragrams.hs b/peragrams.hs new file mode 100644 index 0000000..254aae3 --- /dev/null +++ b/peragrams.hs @@ -0,0 +1,31 @@ +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 +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 + +isPeragram :: String -> Bool +isPeragram s = not . Map.null $ Map.filter (\v -> v > 1 && isOdd) (charTally s) + +minDeleteBecomePeragram :: String -> Int +minDeleteBecomePeragram s + | isPalindrome s = 0 + | otherwise = error "non-palindromes are unimplemented" + +main :: IO () +main = interact (show . minDeleteBecomePeragram)