Skip to content

Commit

Permalink
Improved code according to hlint suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Guryanov committed Mar 12, 2013
1 parent 5446d34 commit e583152
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions 262_B.hs
Expand Up @@ -2,16 +2,16 @@ module Main where

solve :: Int -> [Int] -> [Int] -> Int
solve 0 neg pos = sum neg + sum pos
solve k [] pos = (sum pos) - 2 * (head pos) * (k `mod` 2)
solve k [] pos = sum pos - 2 * head pos * (k `mod` 2)
solve k neg []
| length neg >= k = sum (drop k neg) - sum (take k neg)
| otherwise = -(sum neg) + 2 * (last neg) * ((k - (length neg)) `mod` 2)
| otherwise = -(sum neg) + 2 * last neg * ((k - length neg) `mod` 2)
solve k neg pos
| length neg >= k = sum (drop k neg) + sum pos - sum (take k neg)
| otherwise = if (-(last neg)) > (head pos)
then (sum pos) - (sum neg) - 2 * (head pos) * ((k - (length neg)) `mod` 2)
else (sum pos) - (sum neg) + 2 * (last neg) * ((k - (length neg)) `mod` 2)
| otherwise = if (-(last neg)) > head pos
then sum pos - sum neg - 2 * head pos * ((k - length neg) `mod` 2)
else sum pos - sum neg + 2 * last neg * ((k - length neg) `mod` 2)

main = do
nkStr <- getLine
let [_, k] = map read $ words nkStr
Expand Down
4 changes: 2 additions & 2 deletions 276_B.hs
Expand Up @@ -3,10 +3,10 @@ module Main where
import Data.List

odds :: String -> Int
odds = (foldl (+) 0) . map ((`mod` 2) . length) . group . sort
odds = foldl (+) 0 . map ((`mod` 2) . length) . group . sort

solve :: String -> String
solve str = if odds str == 0 || (odds str) `mod` 2 == 1
solve str = if odds str == 0 || odds str `mod` 2 == 1
then "First"
else "Second"

Expand Down
5 changes: 3 additions & 2 deletions 278_A.hs
@@ -1,10 +1,11 @@
module Main where

import Control.Monad
import Data.List

main = do
distances <- getLine >> getLine >>= (return . map read . words) :: IO [Int]
[s1, s2] <- getLine >>= (return . sort . map read . words) :: IO [Int]
distances <- liftM (map read . words) (getLine >> getLine) :: IO [Int]
[s1, s2] <- liftM (sort . map read . words) getLine:: IO [Int]
let total = sum distances
dist = sum $ drop (s1 - 1) $ take (s2 - 1) distances
print $ min dist (total - dist)

0 comments on commit e583152

Please sign in to comment.