From 94ba658dd384bdb55fae32473421a934bc29277d Mon Sep 17 00:00:00 2001 From: Kristian Rother Date: Wed, 3 Jan 2024 10:18:35 +0100 Subject: [PATCH] style improvements --- README.md | 122 ---------------------------- challenges/anagrams.md | 28 ------- challenges/anagrams.rst | 35 ++++++++ challenges/baby_name_generator.md | 14 ---- challenges/baby_name_generator.rst | 18 ++++ challenges/birthdays.md | 20 ----- challenges/birthdays.rst | 24 ++++++ challenges/checker.md | 21 ----- challenges/checker.rst | 23 ++++++ challenges/ctree.md | 11 --- challenges/ctree.rst | 13 +++ challenges/encrypt.md | 44 ---------- challenges/encrypt.rst | 58 +++++++++++++ challenges/fizzbuzz.md | 16 ---- challenges/fizzbuzz.rst | 17 ++++ challenges/gcd.md | 18 ---- challenges/gcd.rst | 26 ++++++ challenges/palindrome.md | 26 ------ challenges/palindrome.rst | 33 ++++++++ challenges/pyramid.md | 23 ------ challenges/pyramid.rst | 28 +++++++ challenges/querprodukt.md | 27 ------ challenges/querprodukt.rst | 31 +++++++ challenges/quiz.md | 33 -------- challenges/quiz.rst | 36 ++++++++ challenges/roman.md | 29 ------- challenges/roman.rst | 36 ++++++++ challenges/seven_peaks.md | 21 ----- challenges/spiral.md | 37 --------- challenges/spiral.rst | 46 +++++++++++ challenges/text_adventure/README.md | 31 +------ challenges/tictac.md | 20 ----- challenges/tictac.rst | 24 ++++++ conf.py | 2 +- index.rst | 30 +++---- 35 files changed, 465 insertions(+), 556 deletions(-) delete mode 100644 challenges/anagrams.md create mode 100644 challenges/anagrams.rst delete mode 100644 challenges/baby_name_generator.md create mode 100644 challenges/baby_name_generator.rst delete mode 100644 challenges/birthdays.md create mode 100644 challenges/birthdays.rst delete mode 100644 challenges/checker.md create mode 100644 challenges/checker.rst delete mode 100644 challenges/ctree.md create mode 100644 challenges/ctree.rst delete mode 100644 challenges/encrypt.md create mode 100644 challenges/encrypt.rst delete mode 100644 challenges/fizzbuzz.md create mode 100644 challenges/fizzbuzz.rst delete mode 100644 challenges/gcd.md create mode 100644 challenges/gcd.rst delete mode 100644 challenges/palindrome.md create mode 100644 challenges/palindrome.rst delete mode 100644 challenges/pyramid.md create mode 100644 challenges/pyramid.rst delete mode 100644 challenges/querprodukt.md create mode 100644 challenges/querprodukt.rst delete mode 100644 challenges/quiz.md create mode 100644 challenges/quiz.rst delete mode 100644 challenges/roman.md create mode 100644 challenges/roman.rst delete mode 100644 challenges/seven_peaks.md delete mode 100644 challenges/spiral.md create mode 100644 challenges/spiral.rst delete mode 100644 challenges/tictac.md create mode 100644 challenges/tictac.rst diff --git a/README.md b/README.md index d51c608..a982f5d 100644 --- a/README.md +++ b/README.md @@ -11,128 +11,6 @@ Pick an exercise and start programming! There is a live site on [www.academis.eu/python_basics/](http://www.academis.eu/python_basics/) ----- - -## First Steps - -| Chapter | Difficulty | -|-----------|---------------| -| [Installing Python](https://github.com/krother/Python3_Basics_Tutorial/blob/master/first_steps/installing_python.rst) | ⭐ | -| [Python as a calculator](https://github.com/krother/Python3_Basics_Tutorial/blob/master/first_steps/python_shell.rst) | ⭐ | -| [Hello World](https://github.com/krother/Python3_Basics_Tutorial/blob/master/first_steps/hello.rst) | ⭐ | -| [Ada Lovelace](https://github.com/krother/Python3_Basics_Tutorial/blob/master/first_steps/type_conversions.rst) | ⭐ | -| [Rock-Paper-Scissors](https://github.com/krother/Python3_Basics_Tutorial/blob/master/first_steps/rock_paper_scissors.rst) | ⭐ | -| [Square Numbers](https://github.com/krother/Python3_Basics_Tutorial/blob/master/first_steps/for.rst) | ⭐ | -| [Slideshow](https://github.com/krother/Python3_Basics_Tutorial/blob/master/first_steps/slideshow.rst) | ⭐ | - ----- - -## Data Structures - -| Chapter | Difficulty | -|-----------|---------------| -| [Strings](https://github.com/krother/Python3_Basics_Tutorial/blob/master/data_structures/strings.md) | ⭐ | -| [Lists](https://github.com/krother/Python3_Basics_Tutorial/blob/master/data_structures/lists.md) | ⭐ | -| [Dictionaries](https://github.com/krother/Python3_Basics_Tutorial/blob/master/data_structures/dictionaries.md) | ⭐⭐ | -| [Nested Lists](https://github.com/krother/Python3_Basics_Tutorial/blob/master/data_structures/tables.md) | ⭐⭐ | -| [Data Types Overview](https://github.com/krother/Python3_Basics_Tutorial/blob/master/reference/data_types.rst) | ⭐ | - ----- - -## Tabular Data - -| Challenge | Difficulty | -|-----------|---------------| -| [Reading a text file](https://github.com/krother/Python3_Basics_Tutorial/blob/master/tabular_data/readfile.md) | ⭐ | -| [Extracting data from text](https://github.com/krother/Python3_Basics_Tutorial/blob/master/tabular_data/parsing.md) | ⭐ | -| [Writing files](https://github.com/krother/Python3_Basics_Tutorial/blob/master/tabular_data/writing_files.md) | ⭐ | -| [Create a Time Series](https://github.com/krother/Python3_Basics_Tutorial/blob/master/tabular_data/time_series.md) | ⭐ | -| [Working with directories](https://github.com/krother/Python3_Basics_Tutorial/blob/master/tabular_data/os.md) | ⭐ | - ----- - -## Program Structures - -| Chapter | Difficulty | -|-----------|---------------| -| [Conditional Loops](https://github.com/krother/Python3_Basics_Tutorial/blob/master/reference/while.rst) | ⭐ | -| [Writing your own Functions](https://github.com/krother/Python3_Basics_Tutorial/blob/master/structure/functions.md) | ⭐⭐ | -| [Shortcuts](https://github.com/krother/Python3_Basics_Tutorial/blob/master/structure/builtin_functions.md) | ⭐⭐ | - - ----- - -# Challenges - -| Challenge | Difficulty | -|-----------|---------------| -| [Christmas Tree](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/ctree.md) | ⭐ | -| [Pyramid](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/pyramid.md) | ⭐ | -| [Fizz-Buzz-Test](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/fizzbuzz.md) | ⭐ | -| [Tic-Tac-Toe](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/tictac.md) | ⭐⭐ | -| [Checkerboard](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/checker.md) | ⭐⭐ | - -## Text processing - -| Challenge | Difficulty | -|-----------|---------------| -| [Palindrome](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/palindrome.md) | ⭐⭐ | -| [Anagrams](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/anagrams.md) | ⭐⭐ | -| [Roman Numbers](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/roman.md) | ⭐⭐⭐ | -| [Encryption](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/encrypt.md) | ⭐⭐⭐ | -| [Minesweeper](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/minesweeper.md) | ⭐⭐⭐ | - -## Math Problems - -| Challenge | Difficulty | -|-----------|---------------| -| [Factorials](challenges/factorials.md) | ⭐ | -| [Common Divisor](challenges/ggt.md) | ⭐ | -| [Fibonacci](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/fibonacci.md) | ⭐⭐ | -| [Multiplicative Digital Root](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/querprodukt.md) | ⭐⭐ | -| [Birthday Problem](https://github.com/krother/Python3_Basics_Tutorial/blob/master/challenges/birthdays.md) | ⭐⭐ | - -## Algorithms - -| Challenge | Difficulty | -|-----------|---------------| -| [Binary Search](algorithms/binary_search.md) | ⭐ | -| [Sorting Algorithms](algorithms/sorting.md) | ⭐ | -| [Chained List](algorithms/chained_list.md) | ⭐⭐ | -| [Josephus' Problem](algorithms/josephus.md) | ⭐⭐ | -| [Tree Traversal](algorithms/tree_traversal.md) | ⭐⭐ | -| [Graph Traversal](algorithms/graph_traversal.md) | ⭐⭐⭐ | -| [Magic Square](algorithms/magic_square.md) | ⭐⭐⭐ | -| [Traveling Salesman](algorithms/tsp.md) | ⭐⭐⭐ | -| [Backpack Problem](algorithms/backpack_problem.md) | ⭐⭐⭐⭐ | -| [Blockchain](algorithms/blockchain.md) | ⭐⭐⭐⭐ | - -## Web Development - -| Challenge | Difficulty | -|-----------|---------------| -| [Ping Pong](web/pingpong.md) | ⭐⭐ | -| [Google Search](web/google.md) | ⭐⭐⭐ | -| [Download Web Pages](web/webrecherche.md) | ⭐⭐⭐ | - ----- - -## More about Python - -* [Recap Questions](recap.md) -* [Modules](structure/modules.md) -* [Introspection](structure/introspection.md) -* [Background information on Python 3](appendix/background_info.md) - ----- - -## Appendix - -* [Recommended books and websites](https://github.com/krother/Python3_Basics_Tutorial/blob/master/appendix/links.md) -* [Learning Goals](appendix/goals.md) - ----- - ## License diff --git a/challenges/anagrams.md b/challenges/anagrams.md deleted file mode 100644 index 1850e3c..0000000 --- a/challenges/anagrams.md +++ /dev/null @@ -1,28 +0,0 @@ - -# Anagrams - -**🎯 Generate all anagrams of a word with 3-6 letters.** - -For example, the string: - - ROT - -has the anagrams (permutations of characters): - - TOR - ORT - TRO - RTO - OTR - -## Hints - -* Look up the function `itertools.permutations()`. -* You may need an expression like `''.join(["T", "O", "R"])` - -## Extra challenges - -* Get yourself a word list. Find anagrams that are real words. -* Implement the algorithm to generate the anagrams yourself. Get informed about **dynamic programming**. - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/anagrams.rst b/challenges/anagrams.rst new file mode 100644 index 0000000..55ac2a8 --- /dev/null +++ b/challenges/anagrams.rst @@ -0,0 +1,35 @@ +Anagrams +======== + +**🎯 Generate all anagrams of a word with 3-6 letters.** + +For example, the string: + +:: + + ROT + +has the anagrams (permutations of characters): + +:: + + TOR + ORT + TRO + RTO + OTR + +Hints +----- + +- Look up the function ``itertools.permutations()``. +- You may need an expression like ``''.join(["T", "O", "R"])`` + +Extra challenges +---------------- + +- Get yourself a word list. Find anagrams that are real words. +- Implement the algorithm to generate the anagrams yourself. Get + informed about **dynamic programming**. + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/baby_name_generator.md b/challenges/baby_name_generator.md deleted file mode 100644 index f90b1d9..0000000 --- a/challenges/baby_name_generator.md +++ /dev/null @@ -1,14 +0,0 @@ -# Baby Name Generator - -**🎯 Write a baby name generator for undecided parents.** - -Use the function `random.choice()` from the [random module](https://docs.python.org/3/library/random.html#module-random). - -## Extra Challenges: - -* The program randomly outputs a name from a predefined list. -* The program randomly outputs a name from the [US civil register](http://www.ssa.gov/oact/babynames/limits.html) -* The user can select either a boy's or girl's name -* The programme makes 10 proposals - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/baby_name_generator.rst b/challenges/baby_name_generator.rst new file mode 100644 index 0000000..5061547 --- /dev/null +++ b/challenges/baby_name_generator.rst @@ -0,0 +1,18 @@ +Baby Name Generator +=================== + +**🎯 Write a baby name generator for undecided parents.** + +Use the function ``random.choice()`` from the `random +module `__. + +Extra Challenges: +----------------- + +- The program randomly outputs a name from a predefined list. +- The program randomly outputs a name from the `US civil + register `__ +- The user can select either a boy’s or girl’s name +- The programme makes 10 proposals + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/birthdays.md b/challenges/birthdays.md deleted file mode 100644 index 50749cf..0000000 --- a/challenges/birthdays.md +++ /dev/null @@ -1,20 +0,0 @@ - -# Birthday Problem - -**🎯 Calculate probabilities** - -You're at a party. There are a total of N people present. Calculate how likely it is that at least two people will have a birthday on the same day. - -## Hints - -* there are at least two people at the party -* assume that birthdays occur on all days of the year with the same probability. -* ignore leap years - -## Questions - -* How many people have to be there for a >50% or >90% chance? -* What is the probability that there are two or more pairs? -* consider when the assumption that all days have the same probability makes sense - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/birthdays.rst b/challenges/birthdays.rst new file mode 100644 index 0000000..adb3617 --- /dev/null +++ b/challenges/birthdays.rst @@ -0,0 +1,24 @@ +Birthday Problem +================ + +**🎯 Calculate probabilities** + +You’re attending a party with N guests. +Calculate how likely it is that at least two of them will have a birthday on the same day. + +Hints +----- + +- there are at least two people at the party +- assume that birthdays occur on all days of the year with the same probability. +- ignore leap years + +Questions +--------- + +- How many people have to be there for a >50% or >90% chance? +- What is the probability that there are two or more pairs? +- consider when the assumption that all days have the same probability + makes sense + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/checker.md b/challenges/checker.md deleted file mode 100644 index 5699983..0000000 --- a/challenges/checker.md +++ /dev/null @@ -1,21 +0,0 @@ - -# Checkerboard - -**🎯 Write a program that outputs a chess board with 8 * 8 squares:** - - #_#_#_#_ - _#_#_#_# - #_#_#_#_ - _#_#_#_# - #_#_#_#_ - _#_#_#_# - #_#_#_#_ - - -## Extra Challenges - -* use a single `print()` statement -* the characters `#` and `_` occur only once in the program -* do not use the assignment operator `=` - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/checker.rst b/challenges/checker.rst new file mode 100644 index 0000000..85a9d4a --- /dev/null +++ b/challenges/checker.rst @@ -0,0 +1,23 @@ +Checkerboard +============ + +**🎯 Write a program that outputs a chess board with 8 \* 8 squares:** + +:: + + #_#_#_#_ + _#_#_#_# + #_#_#_#_ + _#_#_#_# + #_#_#_#_ + _#_#_#_# + #_#_#_#_ + +Extra Challenges +---------------- + +- use a single ``print()`` statement +- the characters ``#`` and ``_`` occur only once in the program +- do not use the assignment operator ``=`` + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/ctree.md b/challenges/ctree.md deleted file mode 100644 index 73dae9b..0000000 --- a/challenges/ctree.md +++ /dev/null @@ -1,11 +0,0 @@ - -# Christmas Tree - -**🎯 Write a program that outputs the following image:** - - * - *** - ***** - ******* - ********* - *********** diff --git a/challenges/ctree.rst b/challenges/ctree.rst new file mode 100644 index 0000000..b600118 --- /dev/null +++ b/challenges/ctree.rst @@ -0,0 +1,13 @@ +Christmas Tree +============== + +**🎯 Write a program that outputs the following image:** + +:: + + * + *** + ***** + ******* + ********* + *********** diff --git a/challenges/encrypt.md b/challenges/encrypt.md deleted file mode 100644 index 253805f..0000000 --- a/challenges/encrypt.md +++ /dev/null @@ -1,44 +0,0 @@ - -# Encryption - -**🎯 Implement a simple block encryption algorithm.** - -## Step 1: Message in plain text - -Save the message to be encrypted as a string: - - s = "TOP_SECRET_MESSAGE" - -## Step 2: Format as a Table - -Break the string into several lines of equal length. -Fill in blanks at the end: - - TOP_S - ECRET - _MESS - AGE__ - -## Step 3: Encryption Key - -Use a key to sort the columns in a new order. With the key `21403` you get: - - POST_ - RCTEE - EMS_S - EG_A_ - -## Step 4: Merge Columns - -Merge the columns one after the other to a new string. This is the final encrypted message: - - POST_RCTEEEMS_SEG_A_ - -## Extra Challenges: - -* Get text that someone else coded. -* Decrypt the message with the key. -* Crack the code without the key! - - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/encrypt.rst b/challenges/encrypt.rst new file mode 100644 index 0000000..8b2a7ca --- /dev/null +++ b/challenges/encrypt.rst @@ -0,0 +1,58 @@ +Encryption +========== + +**🎯 Implement a simple block encryption algorithm.** + +Step 1: Message in plain text +----------------------------- + +Save the message to be encrypted as a string: + +.. code:: python3 + + s = "TOP_SECRET_MESSAGE" + +Step 2: Format as a Table +------------------------- + +Break the string into several lines of equal length. Fill in blanks at +the end: + +:: + + TOP_S + ECRET + _MESS + AGE__ + +Step 3: Encryption Key +---------------------- + +Use a key to sort the columns in a new order. With the key ``21403`` you +get: + +:: + + POST_ + RCTEE + EMS_S + EG_A_ + +Step 4: Merge Columns +--------------------- + +Merge the columns one after the other to a new string. This is the final +encrypted message: + +:: + + POST_RCTEEEMS_SEG_A_ + +Extra Challenges: +----------------- + +- Get text that someone else coded. +- Decrypt the message with the key. +- Crack the code without the key! + +*Translated with*\ `www.DeepL.com `__ diff --git a/challenges/fizzbuzz.md b/challenges/fizzbuzz.md deleted file mode 100644 index d7fa9ef..0000000 --- a/challenges/fizzbuzz.md +++ /dev/null @@ -1,16 +0,0 @@ - -# Fizz-Buzz-Test - -**🎯 Write a program that runs through the numbers from 1 to 100:** - -* If the number is divisible by 3, the program outputs *"Fizz"*. -* If the number is divisible by 5, the program outputs *"Buzz"*. -* If the number is divisible by 3 and 5, the program outputs *"FizzBuzz"*. -* otherwise the number is printed - -## Note - -The **Fizz Buzz Test** has often been used in coding interviews. - - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/fizzbuzz.rst b/challenges/fizzbuzz.rst new file mode 100644 index 0000000..02d0e1a --- /dev/null +++ b/challenges/fizzbuzz.rst @@ -0,0 +1,17 @@ +Fizz-Buzz-Test +============== + +**🎯 Write a program that runs through the numbers from 1 to 100:** + +- If the number is divisible by 3, the program outputs *“Fizz”*. +- If the number is divisible by 5, the program outputs *“Buzz”*. +- If the number is divisible by 3 and 5, the program outputs + *“FizzBuzz”*. +- otherwise the number is printed + +Note +---- + +The **Fizz Buzz Test** has often been used in coding interviews. + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/gcd.md b/challenges/gcd.md deleted file mode 100644 index 09c5af6..0000000 --- a/challenges/gcd.md +++ /dev/null @@ -1,18 +0,0 @@ - -# Greatest Common Denominator - -**🎯 Implement the [Euclidean Algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) to determine the greatest common denominator of two integers.** - -## Tests - -Use the following code to test your function: - - assert gcd(6, 3) == 3 - assert gcd(12, 8) == 4 - assert gcd(42, 12) == 6 - -## Hints: - -Translate the [pseudocode from the Wikipedia page](https://en.wikipedia.org/wiki/Euclidean_algorithm#Implementations) into executable code and run it. - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/gcd.rst b/challenges/gcd.rst new file mode 100644 index 0000000..2702a69 --- /dev/null +++ b/challenges/gcd.rst @@ -0,0 +1,26 @@ +Greatest Common Denominator +=========================== + +**🎯 Implement the**\ `Euclidean +Algorithm `__\ **to +determine the greatest common denominator of two integers.** + +Tests +----- + +Use the following code to test your function: + +.. code:: python3 + + assert gcd(6, 3) == 3 + assert gcd(12, 8) == 4 + assert gcd(42, 12) == 6 + +Hints: +------ + +Translate the `pseudocode from the Wikipedia +page `__ +into executable code and run it. + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/palindrome.md b/challenges/palindrome.md deleted file mode 100644 index 723bf76..0000000 --- a/challenges/palindrome.md +++ /dev/null @@ -1,26 +0,0 @@ - -# Palindrome - -**🎯 Write a function that checks whether a string is a palindrome:** - - def is_palindrome(s): - ... - -## Tests - -Test your function with this code: - - assert is_palindrome('Abba') - assert is_palindrome('kayak') - assert is_palindrome('Rats live on no evil star') - assert not is_palindrome('abc') - assert not is_palindrome('Hello world') - -## Hints - -* remove whitespace -* ignore punctuation marks -* ignore upper/lower case -* you find more [palindromes on Wikipedia](https://en.wikipedia.org/wiki/Palindrome). - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/palindrome.rst b/challenges/palindrome.rst new file mode 100644 index 0000000..6d75e6b --- /dev/null +++ b/challenges/palindrome.rst @@ -0,0 +1,33 @@ +Palindrome +========== + +**🎯 Write a function that checks whether a string is a palindrome:** + +.. code:: python3 + + def is_palindrome(s): + ... + +Tests +----- + +Test your function with this code: + +.. code:: python3 + + assert is_palindrome('Abba') + assert is_palindrome('kayak') + assert is_palindrome('Rats live on no evil star') + assert not is_palindrome('abc') + assert not is_palindrome('Hello world') + +Hints +----- + +- remove whitespace +- ignore punctuation marks +- ignore upper/lower case +- you find more `palindromes on + Wikipedia `__. + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/pyramid.md b/challenges/pyramid.md deleted file mode 100644 index 18781f0..0000000 --- a/challenges/pyramid.md +++ /dev/null @@ -1,23 +0,0 @@ - -# Pyramid - -**🎯 Use Python to complete the following task:** - -The Cheops pyramid in Giza consists of 2.3 million stone blocks of 3 * 3 * 2 m edge length. -It was built within 20 years. The four basic edges of the pyramid are 130 m long, the pyramid is 147 m high. - -## Questions: - -* How many stone blocks per minute had to be placed on average. -* How much time did a team of 10 workers have to bring a stone block to its destination? -* How many layers were stacked on top of each other? -* How many blocks are there in the bottom layer? - -Assume that the Egyptian working day was 14 hours long and that 20000 construction workers were on the site at the same time. - -## Extra Challenge: - -* Write a user interface so that the pharaoh can enter the desired pyramid size. - - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/pyramid.rst b/challenges/pyramid.rst new file mode 100644 index 0000000..faca437 --- /dev/null +++ b/challenges/pyramid.rst @@ -0,0 +1,28 @@ +Pyramid +======= + +**🎯 Use Python to complete the following task:** + +The Cheops pyramid in Giza consists of 2.3 million stone blocks of 3 \* +3 \* 2 m edge length. It was built within 20 years. The four basic edges +of the pyramid are 130 m long, the pyramid is 147 m high. + +Questions: +---------- + +- How many stone blocks per minute had to be placed on average. +- How much time did a team of 10 workers have to bring a stone block to + its destination? +- How many layers were stacked on top of each other? +- How many blocks are there in the bottom layer? + +Assume that the Egyptian working day was 14 hours long and that 20000 +construction workers were on the site at the same time. + +Extra Challenge: +---------------- + +- Write a user interface so that the pharaoh can enter the desired + pyramid size. + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/querprodukt.md b/challenges/querprodukt.md deleted file mode 100644 index 9f7afe0..0000000 --- a/challenges/querprodukt.md +++ /dev/null @@ -1,27 +0,0 @@ - -# Multiplicative Digital Root - -**🎯 Calculate the multiplicative digital root of a number.** - -The multiplicative digital root is the product of all digits. - -| number | MDR | -|--------|-----| -| 7 | 7 | -| 23 | 6 | -| 111 | 1 | -| 100 | 0 | -| 333 | 27 | - - -## Hints - -* Which data type is suitable for addressing the digits individually? -* Because of the commutative law, it doesn't matter in which order you multiply the numbers. - -## Extra Challenge - -* for an advanced challenge, look up the `functools.reduce` function and solve the problem with it. - - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/querprodukt.rst b/challenges/querprodukt.rst new file mode 100644 index 0000000..a20c50a --- /dev/null +++ b/challenges/querprodukt.rst @@ -0,0 +1,31 @@ +Multiplicative Digital Root +=========================== + +**🎯 Calculate the multiplicative digital root of a number.** + +The multiplicative digital root is the product of all digits. + +====== === +number MDR +====== === +7 7 +23 6 +111 1 +100 0 +333 27 +====== === + +Hints +----- + +- Which data type is suitable for addressing the digits individually? +- Because of the commutative law, it doesn’t matter in which order you + multiply the numbers. + +Extra Challenge +--------------- + +- for an advanced challenge, look up the ``functools.reduce`` function + and solve the problem with it. + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/quiz.md b/challenges/quiz.md deleted file mode 100644 index c3e7d67..0000000 --- a/challenges/quiz.md +++ /dev/null @@ -1,33 +0,0 @@ - -# Quiz - -**🎯 Write a Multiple-Choice-Quiz.** - -The player gets questions with four choices. -Depending on the input, the program outputs **CORRECT** or **WRONG**. - -### Sample output: - - Question 1: - - Who are the burglars trying to rob Duck McScrooge? - - a) Blues Brothers - b) Bagel Brothers - c) Beagle Brothers - d) Soul Brothers - - Enter your answer: c - CORRECT - - Question 2: - - What is the top speed of a swallow? - - a) 50 km/h - b) 70 km/h - c) 120 km/h - d) a European or Asian one? - - Enter your answer: - ... diff --git a/challenges/quiz.rst b/challenges/quiz.rst new file mode 100644 index 0000000..a842796 --- /dev/null +++ b/challenges/quiz.rst @@ -0,0 +1,36 @@ +Quiz +==== + +**🎯 Write a Multiple-Choice-Quiz.** + +The player gets questions with four choices. Depending on the input, the +program outputs **CORRECT** or **WRONG**. + +Sample output: +~~~~~~~~~~~~~~ + +:: + + Question 1: + + Who are the burglars trying to rob Duck McScrooge? + + a) Blues Brothers + b) Bagel Brothers + c) Beagle Brothers + d) Soul Brothers + + Enter your answer: c + CORRECT + + Question 2: + + What is the top speed of a swallow? + + a) 50 km/h + b) 70 km/h + c) 120 km/h + d) a European or Asian one? + + Enter your answer: + ... diff --git a/challenges/roman.md b/challenges/roman.md deleted file mode 100644 index 51a3cf5..0000000 --- a/challenges/roman.md +++ /dev/null @@ -1,29 +0,0 @@ - -# Roman Numbers - -**🎯 Write a function `roman2arabic()`, that translates a Roman into an Arabic number.** - -## Tests - -The following code helps you to check the results: - - def test_roman(self): - assert roman2arabic("I") == 1 - assert roman2arabic("XI") == 11 - assert roman2arabic("IX") == 9 - assert roman2arabic("CLI") == 151 - assert roman2arabic("XCIII") == 93 - assert roman2arabic("CCXCIV") == 294 - assert roman2arabic("MCM") == 1900 - assert roman2arabic("MI") == 1001 - -## Hints - -* You only have to consider numbers from 1-5000 -* Which data structure is suitable for looking up the numerical values of Roman numerals? - -## Extra Challenge - -* Write a function that converts Arabic to Roman numerals. - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/roman.rst b/challenges/roman.rst new file mode 100644 index 0000000..6a704a0 --- /dev/null +++ b/challenges/roman.rst @@ -0,0 +1,36 @@ +Roman Numbers +============= + +**🎯 Write a function ``roman2arabic()``, that translates a Roman into an +Arabic number.** + +Tests +----- + +The following code helps you to check the results: + +.. code:: python3 + + def test_roman(self): + assert roman2arabic("I") == 1 + assert roman2arabic("XI") == 11 + assert roman2arabic("IX") == 9 + assert roman2arabic("CLI") == 151 + assert roman2arabic("XCIII") == 93 + assert roman2arabic("CCXCIV") == 294 + assert roman2arabic("MCM") == 1900 + assert roman2arabic("MI") == 1001 + +Hints +----- + +- You only have to consider numbers from 1-5000 +- Which data structure is suitable for looking up the numerical values + of Roman numerals? + +Extra Challenge +--------------- + +- Write a function that converts Arabic to Roman numerals. + +*Translated with* `www.DeepL.com `__ diff --git a/challenges/seven_peaks.md b/challenges/seven_peaks.md deleted file mode 100644 index 9e3e1ba..0000000 --- a/challenges/seven_peaks.md +++ /dev/null @@ -1,21 +0,0 @@ - -## Seven Peaks - -You are looking for seven dwarven cities. -They are under the highest mountains, of course. -As you scan the horizon, you can clearly see the elevation of each mountain: - - 310 - 464 - 618 - 772 - 926 - 1080 - ... - -A peak is any elevation with two lower numbers before and after it. -Every peak hosts one of the dwarven cities. -You find the elevations in `mountains.csv`. - - -How high are the seven peaks added together? diff --git a/challenges/spiral.md b/challenges/spiral.md deleted file mode 100644 index 4cb4db6..0000000 --- a/challenges/spiral.md +++ /dev/null @@ -1,37 +0,0 @@ - -# Spiral - -**Write a program, that draws a spiral:** - -![spiral](spiral1.svg) - -When your program draws a spiral with at least 3 loops, you have mastered this challenge. - - -### What you can practise in this coding challenge - -* loops -* The **turtle** module in Python - -### Hints - -* It is sufficient to draw the spiral as a series of short lines -* Where is it easier to start (inside or outside)? -* Both the Python modules `Pillow` and `turtle` are up to the task - -### Getting started - -If you have no idea where to start, try the following Python script: - - from turtle import forward, left - forward(50) - left(90) - forward(50) - -### Optional goals - -* the line width grows thicker from the inside to the outside -* there is a color gradient along the spiral -* draw the **Fibonacci spiral** instead - -![Spiral with width and color](spiral2.svg) diff --git a/challenges/spiral.rst b/challenges/spiral.rst new file mode 100644 index 0000000..722a4bb --- /dev/null +++ b/challenges/spiral.rst @@ -0,0 +1,46 @@ +Spiral +====== + +**Write a program, that draws a spiral:** + +.. figure:: spiral1.svg + :alt: spiral + +When your program draws a spiral with at least 3 loops, you have +mastered this challenge. + +What you can practise in this coding challenge +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- loops +- The **turtle** module in Python + +Hints +~~~~~ + +- It is sufficient to draw the spiral as a series of short lines +- Where is it easier to start (inside or outside)? +- Both the Python modules ``Pillow`` and ``turtle`` are up to the task + +Getting started +~~~~~~~~~~~~~~~ + +If you have no idea where to start, try the following Python script: + +.. code:: python3 + + from turtle import forward, left + + forward(50) + left(90) + forward(50) + +Extra Challenge +~~~~~~~~~~~~~~~ + +- the line width grows thicker from the inside to the outside +- there is a color gradient along the spiral +- draw the **Fibonacci spiral** instead + +.. figure:: spiral2.svg + :alt: Spiral with width and color diff --git a/challenges/text_adventure/README.md b/challenges/text_adventure/README.md index 6467ce4..ee6470b 100644 --- a/challenges/text_adventure/README.md +++ b/challenges/text_adventure/README.md @@ -3,11 +3,10 @@ **🎯 Implement a text adventure.** ----- ## The Story -![](images/dragon_egg.png) +![](dragon_egg.png) Far, far away, in an hardly accessible landscape, the mystic dragon egg lies hidden.. Will you find the egg and awaken the life within? @@ -21,7 +20,6 @@ Will you find the egg and awaken the life within? OK, this is not the greatest plot ever written. If you have a better one, program it! ----- ## Requirements @@ -34,11 +32,9 @@ Write a game in which you can travel around between multiple rooms (clearing, to The game is entirely text-based. ----- ## Example Output - :::text Find the Dragon Egg =================== @@ -61,7 +57,6 @@ The game is entirely text-based. Your quest has been successful! ----- ## Step by Step @@ -71,14 +66,12 @@ The game is entirely text-based. * Create a Python file `adventure.py` * Open the file in an editor ----- ### Step 2: The Basic Structure Make the program produce a welcoming message. You could use an output with multiple lines: - :::python3 print(""" Find the Dragon Egg =================== @@ -88,7 +81,6 @@ You could use an output with multiple lines: At the end, the program congratulates the player to success: - :::python3 print(""" On a hidden clearing you discover the dragon egg. @@ -99,7 +91,6 @@ During the project, you will insert more code between these two instructions. **Execute the program and make sure it works.** ----- ### Step 3: The Main Loop @@ -114,20 +105,17 @@ In such situations a **conditional loop** with `while` is a good choice. First you need to define a variable that contains the current location. In Python you can use the name of the room as a string: - :::python3 room = "hometown" As soon as you reach the room *"clearing"*, the game ends. You can check that in the condition of the `while` loop: - :::python3 while room != "clearing": print(f"You are in {room}") room = input("Where would you like to go? ") **Execute the program and make sure you can finish the game.** ----- ### Step 4: Rooms @@ -136,7 +124,6 @@ Your game does not have any rooms yet, so it is hard to tell where you are. Write interesting descriptions of the rooms and print them by adding `if` instructions like the following to the main loop: - :::python3 if room == "hometown": print(""" You are in your home town. @@ -147,7 +134,6 @@ You can replace the `print()` statement from the previous step with the `if` sta **Execute the program and make sure it works.** ----- ### Step 5: Data Structure @@ -157,7 +143,6 @@ But imagine your game has 100 or more rooms – the program would become quite m A better alternative is to **structure the room data**. We will use a **dictionary** that contains descriptions of all rooms: - :::python3 descriptions = { "hometown": """You are in your home town...""", "desert": """...""", @@ -169,14 +154,12 @@ The **key** is the `room` variable. Add these commands to the `while` loop: - :::python3 print(descriptions[room]) and remove the `if` statements from step 4. **Execute the program and make sure it works.** ----- ### Step 6: Checks @@ -187,7 +170,6 @@ Let's check the input to prevent that. The following code matches the users input with the keys of the dictionary `descriptions`: - :::python3 target = input("Where do you want to go? ") if target in descriptions: room = target @@ -198,7 +180,6 @@ Find out where in the program these lines need to be inserted. **Execute the program and make sure it works.** ----- ### Step 7: Paths @@ -212,7 +193,6 @@ The game would be a lot more interesting if only some rooms were connected. For that, we need a second dictionary that contains the connections. Each entry points from one starting room to one or more targets: - :::python3 paths = { "hometown": ["beekeeper", "forest"], "forest": ["hometown", "deser"], @@ -224,30 +204,25 @@ If you leave one of them away, you also could create *one-way-streets*. The paths for the current room could be displayed with the following line: - :::python3 print(paths[room]) or somewhat more nicely with: - :::python3 print(", ".join(paths[room])) If you would like to extend the plausibility check, so that only the current paths are accessible, you need the following line: - :::python3 if target in paths[room]: ... **Execute the program and make sure it works.** ----- ### Step 8: Puzzles An interesting adventure should also contain a few puzzles. Here is how a puzzle could look like: - :::text Where would you like to go? forest There is a BEAR in the forest!!! You run away. @@ -268,19 +243,16 @@ How to implement such a puzzle? First you need a **state variable** that you define before the main loop, e.g.: - :::python3 honey = False Second, you need to check in the main loop whether the state should change, and then change it, e.g.: - :::python3 if room == "beekeeper" and not honey: print("You buy a pot of honey at the beekeeper.") honey = True Finally you need to check the state variable in the main loop to allow actions or prevent them: - :::python3 if target == "forest": if honey: print("You leave the honeypot to the bear and carefully sneak through.") @@ -289,7 +261,6 @@ Finally you need to check the state variable in the main loop to allow actions o print("There is a BEAR in the forest!!! You run away.") target = room # player stays in the same place ----- ### Final Remarks diff --git a/challenges/tictac.md b/challenges/tictac.md deleted file mode 100644 index 3b774d4..0000000 --- a/challenges/tictac.md +++ /dev/null @@ -1,20 +0,0 @@ - -# Tic-Tac-Toe - -**🎯 Find out which player won.** - -You are given a Tic-Tac-Toe playing field as a nested list: - - ttt = [['X', 'O', 'X'], - ['.', 'X', 'O'], - ['X', 'O', 'O']] - -Write a program that determines which player has three symbols in a row (or whether it is a draw). - -## Hints - -* Examine rows, columns and diagonals separately at first. -* It gets a little easier when you leave out the inner brackets. -* Test the code with several game situations. - -*Translated with [www.DeepL.com](www.DeepL.com/Translator)* diff --git a/challenges/tictac.rst b/challenges/tictac.rst new file mode 100644 index 0000000..1836a67 --- /dev/null +++ b/challenges/tictac.rst @@ -0,0 +1,24 @@ +Tic-Tac-Toe +=========== + +**🎯 Find out which player won.** + +You are given a Tic-Tac-Toe playing field as a nested list: + +:: + + ttt = [['X', 'O', 'X'], + ['.', 'X', 'O'], + ['X', 'O', 'O']] + +Write a program that determines which player has three symbols in a row +(or whether it is a draw). + +Hints +----- + +- Examine rows, columns and diagonals separately at first. +- It gets a little easier when you leave out the inner brackets. +- Test the code with several game situations. + +*Translated with* `www.DeepL.com `__ diff --git a/conf.py b/conf.py index e15e60c..97cb4ae 100644 --- a/conf.py +++ b/conf.py @@ -22,7 +22,7 @@ ] templates_path = ['_templates'] -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'learning_goals.md', 'README.md'] language = 'ls' diff --git a/index.rst b/index.rst index d722c82..a79bace 100644 --- a/index.rst +++ b/index.rst @@ -84,23 +84,23 @@ Challenges .. toctree:: :maxdepth: 1 - challenges/ctree.md - challenges/pyramid.md - challenges/fizzbuzz.md - challenges/tictac.md - challenges/quiz.md - challenges/checker.md - challenges/baby_name_generator.md - challenges/palindrome.md - challenges/anagrams.md - challenges/spiral.md - challenges/roman.md - challenges/encrypt.md + challenges/ctree.rst + challenges/pyramid.rst + challenges/fizzbuzz.rst + challenges/tictac.rst + challenges/quiz.rst + challenges/checker.rst + challenges/baby_name_generator.rst + challenges/palindrome.rst + challenges/anagrams.rst + challenges/spiral.rst + challenges/roman.rst + challenges/encrypt.rst challenges/minesweeper.md - challenges/gcd.md + challenges/gcd.rst challenges/fibonacci.md - challenges/querprodukt.md - challenges/birthdays.md + challenges/querprodukt.rst + challenges/birthdays.rst challenges/seven_peaks.rst challenges/count_words/README.md challenges/text_adventure/README.md