From bc46c80b02105d58c5d972207880bddb2654e574 Mon Sep 17 00:00:00 2001 From: william Date: Sun, 3 Jan 2016 11:25:02 -0500 Subject: [PATCH] stuff to do --- 01-title_case/README.md | 26 +++++++++ 01-title_case/title.py | 15 +++++ 02-currency/README.md | 18 ++++++ 02-currency/currency.py | 35 ++++++++++++ 03-roman-numerals/README.md | 16 ++++++ .../__pycache__/roman.cpython-34.pyc | Bin 0 -> 1213 bytes 03-roman-numerals/roman.py | 18 ++++++ 04-matrix-sort/README.md | 28 +++++++++ 04-matrix-sort/row_col_sort.py | 0 05-caesar-cipher/README.md | 54 ++++++++++++++++++ 05-caesar-cipher/caesar.py | 9 +++ 11 files changed, 219 insertions(+) create mode 100644 01-title_case/README.md create mode 100755 01-title_case/title.py create mode 100644 02-currency/README.md create mode 100644 02-currency/currency.py create mode 100644 03-roman-numerals/README.md create mode 100644 03-roman-numerals/__pycache__/roman.cpython-34.pyc create mode 100644 03-roman-numerals/roman.py create mode 100644 04-matrix-sort/README.md create mode 100644 04-matrix-sort/row_col_sort.py create mode 100644 05-caesar-cipher/README.md create mode 100644 05-caesar-cipher/caesar.py diff --git a/01-title_case/README.md b/01-title_case/README.md new file mode 100644 index 0000000..3d851fd --- /dev/null +++ b/01-title_case/README.md @@ -0,0 +1,26 @@ +Title Transform +=============== + +Write a function that transforms a string into [title case](http://en.wikipedia.org/wiki/Letter_case#Headings_and_publication_titles). + +This mostly means capitalizing only every first letter of every word in the string. + +However, there are some non-obvious exceptions to title case which can't easily be hard-coded. Your function must accept, as a second argument, a set or list of words that should not be capitalized. + +Furthermore, the first word of every title should always have a capital leter. For example: +```python +exceptions = ['jumps', 'the', 'over'] +titlecase('the quick brown fox jumps over the lazy dog', exceptions) +``` +This should return: + + The Quick Brown Fox jumps over the Lazy Dog + +An example from the Wikipedia page: +```python + exceptions = ['are', 'is', 'in', 'your', 'my'] + titlecase('THE vitamins ARE IN my fresh CALIFORNIA raisins', exceptions) +``` +Returns: + + The Vitamins are in my Fresh California Raisins diff --git a/01-title_case/title.py b/01-title_case/title.py new file mode 100755 index 0000000..0356135 --- /dev/null +++ b/01-title_case/title.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +def titlecase( string, exceptions ): + word_list = string.lower().split(' ') + + for i, word in enumerate( word_list ): + if( word not in exceptions ): + word_list[i] = word.title() + + word_list[0] = word_list[0].title() + + return ' '.join( word_list ) + +assert( titlecase( 'the quick brown fox jumps over the lazy dog', ['jumps', 'the', 'over'] ) == 'The Quick Brown Fox jumps over the Lazy Dog' ) +assert( titlecase( 'THE vitamins ARE IN my fresh CALIFORNIA raisins', ['are', 'is', 'in', 'your', 'my'] ) == 'The Vitamins are in my Fresh California Raisins' ) diff --git a/02-currency/README.md b/02-currency/README.md new file mode 100644 index 0000000..871b5ad --- /dev/null +++ b/02-currency/README.md @@ -0,0 +1,18 @@ +Float to Currency +================== + +Write a method that gives the number of American coins and bills needed to represent that number (rounded to the nearest 1/100, i.e. the nearest penny). + +As an exmaple, if the float is 12.33, the result would be 1 $10, 2 $1 bills, 1 quarter, 1 nickel and 3 pennies. + +Use the following as denominations for your currencies: + + Penny: 1 cent + Nickel: 5 cent + Dime: 10 cent + Quarter: 25 cent + One-dollar bill + Five-dollar bill + Ten-dollar bill + Fifty-dollar bill + Hundred-dollar bill diff --git a/02-currency/currency.py b/02-currency/currency.py new file mode 100644 index 0000000..28fb718 --- /dev/null +++ b/02-currency/currency.py @@ -0,0 +1,35 @@ +denominations_USD = [ + { 'title': 'Hundred-dollar bill', 'count': 0, 'val': 10000 }, + { 'title': 'Fifty-dollar bill', 'count': 0, 'val': 5000 }, + { 'title': 'Ten-dollar bill', 'count': 0, 'val': 1000 }, + { 'title': 'Five-dollar bill', 'count': 0, 'val': 500 }, + { 'title': 'One-dollar bill', 'count': 0, 'val': 100 }, + { 'title': 'Quarter', 'count': 0, 'val': 25 }, + { 'title': 'Dime', 'count': 0, 'val': 10 }, + { 'title': 'Nickel', 'count': 0, 'val': 5 }, + { 'title': 'penny', 'count': 0, 'val': 1 } +] + +def currency_converter( amount=0, units=[] ): + amount *= 100 + + for unit in units: + while( amount != 0 and amount >= unit['val'] ): + amount -= unit['val'] + unit['count'] += 1 + + return units + +def currency_display( amount=0, units=denominations_USD ): + units = currency_converter( amount , units ) + + for unit in units: + if unit['count'] == 0: continue + + t = [ unit['count'], unit['title'], '\'s' if unit['count'] > 1 else '' ] + print( '{} {}{}'.format(*t) ) + + return None + +currency_amount = float( input('Convert: ') ) +currency_display( currency_amount ) diff --git a/03-roman-numerals/README.md b/03-roman-numerals/README.md new file mode 100644 index 0000000..88d96a2 --- /dev/null +++ b/03-roman-numerals/README.md @@ -0,0 +1,16 @@ +Arabic to Roman Numerals Challenge +================================== + +Did you know our numeral system - the symbols we use to represent numbers are called +Arabic numerals? Fun fact, because now it gets serious. You're going to be translating Arabic to Italian. + +Have the input form accept a number from the user. When the form is submitted, have the function to_roman take an integer as an argument and return a roman numerals string. For example: +``` +60 >> LX +78 >> LXXVIII +99 >> XCIX +3000 >>> MMM +``` +Look up Roman Numerals to get a complete list and jog your memory on its ancient conventions. This is an easy challenge to code, but can be a difficult mental exercise. Don't overcomplicate it! + +Add your own assert statements to the bottom to test your code. diff --git a/03-roman-numerals/__pycache__/roman.cpython-34.pyc b/03-roman-numerals/__pycache__/roman.cpython-34.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f65588edb18d5fdfd09371e3f0622c08f63749ec GIT binary patch literal 1213 zcmZWo%Wl&^6umQXo=ww7)KVTrRY5{oq#>v(tyEQ@fFM%HrlPg1BFl}3Hm&WX~n5g7C z$Lotrkjt3hccXIH@kQmd?Rjm-uj~(cqH-XG2=<-UaacYT;<#FNoxy5FoC(=#ha#+0 z%Q|~G==(xCURcr7mF_?#HKRs_WDi)1;owC!#d2(p5A*Sv^<}JfhZH+^i3a)#_4s*y(%jk`%qZ z43^A#w5ipGIV`R{yrwqHs7Y$NVVXPjdVRR?c>TX6TG3l4$>nf%_1Y3VLM_T-n6pcp8R6_S&7`xs)9_W}G%nl6#fejQh2vTR?@( O7xJu_$nv`^zW)ODDG8_m literal 0 HcmV?d00001 diff --git a/03-roman-numerals/roman.py b/03-roman-numerals/roman.py new file mode 100644 index 0000000..6d1eb25 --- /dev/null +++ b/03-roman-numerals/roman.py @@ -0,0 +1,18 @@ +# Use this function to get and return all the prime numbers below the input number + +def to_roman(num): + pass + + + + + + + +assert to_roman(11) == "XI", "11 should return XI" +assert to_roman(60) == "LX", "60 should return LX" +assert to_roman(78) == "LXXVIII", "78 should return LXXVIII" +assert to_roman(4) == "IV", "4 should return IV" +assert to_roman(99) == "XCIX", "99 should return XCIX" + +# Add your own assert tests below diff --git a/04-matrix-sort/README.md b/04-matrix-sort/README.md new file mode 100644 index 0000000..407b33b --- /dev/null +++ b/04-matrix-sort/README.md @@ -0,0 +1,28 @@ +Row and Column Sorting +======================== + +Write a program that reads a matrix of numbers separated by newlines and whitespace, like this: + + 10 5 4 20 + 9 33 27 16 + 11 6 55 3 + +then calculates the sums for each row and column. For our example above: + + Row Sums: 39 85 75 + Column Sums: 30 44 86 39 + +then prints two new matrices, one where the rows are sorted by their sums (ascending from top to bottom) and one where the columns are sorted by their sums (ascending from left to right). The correct output from the example above: + + 10 5 4 20 + 11 6 55 3 + 9 33 27 16 + + 10 20 5 4 + 9 16 33 27 + 11 3 6 55 + + +Find the large input matrix to import and test your program on inside `testmatrix.txt`. + +For bonus points, format your output matrices nicely (align the columns, draw boxes with - and |...) \ No newline at end of file diff --git a/04-matrix-sort/row_col_sort.py b/04-matrix-sort/row_col_sort.py new file mode 100644 index 0000000..e69de29 diff --git a/05-caesar-cipher/README.md b/05-caesar-cipher/README.md new file mode 100644 index 0000000..588f66e --- /dev/null +++ b/05-caesar-cipher/README.md @@ -0,0 +1,54 @@ +Caesar's Cipher +================ + +[Caesar's Cipher](http://en.wikipedia.org/wiki/Caesar_cipher) is named after Julius Caesar, who used it with a shift of three to protect messages of military significance. + +A shift of three to the right would change the letters thusly: + + A => D + B => E + C => F + ... + Z => C + +A shift of three to the left would change the letters... + + A => X + B => Y + C => Z + D => A + ... + +Of course this offers no communication security whatsoever - except in Roman times when most people couldn't read to begin with. + +But the Caesar Cipher is [still used](http://en.wikipedia.org/wiki/ROT13) in cryptography, in addition to many other methods. So this is your first step into the world of security and data encryption. + +To understand how to complete this challenge, you must first understand the [ASCII](http://en.wikipedia.org/wiki/ASCII) standard. In short, every key on your keyboard has an [assigned numeric value](http://www.asciitable.com/). + +In Python, we use the following methods to get the ASCII decimal value. +```python + ord('a') # => 97 + ord('A') # => 65 + ord('x') # => 120 +``` + +To get the ASCII character from an integer, we use the `chr` function. +```python + chr(97) # => 'a' + chr(65) # => 'A' + chr(32) # => ' ' (Yes that's an empty space, it has a value too!) +``` + +#### Round 1 + +Write the `caesar` function that takes a message and a shifted number as input and returns the shifted message. + +#### Round 2 +Make sure you ignore spaces, symbols, and numbers. The end user wants to see these characters unchanged in the encrypted cipher. Capital letters should remain capital, and lower case letters should remain lower case. + +#### Round 3 +Create a new decrypt function. Take an already encrypted string, and the shift number, and decrypt it back to English. + +#### Round 4 + +Using Python's `assert` write at least 6 tests to test your code output. diff --git a/05-caesar-cipher/caesar.py b/05-caesar-cipher/caesar.py new file mode 100644 index 0000000..2452c2a --- /dev/null +++ b/05-caesar-cipher/caesar.py @@ -0,0 +1,9 @@ +def caesar(message, shift): + pass + + + + + + +# Add your own assert statements to test your code. \ No newline at end of file