Greetings!! Here's a series of Cold Golf problems and solutions in Python as a part of 21 days of Code | Code Golf by Skillenza 
https://skillenza.com/challenge/21days-of-code

DAY - I


A Little Complex

Given n complex numbers each x + yi, where x is the real part and y is the imaginary part, find their product.

Input Format

The first line of input consists of an integer t denoting the number of test cases. t test cases follow. The first line of each test case consists of an integer n denoting the number of complex numbers. Following n lines of the test case consists of two integers x and y separated by a space denoting x + yi.

Output Format

For each test case, output the product of the complex numbers. Each product is in the form p and q space separated denoting p + qi.

Sample Input

4
3
0 1
2 3
4 5
2
1 0
0 1                                                                           
4
9 -3
0 10
-10 5
4 -4
3
-2 -6
0 0
-4 -2

Sample Output

-22 -7
0 1
-6000 0
0 0

Explanation

(2 + 3i)(4 + 5i) = 2*4 + 2*5i + 3i*4 + 3i*5i = 8 + 10i + 12i - 15 = -7 + 22i

Note

i^2 = -1 (where ^ denotes raised to the power).
Complex number multiplication is both commutative and associative.
For any two complex numbers z1 and z2, z1z2 = z2z1
For any three complex numbers z1, z2 and z3, we have (z1z2)z3 = z1(z2z3)

Constraints

1 <= t <= 10000
2 <= n <= 10
-10 <= a,b <= 10

Environment and Scoring

Read from STDIN and write to STDOUT.
This is a Code Golf contest where smaller source awards higher score. Score is calculated by the following formula
(1 - s/10000) *100
where s is the number of bytes in your source.
For e.g. if a correct source uses 1000 bytes, a score of (1 - 1000/10000) *100 i.e. 90 will be awarded. The source size limit in bytes is 10000.
Please check the sample programs below which print the sum of two numbers received as input


CODE:

  1. z=input  
  2. b=int  
  3. for _ in[0]*b(z()):  
  4.  p=1+0j  
  5.  for i in[0]*b(z()):p*=complex(*map(b,z().split()))  
  6.  print(b(p.real),b(p.imag))  

RESULT

Exit Code
0
Passed
true
Memory
5572kb
Time
0.16s
Total (out of 1)
0.9879

1

View comments

Popular Posts
Popular Posts
print ("About Me")
print ("About Me")
My Photo
HYDERABAD, Telangana, India
Blog.History(All)
Labels
Total Pageviews
Total Pageviews
21466
About Me
About Me
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.