Skip to content

Instantly share code, notes, and snippets.

View ZechCodes's full-sized avatar
🏄‍♂️
Surfing on a space-time bubble

Zech Zimmerman ZechCodes

🏄‍♂️
Surfing on a space-time bubble
View GitHub Profile

Challenge 38 - Rearrange the Number

Given a number, return the difference between the maximum and minimum numbers that can be formed when the digits are rearranged.

Examples

rearranged_difference(972882) ➞ 760833
# 988722 - 227889 = 760833

rearranged_difference(3320707) ➞ 7709823
@ZechCodes
ZechCodes / challenge-39.md
Created June 25, 2020 01:52
Challenge 39 - Left Most Digit

Challenge 39 - Left Most Digit

Write a function that takes a string as an argument and returns the left most digit in the string.

Examples

left_digit("TSU2Astneuoah") ➞ 2

left_digit("TS3NHriu4et") ➞ 3
@ZechCodes
ZechCodes / challenge-40.md
Last active June 27, 2020 01:42
Challenge 40 - Sum of Every Nth Number

Challenge #40 - Sum of Every Nth Number

Given a list of numbers and a positive value for n, return the sum of every nth number in the list.

Examples

sum_every_nth([4, 8, 6, 6, 7, 9, 3], 1) ➞ 43
# 4+8+6+6+7+9+3 = 43

sum_every_nth([7, 3, 10, 4, 5, 8, 4, 9, 6, 9, 10, 1, 4], 4) ➞ 14

Challenge #41 - Matrix Movement

Create a function which takes a parameter mat, where mat is a matrix (list of lists) 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.
@ZechCodes
ZechCodes / challenge-41-oop-solution.py
Last active June 28, 2020 12:48
Challenge 41 - Solutions
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":
@ZechCodes
ZechCodes / challenge-42.md
Last active June 29, 2020 01:54
Challenge 42 - Factorials

Challenge 42 - Factorials

Write a function that takes a positive integer and return its factorial.

Examples

factorial(4) ➞ 24

factorial(0) ➞ 1
@ZechCodes
ZechCodes / challenge-43.md
Created June 29, 2020 23:41
Challenge 43 - Sock Pairs

Challenge 43 - Sock Pairs

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.

Examples

sock_pairs("AA") ➞ 1
@ZechCodes
ZechCodes / challenge-44.md
Last active July 1, 2020 01:36
Challenge 44 - Folding a Piece of Paper

Challenge 44 - Folding a Piece of Paper

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.

Examples

num_layers(1) ➞ "0.001m"
# Paper folded once is 1mm (equal to 0.001m)

num_layers(4) ➞ "0.008m"
@ZechCodes
ZechCodes / challenge-45.md
Created July 2, 2020 00:48
Challenge 45 - Inequality Expressions

Challenge 45 - Inequality Expressions

Without using exec or eval, create a function that returns True if a given inequality expression is correct and False otherwise.

Examples

correct_signs("3 < 7 < 11") ➞ True

correct_signs("13 > 44 > 33 > 1") ➞ False
@ZechCodes
ZechCodes / challenge-46.md
Last active July 3, 2020 01:03
Challenge 46 - Missing Numbers

Challenge 46 - Missing Numbers

Create a function that takes a list of numbers that form a range and returns a list of the numbers missing from that range.

Examples

missing_numbers([1, 2, 3, 4, 6, 7, 8, 9, 10]) ➞ [5]

missing_numbers([7, 2, 3, 6, 5, 9, 1, 4, 11]) ➞ [8, 10]