Skip to content

Instantly share code, notes, and snippets.

@neizod
Forked from Python1Liners/LICENSE.txt
Created February 21, 2012 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neizod/1872573 to your computer and use it in GitHub Desktop.
Save neizod/1872573 to your computer and use it in GitHub Desktop.
Minimum Scalar Product
min_scalar = '\n'.join('Case #{0}: {2}'.format(test+1, input(), sum(a * b for a, b in zip(sorted(int(v) for v in input().split()), sorted(int(v) for v in input().split())[::-1]))) for test in range(int(input())))

Minimum Scalar Product

According to this Code Jam problem, I try to made it in one line.

min_scalar = '\n'.join(
'Case #{0}: {2}'.format(
test+1,
input(), # from test case, the value describe length has no use in python.
sum(a * b for a, b in zip(
sorted(int(v) for v in input().split()),
sorted(int(v) for v in input().split())[::-1])))
for test in range(int(input())))
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 Nattawut Phetmak <http://about.me/neizod>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "minimum_scalar_product",
"description": "find minimum scalar product of two vector.",
"keywords": [
"math",
"codejam"
]
}
min_scalar = '\n'.join('Case #{0}: {2}'.format(test+1, input(), sum(a * b for a, b in zip(sorted(int(v) for v in input().split()), sorted(int(v) for v in input().split())[::-1]))) for test in range(int(input())))
# stdin:
# 2
# 3
# 1 3 -5
# -2 4 1
# 5
# 1 2 3 4 5
# 1 0 1 0 1
expected = '''Case #1: -25
Case #2: 6'''
print(expected)
print(min_scalar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment