From 1ccaeae174f9091ec0ac3ebc2fce991464ac29c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Tue, 16 Jul 2024 17:39:02 +0200 Subject: [PATCH] Initial commit --- go.mod | 3 +++ main.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 go.mod create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9a9693e --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module main + +go 1.22.4 diff --git a/main.go b/main.go new file mode 100644 index 0000000..e96278f --- /dev/null +++ b/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "log" +) + +func init() { + log.SetFlags(log.Lmicroseconds) +} + +type ingredient struct { + weight int + caloriesPer100 int +} + +const ( + bakingPowder = 92 + beans = 100 + butter = 717 + butter2 = 630 // Cake butter thing that's not real butter + carrots = 35 + chickenBreast = 98 + cocoa = 363 + egg = 150 + flour = 338 + hotdogs = 250 + meatRoll = 210 + olives = 151 + pastaSauce = 84 + peas = 84 + postCheese = 78 // Posni sir + potato = 86 + fatPork = 393 + onion = 23 + cabbage = 25 + sugar = 387 + sunflowerOil = 828 + tomatoPassata = 31 + tomatoPaste = 82 + rice = 130 + water = 0 +) + +func main() { + var ingredients = []ingredient{ + {weight: 25, caloriesPer100: sunflowerOil}, + {weight: 100, caloriesPer100: onion}, + {weight: 16, caloriesPer100: sugar}, + {weight: 800, caloriesPer100: cabbage}, + } + + var totalWeight int64 + var totalCalories int64 + for _, ingredient := range ingredients { + totalWeight += int64(ingredient.weight) + totalCalories += int64((ingredient.weight * ingredient.caloriesPer100) / 100) + } + log.Printf("Total weight: %dg", totalWeight) + log.Printf("Total calories: %dcal", totalCalories) + log.Printf("Calories per 100g: %dcal", totalCalories*100/totalWeight) +}