Skip to content

Latest commit

 

History

History
76 lines (65 loc) · 1.48 KB

File metadata and controls

76 lines (65 loc) · 1.48 KB

Python Problems

Divisible by a given number

Find all numbers in the list n which are divisible by a given integer d.

Signature

def divisible_by_d(n: list, d: int) -> list:
    pass

Test examples

>>> divisible_by_d([1,2,3,4,5,6], 3)
[3, 6]
>>> divisible_by_d([0,1,2,3,4,5,6], 4)
[0, 4]
>>> divisible_by_d([0], 4)
[0]
>>> divisible_by_d([1,3,5], 2)
[]

Knight valid moves count

Given a tuple with two indexes that denote the knight position on a matrix board, return the count of all valid moves which the knight can made.

Signature

def knight_moves(pos: tuple) -> int:
    # pos[0] denotes the knights row
    # pos[1] denotes the knights column
    pass

Test examples

>>> knight_moves((2, 6))
6
>>> knight_moves((0, 7))
2
>>> knight_moves((5, 0))
4
>>> knight_moves((4, 3))
8
>>> knight_moves((6, 7))
3

Consider these graphical examples

Eight legal moves where pos = (4, 3)

M 0 1 2 3 4 5 6 7
0
1
2 * *
3 * *
4 N
5 * *
6 * *
7

Two legal moves where pos = (7, 7)

M 0 1 2 3 4 5 6 7
0
1
2
3
4
5 *
6
7 * N