This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cs50 import get_float | |
# Get positive float from user | |
while True: | |
change = get_float("Change owed: ") | |
if change > 0: | |
break | |
# declare counters | |
quarters, dimes, nickels, pennies = 0, 0, 0, 0 | |
# make total |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(100) | |
if i % 3 == 0 and i % 5 == 0: | |
print("FizzBuzz") | |
elif i % 3 == 0: | |
print("Fizz") | |
elif i % 5 == 0: | |
print("Buzz") | |
else print i | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Program prints numbers 1-100 | |
// For multiples of 3 print Fizz | |
// For multiples of 5 print buzz | |
// For multiples of BOTH print FizzBuzz | |
// Make an array of ints | |
// Make a for loop that prints the ith int in the array up until i = 100 | |
// Add if array[i] % 3 != 0 then print buzz | |
// Add same for % 5 | |
// Add for both |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cs50.h> | |
#include <stdio.h> | |
#include <math.h> | |
//notes to self, it works for entering numbers as pennies ie 85 for $0.85 | |
//need to take input as float and convert to int | |
//need to prompt user again if input is negative or not a number | |
//need to remove printf of each coin so output is just total | |
int main(void) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cs50.h> | |
#include <stdio.h> | |
#include <math.h> | |
int main(void) | |
{ | |
int change = get_int("change owed: "); | |
int quarter_count = 0; | |
quarter_count = ((change - (change % 25)) / 25); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
int n; | |
do | |
n = get_int("change owed: "); | |
while (n < 0); | |
int quarter_counter = 0; | |
int dime_counter = 0; | |
int nickel_counter = 0; | |
int penny_counter = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cases when the amount cannot be made up: | |
amount < min-denomination | |
smallest-remainder-of-amount / min-denom is not an integer | |
actually the above isn't right - if the coins were say 71, 4 and 3 and the amount was 75 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://leetcode.com/problems/coin-change/description/ | |
cond (> amount min-denom) | |
coin-iter | |
else | |
-1)) | |
define coin-iter | |
if (> amount max-denom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define (sum term A next B) | |
(IF (> A B) | |
0 | |
(+ (term A) | |
(sum term | |
(next A) | |
next | |
B)))) | |
define (sum-int A B) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (pascal row col) | |
cond (> col row) 0)) | |
(= col row) 1)) | |
(> col row) 1)) | |
else (+ (pascal (- row 1) (- col 1) | |
(pascal (- row 1) col)))))) |