Fat Python donuts and algorithms

Fat Python donuts and algorithms

The name is ridiculous, all for you, because the task of the algorithms is never enough! On the occasion of the Fat Thursday catch thematic żądanką for the solution, usually in Python (or any other programming language).

Mental effort burns calories, even after everything, you can generously reward fatty doughnut!

Donut, coffee and code… a Python recommends every day! 😉

Task 1 – theory

You want to eat as many donuts in the ” Fat Thursday. Unfortunately, previous experience tells You that a pound of buds-this is the maximum volume of Your stomach, so you have no chance to eat every taste. Your goal is to eat as many calories (on a first weight, then the sculpture 😉 ), so before you choose the flavors, analyze their weight and calorific value, to eat one’s fill.

On the table you are waiting for the donuts in various ways:

  • Bud cherry approx. 100g (252 kcal)
  • fit Bud buckwheat with prunes OK. 200 gr (205 kcal)
  • donuts with chocolate “OK”. 150 g (315 kcal)
  • the Bud with karmelowo-nut “OK”. 100 g (441 kcal)
  • oreo donut approx. 150 (630 kcal)
  • mini donuts with pudding 50g (126kcal)

For convenience, the donuts numerujesz from 0 to 5, and carefully preserve in the table

No. parcel (i) 0 1 2 3 4 5
the weight of parcel (wi) 100 200 150 100 150 50
the value of kcal(vi) 252 205 315 441 630 126

Which donut you need to eat to calorific value to be large?
To solve the problem on paper, creating an array of a problem.

(hint: use dynamic programming)

Task 2 – python: dynamic programming, the problem plecakowy

Will not in fact that year to count calories on a worksheet! Just this issue save as decision-making other zero-jedynkowy problem plecakowy (0-1 Knapsack Problem). Create a program that implements a dynamic programming algorithm (optional: greedy algorithm).

  • Allow user to enter the unique capacity of the stomach (b), and elements doughnuts (weight and energy value) from the keyboard.
  • Allow the user to load data from a file. The format must be defined and explained in the beginning.
  • The program must be sustainable for major errors (e.g., reading data about the bad taste, for example, calories given as a string).

Check your program manually, or you can write a generator of donuts.

For those wishing time comparison of the algorithm is dynamic (compare only the performance of the algorithms for reading the data or display data).

The fact that you are doing here, what are you willing, aren’t you?

The author of illustrations – Berry Wielbacka (artneko.pl)
python snake loves donuts ❤

Ready to see us in action:

More To Explore

Enable registration in settings - general
Have any project in mind?

Contact us: