forked from course-work/week1
more
This commit is contained in:
parent
bc46c80b02
commit
f8006eb17c
13
02-remove_dupe/README.md
Normal file
13
02-remove_dupe/README.md
Normal file
@ -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"
|
2
02-remove_dupe/duplicate.py
Normal file
2
02-remove_dupe/duplicate.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
def remove_duplicate(string):
|
||||||
|
pass
|
18
03-birthday/README.md
Normal file
18
03-birthday/README.md
Normal file
@ -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.
|
5
03-birthday/convert.py
Normal file
5
03-birthday/convert.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
def age_to_time(age):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def birthday_to_time(birthday):
|
||||||
|
pass
|
23
04-mcnugget-numbers/README.md
Normal file
23
04-mcnugget-numbers/README.md
Normal file
@ -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`.
|
0
04-mcnugget-numbers/mcnugget.py
Normal file
0
04-mcnugget-numbers/mcnugget.py
Normal file
14
05-sum_of_divisors/README.md
Normal file
14
05-sum_of_divisors/README.md
Normal file
@ -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!
|
14
05-sum_of_divisors/wtf.py
Normal file
14
05-sum_of_divisors/wtf.py
Normal file
@ -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
|
41
06-binary-converter/README.md
Normal file
41
06-binary-converter/README.md
Normal file
@ -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)
|
16
06-binary-converter/binary-converter.py
Normal file
16
06-binary-converter/binary-converter.py
Normal file
@ -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"
|
Loading…
x
Reference in New Issue
Block a user