Skip to content

Instantly share code, notes, and snippets.

@transformer45
transformer45 / credit.py
Created October 6, 2023 19:40
cs50 Problem Set 6 "Credit Python"
def get_credit_card():
return input('Number: ')
def confirm_CC(credit_card_number):
# Clean up any dashes or other non-numeric characters from the credit card number
cc = ''.join(filter(str.isdigit, credit_card_number))
# check Luhn’s Algorithm
sum = 0
@transformer45
transformer45 / cash.py
Created October 6, 2023 18:33
cs50 Problem Set 6 "Cash"
cents = -1
while cents < 0:
cents = input("Change owed: ")
cents = int(cents)
coins = 0
while cents >= 25:
cents -= 25
coins += 1
while cents >= 10:
@transformer45
transformer45 / mario.py
Created October 6, 2023 18:26
cs50 Leb 6 "Mario-More"
import cs50
def main():
height = get_height()
print_pyramid(height)
def get_height():
height = 0
@transformer45
transformer45 / tournament.py
Created October 6, 2023 17:58
cs50 Lab 6 "World Cup"
# Simulate a sports tournament
# thanks to ymeng979 on Github for pointing me in the right direction
# https://gist.github.com/ymeng979/69d040ce428fa957d3584f541836e394
import csv
import sys
import random
# Number of simluations to run
N = 1000
@transformer45
transformer45 / taqueria.py
Created October 5, 2023 22:40
cs50 Practice set 6 "Taqueria"
menu = {
"Baja Taco": 4.00,
"Burrito": 7.50,
"Bowl": 8.50,
"Nachos": 11.00,
"Quesadilla": 8.50,
"Super Burrito": 8.50,
"Super Quesadilla": 9.50,
"Taco": 3.00,
"Tortilla Salad": 8.00
@transformer45
transformer45 / jar.py
Created October 5, 2023 19:02
cs50 Practice Problems 6 "Jar"
class Jar:
def __init__(self, capacity=12):
if capacity < 0:
raise ValueError("Jar size too small")
self._capacity = capacity
self._size = 0
def __str__(self):
return '🍪' * self.size
@transformer45
transformer45 / figlet.py
Created October 5, 2023 17:51
cs50 Practice Set 6 "Figlet"
from cs50 import get_string
from pyfiglet import Figlet
import random, sys
Figlet = Figlet()
fonts = Figlet.getFonts()
# if no arguments provided, pick random font
if len(sys.argv) == 1:
f = random.choice(Figlet.getFonts())
@transformer45
transformer45 / bank.py
Created October 5, 2023 16:50
cs50 Practice Problems 6 "Bank"
from cs50 import get_string
try:
greeting = get_string("What say you? ")
character = greeting[0]
if greeting.lower() == "hello":
print("$100")
elif character.lower() == 'h':
print("$20")
@transformer45
transformer45 / dictionary.c
Last active October 3, 2023 19:03
cs50 Problem Set 5 "Speller" (using Division-Remainder Method, only 1.33 seconds on Holmes.txt!)
// Implements a dictionary's functionality
// This HASH function uses the single first letter of the word, and is the slowest...
#include <ctype.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@transformer45
transformer45 / dictionary.c
Created October 3, 2023 17:41
cs50 Problem Set 5 "Speller" (hash version with first 2 letters, faster than 1 letter, but not much...)
// Implements a dictionary's functionality
// This HASH function uses the first two letters of the word, and is faster than a single letter...
// includes the typedef of struct hashindex in dictionary.h
//
// typedef struct hashindex
// {
// int first;
// int second;
// }