-
Notifications
You must be signed in to change notification settings - Fork 0
/
salad.go
77 lines (63 loc) · 1.49 KB
/
salad.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import "fmt"
var saladRequirements = []string{"lettuce", "kale", "field greens", "spinach"}
var saladExclusions = []string{"bread", "crust", "pita", "wrap", "tortilla"}
var ingredientMin = 3
var ingredients = []string{"tomato", "mayo"}
func testRequirements(ingredients []string, requirements []string, exclusions []string) (valid bool) {
for _,v := range ingredients {
for _,vv := range requirements {
if v == vv {
valid = true
}
}
for _,vx := range exclusions {
if v == vx {
return false
}
}
}
return
}
func isMeal(ingredients []string, servingDevice string) bool {
salad := false
if servingDevice != "bowl" && servingDevice != "plate" {
return false
}
salad = testRequirements(ingredients, saladRequirements, saladExclusions)
if !salad {
return false
}
if len(ingredients) >= ingredientMin {
salad = true
} else {
return false
}
return salad
}
func main() {
servingDevice := "bowl"
print("A meal with the ingredients:")
for i,v := range ingredients {
last := false
if i == len(ingredients) - 1 {
last = true
print(" and")
}
print(" ")
print(v)
if !last && len(ingredients) > 2 {
print(",")
}
}
print(", served")
if servingDevice == "bowl" {
print(" in a bowl, is")
} else {
print(fmt.Sprintf(" on a %s, is", servingDevice))
}
if !isMeal(ingredients, servingDevice) {
print(" not")
}
print(" a salad.\n")
}