1---
2version: 0.1.0
3precision: 3
4form_title: Grocery Unit Price Calculator
5form_description: Compare products by price per unit. Enter price and quantity/weight to find the best value.
6form_inputs: Price A|price_a{€}, Weight A|weight_a{g}, Price B|price_b{€}, Weight B|weight_b{g}, Price C|price_c{€}, Weight C|weight_c{g}
7form_outputs: Price/100g A|unit_a, Price/100g B|unit_b, Price/100g C|unit_c, Best value|min_unit
8---
9# draftply – Grocery Unit Price Calculator
10# Which product is the best value? Compare price per 100g or per kg.
11
12# ── Product A ──────────────────────────────────────────
13price_a = 2.50 €
14weight_a = 500 g # net weight
15unit_a = price_a / weight_a * 100 g
16
17# ── Product B ──────────────────────────────────────────
18price_b = 3.20 €
19weight_b = 750 g
20unit_b = price_b / weight_b * 100 g
21
22# ── Product C ──────────────────────────────────────────
23price_c = 1.80 €
24weight_c = 250 g
25unit_c = price_c / weight_c * 100 g
26
27# ── Comparison ──────────────────────────────────────────
28# Find the best value (lowest price per 100g)
29min_ab = min(unit_a, unit_b)
30min_unit = min(min_ab, unit_c)
31
32# Price per kg for comparison
33unit_a_kg = unit_a * 10
34unit_b_kg = unit_b * 10
35unit_c_kg = unit_c * 10
36
37# Savings when buying the best option for 1kg
38# Average price per kg of the others
39min_kg_ab = min(unit_a_kg, unit_b_kg)
40min_kg = min(min_kg_ab, unit_c_kg)
41avg_others_kg = (unit_a_kg + unit_b_kg + unit_c_kg - min_kg) / 2
42
43# Cost to buy 1kg of each
44cost_1kg_a = price_a / weight_a * 1000 g
45cost_1kg_b = price_b / weight_b * 1000 g
46cost_1kg_c = price_c / weight_c * 1000 g
47
48# ── Results ─────────────────────────────────────────────
49"Product A": {weight_a} for {price_a} = {unit_a} €/100g = {cost_1kg_a} €/kg
50"Product B": {weight_b} for {price_b} = {unit_b} €/100g = {cost_1kg_b} €/kg
51"Product C": {weight_c} for {price_c} = {unit_c} €/100g = {cost_1kg_c} €/kg
52
53"Lowest price per 100g": min_unit
54
55# Price per gram for precision
56"Price per gram A": price_a / weight_a
57"Price per gram B": price_b / weight_b
58"Price per gram C": price_c / weight_c
59