Skip to content

Instantly share code, notes, and snippets.

View les-peters's full-sized avatar

Les Peters les-peters

View GitHub Profile
question = """
Given a set of letter grades, output the GPA (grade point average) of those grades.
Key and examples:
A = 4 grade points
A- = 3.7 grade points
B+ = 3.3 grade points
B = 3 grade points
B- = 2.7 grade points
@les-peters
les-peters / 2022-09-05.py
Created September 5, 2022 19:17
From To
question = """
Write a function fromTo that produces a generator, that will produce values in a range.
Usage:
let gen = fromTo(5,7)
> gen()
5
@les-peters
les-peters / 2022-08-22.py
Created August 27, 2022 16:11
Formatted Table String
question = """
Given a string that represents a markdown table,
return a formatted markdown table. A formatted markdown
table means that the width of each column is the width of
the longest cell in the column.
Example:
Input:
| Syntax | Description |
@les-peters
les-peters / 2022-08-15.py
Created August 16, 2022 21:03
Longest paren substring
question = """
Given a string s consisting of various parenthesis ( and ),
find the length of the longest valid parenthesis substring.
Example:
> parensSubstring('(()(')
> 2
> parensSubstring(')()(()))')
@les-peters
les-peters / 2022-07-18.py
Created July 21, 2022 18:51
Hide Email Address
question = """
Given a string that has a valid email address, write a function to hide
the first part of the email (before the @ sign), minus the first and last
character. For extra credit, add a flag to hide the second part after the
@ sign to your function excluding the first character and the domain extension.
Examples:
> hideEmail('example@example.com')
@les-peters
les-peters / 2022-07-04.py
Created July 10, 2022 11:48
Rumikub simulation
question = """
The game Rummikub has 106 tiles: 8 sets numbered 1-13, colored
red, blue, black, and yellow, and two (2) “wildcard” tiles.
Write two functions: one that creates a new player's tray of
14 tiles (repetitions allowed), and one that returns the valid
sets from a given tray. A set can be either 3 or 4 tiles of the
same number (but all different colors), or it can be a “run”
(which is three or more consecutive numbers all in the same color).
The rules for Rummikub are here if you need more clarification!
@les-peters
les-peters / 2022-06-27.py
Created June 27, 2022 11:00
Longest Word
question = """
Given a string str and a set of words dict, find the longest word in dict that is a subsequence of str.
Example:
let str = "abppplee"
let dict = {"able", "ale", "apple", "bale", "kangaroo"}
$ longestWord(str, dict)
@les-peters
les-peters / 2022-06-20.py
Created June 20, 2022 13:20
Previous Fibonacci
question = """
Given a Fibonacci number, give the previous Fibonacci number.
If the number given is not a Fibonacci number, return -1.
"""
def prevFib(number):
fibs = [ 0, 1 ]
answer = None
@les-peters
les-peters / 2022-06-13.py
Created June 13, 2022 20:25
Long Text Generator
question = """
Create a loooong teeeext generator that takes in a string and an integer n,
and multiplies the vowels in the string by n.
Example:
$ longText('hello world', 3)
$ 'heeellooo wooorld'
question = """
Write a function that determines if all the characters in a given string
are unique. Can you do this without making any new variables? You choose
if you want to include capitalization in your consideration for this one,
as a fun challenge.
Example:
> allUnique('Cassidy')