A bishop is placed at center (0,0,0) of a 3 dimensional cubical chess board.

A rook is placed at various x,y,z positions in the cube.

Can the bishop take the rook?

Return True or False

Examples:

rook at (2,2,2) returns True,

(-1,-1,-1) returns true,

(2,2,0) returns True,

(8,1,0) returns False,

Notes:

Bishop can move diagonal in xy plane, xz plane, and yz plane as well as along the diagonals of the cube from corner to corner

```
def bishop_move_3d(p):
if p[0]==p[1]==p[2]:
return True
if p[0]==p[1] and p[2]==0:
return True
if p[0]==p[2] and p[1]==0:
return True
if p[2]==p[1] and p[0]==0:
return True
return False
```

```
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(bishop_move_3d((2,2,2)), True)
test.assert_equals(bishop_move_3d((2,2,0)), True)
test.assert_equals(bishop_move_3d((0,1,1)), True)
test.assert_equals(bishop_move_3d((2,0,2)), True)
test.assert_equals(bishop_move_3d((-1,-1,-1)), True)
test.assert_equals(bishop_move_3d((2,5,6)), False)
test.assert_equals(bishop_move_3d((2,2,0)), True)
test.assert_equals(bishop_move_3d((0,1,1)), True)
test.assert_equals(bishop_move_3d((8,1,0)), False)
test.assert_equals(bishop_move_3d((-1,-1,-1)), True)
```

You are collecting data that fits a wave signal. Your must determine witch mathematical expression fits the signal.

You will receive an array of four numbers into your function called find_signal()

The numbers will obey one of these expressions:

y = sin x,

y = cos x,

y = sin x + cos x

The given y values will always correspond to x input values of 0,1,2,3

Your function will identify which signal is coming in and return string: 'sin x', 'cos x' or sin x + cos x

If no match return None

Important: The given data is rounded to 2 decimal places so always round your calculations likewise to get the correct answer

```
import math as m
def find_signal(s):
k=0; k1=0; k2=0
for i in range(4):
if s[i]==round(m.sin(i),2):
k=k+1
if k==4:
return('sin x')
if s[i]==round(m.cos(i),2):
k1=k1+1
if k1==4:
return('cos x')
if s[i]==round(m.cos(i)+m.sin(i),2):
k2=k2+1
if k2==4:
return('sin x + cos x')
```

```
import codewars_test as test
# TODO Write tests
from solution import find_signal # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(find_signal([0,.84,.91,.14]),'sin x')
test.assert_equals(find_signal([1,.54,-.42,-.99]),'cos x')
test.assert_equals(find_signal([1,1.38,.49,-.85]),'sin x + cos x')
test.assert_equals(find_signal([0,.84,.91,.14]),'sin x')
test.assert_equals(find_signal([0,.84,.91,.14]),'sin x')
test.assert_equals(find_signal([1,.54,-.42,-.99]),'cos x')
test.assert_equals(find_signal([1,1.38,.49,-.85]),'sin x + cos x')
test.assert_equals(find_signal([0,0,0,.14]),None)
```

Train station A is occupied by 1000 people on any given day. The same for Train station B.

A train of 100 people runs each day from station A to B.

One person at station A spreads a virus. Assume the virus doubles each day. Assume the same percentage of infected people from station A ride the train to station B each day. How many days until station B is fully infected?

Assume the train always brings 100 people of which the same percentage from A is infected. And B population stays at 1000 as well as A.

```
def virus_train():
va=1 ;vb=0
for day in range(30):
va=va*2
vafraction=va/1000
ntrain=(vafraction*100)
vb=vb+ntrain
vb=vb*2
if vb >= 1000:
return(day)
```

```
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(virus_train(),9)
```

In a classroom of students a virus begins to spread from point x,y in a 20x20 grid of desks.

Assume that each day the virus spreads to all students sitting diagonal to the present carrier.

0000000000

000X0X0000

0000X00000

000X0X0000

0000000000

How many days will it take the virus to reach across the room to the farthest wall?

You will be given an x,y starting point in a 20x20 grid. Return n, the number of days it takes to reach the farthest wall.

example:

given (10,10) returns 10

(7,0) returns 13

Notes: The first corner desk is taken as desk 1,1 not 0,0

```
def classroom_virus(p):
#if virus starts less than half way count forwards
if p[0]<=10 or p[1]<=10:
for n in range(1,20):
p[0]+=1
p[1]+=1
if p[0] == 20 or p[1]==20:
return n
#if virus starts greater than half way, count backwards
if p[0]>10 or p[1]>10:
for n in range(1,21):
p[0]-=1
p[1]-=1
if p[0] == 1 or p[1]==1:
return n
```

```
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(classroom_virus([10,10]),10)
test.assert_equals(classroom_virus([9,9]),11)
test.assert_equals(classroom_virus([1,1]),19)
test.assert_equals(classroom_virus([7,0]),13)
test.assert_equals(classroom_virus([20,20]),19)
```

Imagine a 3 dimentional cubical chess board. A knight is placed at the center of the cube at (0,0,0).

You will be given an x,y,z coordinate. Can the knight reach that point in 2 moves?

Return either True or False

Examples:

Given coordinate (3,2,1) returns True

Given coordinate (4,2,0) returns True

Given coordinate (1,2,3) returns True

Given coordinate (0,-1,0) returns False

(0,0,0) will be taken as True

Negative coordinates are valid

Helpful knowledge:

There are 24 total positions the knight can move to: 8 in the xy plane, 8 in the xz plane,and 8 in the yz plane

```
import random
def knight_move3d(p):
#Brute force: randomly generate 2 moves at a time and compare to point p, still needs work, its taking wrong values as True...
for i in range(100000):
q = [0,0,0]
for n in range(2):
#r0 and r1 are random places in point q(x,y,z)
r0=random.randint(0,2)
r1=random.randint(0,2)
if r1 == r0: #filters out using same place value twice
break
#j and k are random values to try in q
j=random.randint(-2,2)
k=random.randint(-2,2)
if abs(k) == abs(j): #filters out using the same number twice
break
# add random values -2 to +2 to point q in random places r0 and r1
q[r0]+=j
q[r1]+=k
#compare xyz of q to xyz of p
if q[0]==p[0]:
if q[1]==p[1]:
if q[2]==p[2]:
return True
return False
```

```
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(knight_move3d((3,2,1)),True)
test.assert_equals(knight_move3d((4,2,0)),True)
test.assert_equals(knight_move3d((1,2,3)),True)
test.assert_equals(knight_move3d((1,1,0)),True)
test.assert_equals(knight_move3d((0,0,0)),True)
test.assert_equals(knight_move3d((0,-1,0)),False)
test.assert_equals(knight_move3d((1,0,0)),False)
test.assert_equals(knight_move3d((-1,0,0)),False)
test.assert_equals(knight_move3d((0,1,0)),False)
test.assert_equals(knight_move3d((0,0,1)),False)
test.assert_equals(knight_move3d((0,0,-1)),False)
```

Imagine a 3 dimentional cubical chess board. A knight is placed at the center of the cube at (0,0,0).

You will be given an x,y,z coordinate. Can the knight reach that point in one move?

Return either True or False

Examples:

Given coordinate (2,0,1) returns True

Given coordinate (-2,1,0) returns True

Given coordinate (0,1,2) returns True

Given coordinate (-1,1,2) returns False

(0,0,0) will be taken as True

negative coordinates are valid

There are 24 total positions the knight can move to: 8 in the xy plane, 8 in the xz plane,and 8 in the yz plane

```
def knight_move3d(p):
return()
```

```
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals((2,0,1),True)
```