[ prog / sol / mona ]

prog


[Show SBBS] How I saved the day and cooked a brioche with GNU Guile

1 2020-06-01 19:51

It says in the recipe that I need 60g of sugar but I don't have a kitchen scale (I use a measuring cup).
The problem is that I only have sugar cubes, I can't use a measuring cup with that. After fiddling with the idea of pounding sugar cubes into powdered sugar, I reckoned that, knowing the weight of the sugar box, I could use some math tricks to compute how many sugar cubes I needed. (I f*ing love science!)
I made an app that you can use if you ever find yourself in the same situation. What's terrific about this app is that it doesn't matter if you use the metric or imperial system of units, it will work the same!

(use-modules (ice-9 readline))
(use-modules (ice-9 format))
(let* ((x (string->number (readline "What's the length of your box (in sugar cubes) ")))
       (y (string->number (readline "What's the width of your box? (in sugar cubes) ")))
       (z (string->number (readline "What's the height of your box? (in sugar cubes) ")))
       (w (string->number (readline "What's the weight of your sugar box? (in units of weigth) ")))
       (q (string->number (readline "How much sugar do you need? (in units of weight) ")))
       (n (ceiling (/ (* x y z q) w)))) ; more sugar is better
  (format #t "You need ~r cubes of sugars.\nBon appetit!\n" n))

Typical session:

$ guile sugarhack.scm
What's the length of your box (in sugar cubes) 14
What's the width of your box? (in sugar cubes) 4
What's the height of your box? (in sugar cubes) 4
What's the weight of your sugar box? (in units of weigth) 1000
How much sugar do you need? (in units of weight) 60
You need fourteen cubes of sugars
Bon Appetit!
2 2020-06-01 19:56 *

Edit: actually there's only 3 rows of cubes in height, 10 cubes are enough (10.08)

3 2020-06-02 07:02 *

I knew I should have posted this on HN or Reddit to get upvotes. At least I enjoyed a luscious briouche.

Losers.

4 2020-06-13 19:07

Nice.

5 2020-08-18 15:54 *

>>3

I knew I should have posted this on HN or Reddit to get upvotes. At least I enjoyed a luscious brioche.

A half-baked post like >>1?

6


VIP:

do not edit these