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
@ZechCodes
ZechCodes / challenge_162.md
Created January 9, 2021 03:43
Challenge 162 - Havel-Hakimi Algorithm

Challenge 162 - Havel-Hakimi Algorithm

It was a dark and stormy night. Detective Havel and Detective Hakimi arrived at the scene of the crime.

Other than the detectives, there were 10 people present. They asked the first person, "out of the 9 other people here, how many had you already met before tonight?" The person answered "5". They asked the same question of the second person, who answered "3". And so on. The 10 answers they got from the 10 people were:

5 3 0 2 6 2 0 7 2 5

The detectives looked at the answers carefully and deduced that there was an inconsistency, and that somebody must be lying. (For the purpose of this challenge, assume that nobody makes mistakes or forgets, and if X has met Y, that means Y has also met X.)

@ZechCodes
ZechCodes / challenge_161.md
Last active January 8, 2021 05:01
Challenge 161 - Lambda Adder

Challenge 161 - Lambda Adder

Write a function that returns a lambda expression, which adds n to its input.

Examples

adds1 = adds_n(1)

adds1(3) ➞ 4
adds1(5.7) ➞ 6.7
@ZechCodes
ZechCodes / challenge_160.md
Last active January 8, 2021 05:00
Challenge 160 - Car Timer 🏎️

Challenge 160 - Car Timer 🏎️

A built-in timer inside your car can count the length of your ride in minutes and you have started your ride at 00:00.

Given the number of minutes n at the end of the ride, calculate the current time. Return the sum of digits that the digital timer in the format hh:mm will show at the end of the ride.

Examples

car_timer(240) ➞ 4
# 240 minutes have passed since 00:00, the current time is 04:00
@ZechCodes
ZechCodes / challenge_159.md
Created January 6, 2021 03:40
Challenge 159 - Face Interval

Challenge 159 - Face Interval

In mathematics, interval is the difference between the largest number and the smallest number in a list.

To illustrate:

A = (3, 5, 7, 23, 11, 42, 80)

Interval of A = 80 - 3 = 77

@ZechCodes
ZechCodes / challenge_158.md
Created January 5, 2021 00:59
Challenge 158 - Time Saved Speeding

Challenge 158 - Time Saved Speeding

One cause for speeding is the desire to shorten the time spent traveling. In long distance trips speeding does save an appreciable amount of time. However, the same cannot be said about short distance trips.

Create a function that calculates the amount of time saved were you traveling with an average speed that is above the speed-limit as compared to traveling with an average speed exactly at the speed-limit.

Examples

# The parameter's format is as follows:
# (speed limit, avg speed, distance traveled at avg speed)
@ZechCodes
ZechCodes / challenge_157.md
Created January 2, 2021 02:00
Challenge 157 - Date Format

Challenge 157 - Date Format

Create a function that converts a date formatted as MM/DD/YYYY to YYYYDDMM.

Examples

format_date("11/12/2019") ➞ "20191211"

format_date("12/31/2019") ➞ "20193112"
@ZechCodes
ZechCodes / challenge_156.md
Created January 1, 2021 02:05
Challenge 156 - Invert Keys & Values

Challenge 156 - Invert Keys & Values

Write a function that inverts the keys and values of a dictionary.

Examples

invert({ "z": "q", "w": "f" })
➞ { "q": "z", "f": "w" }

invert({ "a": 1, "b": 2, "c": 3 })
@ZechCodes
ZechCodes / challenge_155.md
Created December 31, 2020 01:22
Challenge 155 - List of Multiples

Challenge 155 - List of Multiples

Create a function that takes two numbers as arguments (num & length) and returns a list of multiples of num until the list length reaches length.

Examples

list_of_multiples(7, 5) ➞ [7, 14, 21, 28, 35]

list_of_multiples(12, 10) ➞ [12, 24, 36, 48, 60, 72, 84, 96, 108, 120]
@ZechCodes
ZechCodes / challenge_154.md
Created December 30, 2020 02:41
Challenge 154 - Validate Pin

Challenge 154 - Validate Pin

Create a function to test if a string is a valid pin or not.

A valid pin has:

  • Exactly 4 or 6 characters.
  • Only numerical characters (0-9).
  • No whitespace.
@ZechCodes
ZechCodes / challenge_153.md
Created December 28, 2020 23:53
Challenge 153 - Father and Son Ages

Challenge 153 - Father and Son Ages

Create a function that takes two arguments: a father's current age and his son's current age. Сalculate how many years ago the father was twice as old as his son, or in how many years he will be twice as old.

Examples

age_difference(36, 7) ➞ 22
# 22 years from now, the father will be 58 years old and his son will be 29 years old.

age_difference(55, 30) ➞ 5