Skip to content

Instantly share code, notes, and snippets.

"""4.10.2024
This week's question:
Imagine you have n dice, and each die has m faces on it (so the numbers are from 1 to m). Write a function where, given
an integer target, it returns the number of possible ways to roll the dice to get the sum of target face up. You can
safely assume m will never be larger than 20 (so you don't have to deal with mega huge numbers)."""
from itertools import product
def dice_roller(n,m,target):
#n is the number of dice
/*
This week's question:
Given an integer array arr, return the maximum difference between two successive elements
in arr's sorted form. Return 0 if there's 0 or 1 elements.
*/
let array_input = [3,6,9,1,2]
function max_gap(array) {
if (array.length <2){
"""02.27.2024"""
"""
This week's question:
Given a number and a digit to remove from that number, maximize the resulting number after the digit has been removed
and print it. You can choose how you want to handle a digit not existing in the number.
"""
integer_input = 314159268
def remove_digit(number, digit):
integer_as_string = str(number)
"""02.21.2024"""
"""
Given a string array, find the maximum product of word lengths where the words
don't share any letters.
"""
import itertools
list_input = ["fish","fear","boo","egg","cake","abcdef"]
def word_length_product(input):
def flip(array, direction):
if direction == "vertical":
return array.reverse()
elif direction == "horizontal":
for i in range(len(array)):
array[i].reverse()
return array
twod_array= [
@athursto
athursto / solution0918.py
Created September 19, 2023 20:28
Casidoo 9.18.23
"""9.18.2023"""
"""You have n equal-sized blocks and you want to build a staircase with them. Return the number of steps you
\can fully build."""
def stair_builder(num):
building_blocks, step_array = "#" * num, [] # input represented as hashes, and a place to store the steps
# print(f"There are currently {len(building_blocks)} building blocks")
step_width = 0 # this is the latest step to be taken out of original
while len(building_blocks) > step_width:
@athursto
athursto / solution0911.py
Created September 11, 2023 14:29
Casidoo 9.11.23
"""9.11.2023"""
"""This week's question: Given an array of integers, sort them into two separate sorted arrays of even and odd numbers.
If you see a zero, skip it."""
def separate_and_sort(array):
zeros_out = [num for num in array if num!= 0]
zeros_out.sort()
even_list, odd_list = [num for num in zeros_out if num % 2 == 0], [num for num in zeros_out if num % 2 != 0]
return even_list, odd_list
"""9.7.2023"""
"""Given an array of integers and a number k (where k is guaranteed to be less than the array's length), return a
subarray of length k with the minimum possible sum. Maintain the order of the original array!"""
def min_array(array, k):
pointer, endpoint, min_sum, ideal_array = 0, k, 1000000000, None
while pointer <= (len(array) - k):
sub_array = array[pointer: endpoint]
print(f"assessing {sub_array}")
if sum(sub_array) < min_sum:
"""8.21.2023"""
"""Make a "guessing game" where there is a target number, and as the user makes guesses, the output returns
higher or lower until the user is correct."""
def guessing_game(target_number):
guess_count = 0
s = -10000
if type(target_number) != int:
print("Please enter an integer and try again.")
def faulty_keyboard(string):
vowel_list = ["a", "e", "i", "o", "u", "y"]
substring = ""
for char in string:
print(f"evaluating.... {char}")
if char in vowel_list:
substring = substring[::-1]
print(f"reversing.... substring is now {substring}")
else:
substring = substring + char