Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 2048.hs
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 24 additions & 0 deletions a1paper.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions karte.hs
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions peragrams.hs
Original file line number Diff line number Diff line change
@@ -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)