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_152.md
Created December 26, 2020 02:42
Challenge 152 - Finding Adjacent Nodes

Challenge 152 - Finding Adjacent Nodes

A graph is a set of nodes and edges that connect those nodes.

There are two types of graphs; directed and undirected. In an undirected graph, the edges between nodes have no particular direction (like a two-way street) whereas in a directed graph, each edge has a direction associated with it (like a one-way street).

0 --- 1 --- 3
       \   /
        \ /
@ZechCodes
ZechCodes / challenge_151.md
Last active November 21, 2020 01:57
Challenge 151 - Sales Commissions

Challenge 151 - Sales Commissions

You're a regional manager for an office beverage sales company, and right now you're in charge of paying your sales team their monthly commissions.

Sales people get paid using the following formula for the total commission: 6.2% of profit, with no commission for any product to total less than 0.

Create a function that takes two dictionaries, one showing the sales figure per salesperson for each product they sold, and another for the expenses by product per salesperson. It should return a dictionary of the sales people with their total commissions rounded to two decimal places.

Example

@ZechCodes
ZechCodes / challenge_150.md
Created November 18, 2020 02:35
Challenge 150 - Harshad Numbers

Challenge 150 - Harshad Numbers

A number is a Harshad (also called Niven) number if it is divisible by the sum of its digits. For example, 666 is divisible by 6 + 6 + 6, so it is a Harshad number.

Write a function to determine whether the given number is a Harshad number.

Examples

is_harshad(209) ➞ True
@ZechCodes
ZechCodes / challenge_149.md
Created November 17, 2020 01:56
Challenge 149 - Calculating Damage

Challenge 149 - Calculating Damage

Create a function that takes damage and speed (attacks per second) and returns the amount of damage after a given time.

Examples

calculate_damage(40, 5, "second") ➞ 200

calculate_damage(100, 1, "minute") ➞ 6000
@ZechCodes
ZechCodes / challenge_148.md
Created November 13, 2020 03:06
Challenge 148 - Calculate Uncovered

Challenge 148 - Calculate Uncovered

Someone stole some of your stuff. You have insurance that will cover the cost to replace them up to a certain limit. Create a function that returns the amount that isn't covered when given a limit and a dictionary of all stolen items and their value. If the insurance covers the cost of all items then return 0.

Examples

calc_uncovered({ "baseball bat": 20 }, 5) ➞ 15

calc_uncovered({"skate": 10, "painting": 20 }, 19) ➞ 11
@ZechCodes
ZechCodes / challenge_147.md
Last active November 12, 2020 05:21
Challenge 147 - Emotify Sentence

Challenge 147 - Emotify Sentence

Create a function that changes specific words into emoticons. Given a sentence as a string, replace the words "smile", "grin", "sad", and "mad" with their corresponding emoticons.

word	 emoticon
smile	 :D
grin	 :)
sad	 :(
mad	 :P
@ZechCodes
ZechCodes / challenge_146.md
Created November 9, 2020 00:01
Challenge 146 - Compare by ASCII Codes

Challenge 146 - Compare by ASCII Codes

Create a function that compares two words based on the sum of their ASCII codes and returns the word with the smaller ASCII sum.

Examples

ascii_compare("hey", "man") ➞ "man"
# ["h", "e", "y"] ➞ sum([104, 101, 121]) ➞ 326
# ["m", "a", "n"] ➞ sum([109, 97, 110]) ➞ 316
@ZechCodes
ZechCodes / challenge_145.md
Created November 2, 2020 02:15
Challenge 145 - UPC check digits

Challenge 145 - UPC check digits

The Universal Product Code (UPC-A) is a bar code used in many parts of the world. The bars encode a 12-digit number used to identify a product for sale, for example:

042100005264

The 12th digit (4 in this case) is a redundant check digit, used to catch errors. Using some simple calculations, a scanner can determine, given the first 11 digits, what the check digit must be for a valid code. UPC's check digit is calculated as follows (taken from Wikipedia):

  • STEP 1: Sum the digits at odd-numbered positions (1st, 3rd, 5th, ..., 11th). If you use 0-based indexing, this is the even-numbered positions (0th, 2nd, 4th, ... 10th).
  • STEP 2: Multiply the result from step 1 by 3.
@ZechCodes
ZechCodes / challenge_144.md
Created November 1, 2020 02:13
Challenge 144 - Snail Goes Up the Stairs

Challenge 144 - Snail Goes Up the Stairs

A snail goes up the stairs. Every step, he must go up the step, then go across to the next step. He wants to reach the top of the tower.

Write a function that returns the distance the snail must travel to the top of the tower given the height and length of each step and the height of the tower.

Examples

total_distance(0.2, 0.4, 100.0) ➞ 300.0
# Total distance is 300.
@ZechCodes
ZechCodes / challenge_143.md
Created October 31, 2020 01:37
Challenge 143 - Return First and Last Parameter

Challenge 143 - Return First and Last Parameter

Write two functions:

  • first_arg() should return the first parameter passed in.
  • last_arg() should return the last parameter passed in.

Examples

first_arg(1, 2, 3) ➞ 1