Created
March 16, 2012 18:27
-
-
Save dradtke/2051679 to your computer and use it in GitHub Desktop.
Partial Haskell solution for Minimum Scalar Product
This file contains hidden or 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
| {- | |
| - Problem URL: http://code.google.com/codejam/contest/32016/dashboard#s=p0 | |
| - | |
| - solve takes as input a list of strings for a particular case | |
| - and returns a string representation of its solution. | |
| -} | |
| solve :: [String] -> String | |
| solve input = show $ minimum options | |
| where (l1:l2:l3:_) = input | |
| n = read l1 :: Int | |
| v1 = parseVector l2 n | |
| v2 = parseVector l3 n | |
| pairs = [(a,b) | a <- permutations v1, b <- permutations v2] | |
| options = map scalar pairs | |
| parseVector :: String -> Int -> [Int] | |
| parseVector line n = map read $ take n $ (words line) :: [Int] | |
| scalar :: ([Int],[Int]) -> Int | |
| scalar (v1,v2) = sum $ zipWith (*) v1 v2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment