-
Notifications
You must be signed in to change notification settings - Fork 0
/
54-companion-plants
89 lines (76 loc) · 3.2 KB
/
54-companion-plants
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
78
79
80
81
82
83
84
85
86
87
88
89
public Boolean companionPlants(String plant1, String plant2) {
/* sol 1
if (plant1 == 'onions' && (plant2 == 'lettuce' || plant2 == 'carrots' || plant2 == 'tomatoes'))
return true;
else if (plant1 == 'lettuce' && (plant2 == 'cucumbers' || plant2 == 'onions'))
return true;
else if (plant1 == 'cucumbers' && plant2 == 'lettuce')
return true;
else if (plant1 == 'carrots' && plant2 == 'onions')
return true;
else if (plant1 == 'tomatoes' && plant2 == 'onions')
return true;
else return false; */
/* sol 2
Map<String, Set<String>> companionPlants = new Map<String, Set<String>>();
companionPlants.put('lettuce', new Set<String>{'cucumbers', 'onions'});
companionPlants.put('cucumbers', new Set<String>{'lettuce'});
companionPlants.put('onions', new Set<String>{'lettuce', 'carrots', 'tomatoes'});
companionPlants.put('carrots', new Set<String>{'onions'});
companionPlants.put('tomatoes', new Set<String>{'onions'});
return companionPlants.get(plant1).contains(plant2); */
/* sol 3
Map<String, String> mapCompaniorPlants = new Map<String, String>();
mapCompaniorPlants.put('lettuce','cucumbers');
mapCompaniorPlants.put('onions','lettuce');
mapCompaniorPlants.put('carrots','onions');
mapCompaniorPlants.put('tomatoes','onions');
if((mapCompaniorPlants.get(plant1) == plant2) || (mapCompaniorPlants.get(plant2) == plant1)){
return true;
}
return false; */
/* sol 4
MAP<String, Boolean> plantMap = NEW MAP<String, Boolean>{
'lettucecucumbers' => true,
'lettuceonions' => true,
'onionscarrots' => true,
'onionstomatoes' => true,
'cucumberslettuce' => true,
'onionslettuce' => true,
'carrotsonions' => true,
'tomatoesonions' => true
};
if (plantMap.get(plant1+plant2) == true ) return true;
return false; */
/* sol 5
Boolean bro = false;
if(plant1 == 'lettuce' || plant2 == 'lettuce') {
if(plant1=='cucumbers' || plant2=='cucumbers' ||
plant1=='onions'||plant2=='onions') bro = true;
}
else if(plant1 == 'onions' || plant2 == 'onions') {
if(plant1=='carrots' || plant2=='carrots' ||
plant1=='tomatoes'||plant2=='tomatoes') bro = true;
}
return bro; */
/* sol 6
return (plant1 == 'onions' && (plant2 == 'lettuce' ||
plant2 == 'carrots' || plant2 == 'tomatoes')) ? true :
(plant1 == 'lettuce' && (plant2 == 'cucumbers' ||
plant2 == 'onions')) ? true :
(plant1 == 'cucumbers' && plant2 == 'lettuce') ? true :
(plant1 == 'carrots' && plant2 == 'onions') ? true:
(plant1 == 'tomatoes' && plant2 == 'onions') ? true : false; */
// sol 7
String result=plant1+plant2;
if(result=='lettucecucumbers' ||
result=='cucumberslettuce' ||
result=='lettuceonions' ||
result=='onionslettuce' ||
result=='carrotsonions' ||
result=='onionscarrots' ||
result=='tomatoesonions' ||
result=='onionstomatoes')
return True;
else return False;
}