Skip to content

Commit

Permalink
get rid of all warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristian Rother committed Jan 3, 2024
1 parent 7b8a63d commit 04dd796
Show file tree
Hide file tree
Showing 24 changed files with 382 additions and 390 deletions.
46 changes: 0 additions & 46 deletions challenges/backpack_problem.md

This file was deleted.

58 changes: 58 additions & 0 deletions challenges/backpack_problem.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Backpack Problem
================

**🎯 Optimize the value of a heist.**

.. figure:: burglar.png
:alt: Burglar


A burglar broke into a villa. There he finds so many valuables that he
can’t put them all in his backpack. Write a program that makes an
optimal selection.

The burglar is an experienced professional who can estimate the market
value and size of each item in no time:

================ ==== ======
item size value
================ ==== ======
laptop 2 600,-
cutlery 2 400,-
spotify speakers 3 300,-
jewels 2 1100,-
vase 5 700,-
camera 2 500,-
painting 4 900,-
cash 1 800,-
================ ==== ======

The backpack has a capacity of ``8``.

When your program manages to pack items worth ``3000``, it can be used
as an app for amateur burglars.

Hints
-----

- the optimal solution uses **dynamic programming**.

Use the following pseudocode:

1. create an empty list that will include the best combination(s) of
items for each backpack size
2. insert an empty combination for a size 0 backpack
3. start with a size 1 backpack
4. copy the best combination for the current size from the previous
size, store it as ``current best``
5. go through all objects
6. create a new combination usign an item plus the best combination for
the space remaining
7. if the combination is more valuable than the ``current best``,
replace ``current best`` by the new combination
8. if the combination is worth the same amount, save both
9. increase the size of the backpack by 1
10. repeat step 4 until you reach the desired size
11. print the best combination for the desired size

*Translated with* `www.DeepL.com <https://www.DeepL.com/Translator>`__
2 changes: 1 addition & 1 deletion challenges/binary_search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ only one extra recursion is necessary.
Visual Explanation
------------------

.. figure:: .binary-search.png
.. figure:: binary-search.png
:alt: BINÄRY SEARCH

*source: idea-instructions.com, CC-BY-NC-SA 4.0*
Expand Down
63 changes: 0 additions & 63 deletions challenges/blockchain.md

This file was deleted.

80 changes: 80 additions & 0 deletions challenges/blockchain.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Blockchain
==========

**🎯 Implement your own blockchain algorithm.**

Step 1
------

Write a function that generates random transactions in the format
``(name1, name2, amount)``.

We want to save these transactions *forgery-proof*, so that they are as
difficult to manipulate as possible afterwards.

Step 2
------

Define a data type *"Block"* that contains the following:

- The hash of a previous block
- Some transactions
- A checksum (any number or string)

Step 3
------

Write a function that calculates a hash from all properties of a block.
To do this, represent the entire block as a string. Use the hash
function ``sha256``:

::

import hashlib

h = hashlib.sha256()
h.update(text.encode())
print(h.hexdigest())

Step 4
------

Create the blockchain as an empty list.

Create the first block, the "Genesis block". Use ‘genesis’ as previous
hash. Place some random transactions in the block.

Find a checksum so that the *sha256-hexdigest* ends with four zeros
(``0000``). You may need to try many checksums.

Add the finished block to the blockchain.

Step 5
------

Create the second block:

- The hash is the ``hexdigest`` of the previous block
- Add more transactions.
- Again find a checksum that generates a ``hexdigest`` with four zeros
at the end.
- Add the finished block to the blockchain.

Step 6
------

Generate more blocks.

Questions
---------

- What happens if the number of necessary zeros in the hex digest is
set to 2 or 6?
- What happens if someone changes a transaction in the Genesis block?
- What makes the blockchain forgery-proof?
- How could a blockchain still be forged?
- Why is finding the checksum also called *"proof of work"*?
- Why are several computers involved in a blockchain?
- What is a *"consensus algorithm"*?

*Translated with* `www.DeepL.com <https://www.DeepL.com/Translator>`__
26 changes: 0 additions & 26 deletions challenges/dice/dice.md

This file was deleted.

2 changes: 1 addition & 1 deletion challenges/dice/dice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Hints
:alt: dice faces


*Translated with*\ `www.DeepL.com <https://www.DeepL.com/Translator>`__
*Translated with* `www.DeepL.com <https://www.DeepL.com/Translator>`__
25 changes: 0 additions & 25 deletions challenges/magic_square.md

This file was deleted.

29 changes: 29 additions & 0 deletions challenges/magic_square.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Magic Square
============

**🎯 Solve a magic square.**

- create a magic square with 3 \* 3 fields.
- fill the square with the numbers from 1-9
- the sum of the numbers in each row, column and diagonal shall be 15
- use each number only once
- print the finished square

Hints
-----

- Write a function that calculates all sums
- A *brute-force* approach is to try out all permutations\*
- See the ``itertools`` module

Extra Challenge
---------------

Fill a magic square with 4 \* 4 fields with the numbers 1-16 (sum 34).

If you don’t want to try all the possibilities (9!), you can describe
the magic square as a linear system of equations. The Python package
**PuLP** allows you to express the necessary equations in a very compact
way.

*Translated with* `www.DeepL.com <https://www.DeepL.com/Translator>`__
Loading

0 comments on commit 04dd796

Please sign in to comment.