Files
calorie-calculator/main.go
2024-08-11 22:16:42 +02:00

79 lines
1.6 KiB
Go

package main
import (
"log"
)
func init() {
log.SetFlags(log.Lmicroseconds)
}
type ingredient struct {
weight int
caloriesPer100 int
}
const (
bakingPowder = 92
beans = 100
butter = 774
butter2 = 630 // Cake butter thing that's not real butter
carrot = 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 = 25
tomatoPaste = 82
hardCheese = 330
porkLean = 143
rice = 130
water = 0
skyr = 62
vegetableMix = 50
mustard = 30
beetroot = 43
ketchup = 92
sausage = 300
mexicomix = 59
milk = 64
yeast = 185
tofu = 76
sourcream = 70
cherry = 63
lentil = 116
cream = 232
)
func main() {
var ingredients = []ingredient{
{500, potato},
{150, lentil},
{125, cream},
{30, flour},
{1500, water},
}
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)
}