Given a number, return the difference between the maximum and minimum numbers that can be formed when the digits are rearranged.
rearranged_difference(972882) ➞ 760833
# 988722 - 227889 = 760833
rearranged_difference(3320707) ➞ 7709823
Create a function which takes a parameter mat
, where mat
is a matrix (list
of list
s) such that all but one entry equals 0
(and the non-zero entry equals 1
). The function, after being passed a matrix, should be repeatedly callable with the following str
commands:
"up"
➞ Move the 1
to the cell above it."down"
➞ Move the 1
to the cell below it."left"
➞ Move the 1
to the cell to the left of it."right"
➞ Move the 1
to the cell to the right of it."stop"
➞ Return the resulting matrix.class MatrixMover(MatrixMoverABC): | |
def __init__(self, matrix: List[List[int]]): | |
super().__init__(matrix) | |
self.matrix = matrix | |
def up(self) -> "MatrixMoverABC": | |
self.matrix.append(self.matrix.pop(0)) | |
return self | |
def down(self) -> "MatrixMoverABC": |
Joseph is in the middle of packing for a vacation. He's having a bit of trouble finding all of his socks, though.
Write a function that returns the number of sock pairs he has. A sock pair consists of two of the same letter, such as "AA"
. The socks are represented as an unordered sequence.
sock_pairs("AA") ➞ 1
Create a function that returns the thickness (in meters) of a piece of paper after folding it n
number of times. The paper starts off with a thickness of 0.5mm
.
num_layers(1) ➞ "0.001m"
# Paper folded once is 1mm (equal to 0.001m)
num_layers(4) ➞ "0.008m"