From f8006eb17cd9b7b7a7a393921487d2994dfc2ec9 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Wed, 20 Sep 2023 09:53:04 -0400 Subject: [PATCH] more --- 02-remove_dupe/README.md | 13 ++++++++ 02-remove_dupe/duplicate.py | 2 ++ 03-birthday/README.md | 18 +++++++++++ 03-birthday/convert.py | 5 +++ 04-mcnugget-numbers/README.md | 23 ++++++++++++++ 04-mcnugget-numbers/mcnugget.py | 0 05-sum_of_divisors/README.md | 14 +++++++++ 05-sum_of_divisors/wtf.py | 14 +++++++++ 06-binary-converter/README.md | 41 +++++++++++++++++++++++++ 06-binary-converter/binary-converter.py | 16 ++++++++++ 10 files changed, 146 insertions(+) create mode 100644 02-remove_dupe/README.md create mode 100644 02-remove_dupe/duplicate.py create mode 100644 03-birthday/README.md create mode 100644 03-birthday/convert.py create mode 100644 04-mcnugget-numbers/README.md create mode 100644 04-mcnugget-numbers/mcnugget.py create mode 100644 05-sum_of_divisors/README.md create mode 100644 05-sum_of_divisors/wtf.py create mode 100644 06-binary-converter/README.md create mode 100644 06-binary-converter/binary-converter.py diff --git a/02-remove_dupe/README.md b/02-remove_dupe/README.md new file mode 100644 index 0000000..17fe302 --- /dev/null +++ b/02-remove_dupe/README.md @@ -0,0 +1,13 @@ +Remove The Dupes! +================== + +You have a string "aabbccddeded". We want to remove all the _consecutive_ duplicates and put them in a separate string, which yields two separate instances of the string "abcdeded". + + input: "balloons" + expected output: "balons" "lo" + + input: "aabbccddeded" + expected output: "abcdeded" "abcd" + + input: "flabby aapples" + expected output: "flaby aples" "bap" diff --git a/02-remove_dupe/duplicate.py b/02-remove_dupe/duplicate.py new file mode 100644 index 0000000..6eb0181 --- /dev/null +++ b/02-remove_dupe/duplicate.py @@ -0,0 +1,2 @@ +def remove_duplicate(string): + pass diff --git a/03-birthday/README.md b/03-birthday/README.md new file mode 100644 index 0000000..2fb08a7 --- /dev/null +++ b/03-birthday/README.md @@ -0,0 +1,18 @@ +Age Calculator +=============== + +###Part 1 + +Create a program that will take user input and tell them their age in months, days, hours, and minutes. + +Sample output: +``` +How old are you? 18 +months : 216, days : 6480, hours : 155520, and minutes : 388800 +``` + +###Part 2 + +Add a function to your program that takes the user's birthday as input in `YYYY-MM-DD` format and tells them their age in months, days, hours and minutes in the same fashion. + +Hint: Take a look at Python's `datetime` library. diff --git a/03-birthday/convert.py b/03-birthday/convert.py new file mode 100644 index 0000000..198e821 --- /dev/null +++ b/03-birthday/convert.py @@ -0,0 +1,5 @@ +def age_to_time(age): + pass + +def birthday_to_time(birthday): + pass diff --git a/04-mcnugget-numbers/README.md b/04-mcnugget-numbers/README.md new file mode 100644 index 0000000..9794884 --- /dev/null +++ b/04-mcnugget-numbers/README.md @@ -0,0 +1,23 @@ +McNugget Numbers +================== + +In the 1980s, while eating McDonald's with his son, mathematician Henri Picciotto reasoned [McNugget Numbers](http://en.wikipedia.org/wiki/Coin_problem#McNugget_numbers). + +At McDonalds’ Restaurants at the time, Chicken McNugget meals were available in sizes of 6 McNuggets, 9 McNuggets, or 20 McNuggets. + +A number is a McNugget number if it can be the sum of the number of McNuggets purchased in an order before eating any of them. + +Some Examples: + + 20 + 6 == 26 + 9 + 9 + 9 + 9 + 9 == 45 + 20 + 9 + 6 == 35 + ...etc + +###Task 1 + +Determine all numbers that are not McNugget numbers using 1980s order sizes - `6`, `9` and `20`. + +###McNugget 2015 Redux + +Determine all numbers that are not McNugget numbers using today's order sizes - `4`, `6`, `10`, `20` and `40`. diff --git a/04-mcnugget-numbers/mcnugget.py b/04-mcnugget-numbers/mcnugget.py new file mode 100644 index 0000000..e69de29 diff --git a/05-sum_of_divisors/README.md b/05-sum_of_divisors/README.md new file mode 100644 index 0000000..ef36229 --- /dev/null +++ b/05-sum_of_divisors/README.md @@ -0,0 +1,14 @@ +WTF - Write Totatives Finder +================= + +The divisors of a number are those numbers that divide it evenly; for example, the divisors of 60 are `1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, and 60`. The sum of the divisors of 60 is 168, and the number of divisors of 60 is 12. + +The totatives of a number are those numbers less than the given number and coprime to it. Two numbers are coprime if they have no common factors other than 1. + +For example, the totatives of 30 are `1, 7, 11, 13, 17, 19, 23, and 29`. + +The number of totatives of a given number is called its totient. As you can see above, the totient of 30 is 8. + +Your task is to write a small library of five functions that compute the divisors of a number, the sum and number of its divisors, the totatives of a number, and its totient. + +_Hint_: The functions can call each other! diff --git a/05-sum_of_divisors/wtf.py b/05-sum_of_divisors/wtf.py new file mode 100644 index 0000000..9d2e936 --- /dev/null +++ b/05-sum_of_divisors/wtf.py @@ -0,0 +1,14 @@ +def compute_divisors(num): + pass + +def sum_of_divisors(num): + pass + +def divisor_count(num): + pass + +def get_totatives(num): + pass + +def totient(num): + pass diff --git a/06-binary-converter/README.md b/06-binary-converter/README.md new file mode 100644 index 0000000..1421cf8 --- /dev/null +++ b/06-binary-converter/README.md @@ -0,0 +1,41 @@ +Binary Converter +================ + +In this exercise you will be making functions that convert between base 10 numbers and binary. + +Binary notation is based on powers of 2. Each digit is a power of 2. The first digit is 2^0, second 2^1, etc... You then add all of the digits together. + +For example, 101 is 5 (4 + 1). 110 is 6 (4 + 2). 1100 is 12 (8 + 4) +Here is a chart of some base 2 vs base 10 notation numbers: + + 0.....0 + 1.....1 + 10.....2 + 11.....3 + 100.....4 + 101.....5 + 110.....6 + 111.....7 + 1000.....8 + 1001.....9 + 1010.....10 + 1011.....11 + 1100.....12 + 1101.....13 + +####Step 1 + +Write a method that takes binary numbers and outputs a base 10 number. + + binary_to_decimal(1011) ## returns 11 + +####Step 2 + +Write a method that takes decimal numbers and returns it in binary notation. + + decimal_to_binary(12) ## 1100 + +Resources +---------- + +[How to Convert Decimal to Binary](http://www.wikihow.com/Convert-from-Decimal-to-Binary) diff --git a/06-binary-converter/binary-converter.py b/06-binary-converter/binary-converter.py new file mode 100644 index 0000000..c12f4de --- /dev/null +++ b/06-binary-converter/binary-converter.py @@ -0,0 +1,16 @@ +def binary_to_decimal(num): + pass + +def decimal_to_binary(num): + pass + + +assert binary_to_decimal(0) == 0, "0 to decimal should return 0" +assert binary_to_decimal(1011) == 11, "1011 to decimal should return 11" +assert binary_to_decimal(101011) == 43, "101011 to decimal should return 43" +assert binary_to_decimal(101011101) == 349, "101011101 to decimal should return 349" + +assert decimal_to_binary(0) == 0, "0 to binary should return 0" +assert decimal_to_binary(5) == 101, "5 to binary should return 101" +assert decimal_to_binary(10) == 1010, "10 to binary should return 1010" +assert decimal_to_binary(113) == 1110001, "113 to binary should return 1110001"