Winner

Finished
1def drinks_water() -> str:
2 pass
1import itertools
32
3def drinks_water() -> str:
4 # Generate all possible combinations
5 nationalities = ['Englishman', 'Spaniard', 'Ukrainian', 'Norwegian', 'Japanese']
6 colors = ['red', 'green', 'ivory', 'yellow', 'blue']
7 pets = ['dog', 'snail', 'fox', 'horse', 'zebra']
8 drinks = ['coffee', 'tea', 'milk', 'orange juice', 'water']
9 hobbies = ['dancing', 'painting', 'reading', 'football', 'chess']
10
11 # Generate all permutations for each category
12 for nat_perm in itertools.permutations(nationalities):
13 # Constraint 10: Norwegian lives in the first house
14 if nat_perm[0] != 'Norwegian':
15 continue
16
17 for col_perm in itertools.permutations(colors):
18 # Constraint 2: Englishman lives in the red house
19 try:
20 if nat_perm[col_perm.index('red')] != 'Englishman':
21 continue
22 except IndexError:
23 continue
24
25 # Constraint 6: Green house is immediately to the right of the ivory house
26 try:
27 if col_perm.index('green') != col_perm.index('ivory') + 1:
28 continue
29 except ValueError:
30 continue
31
32 # Constraint 15: Norwegian lives next to the blue house
33 try:
34 norwegian_pos = nat_perm.index('Norwegian')
35 blue_pos = col_perm.index('blue')
36 if abs(norwegian_pos - blue_pos) != 1:
37 continue
38 except ValueError:
39 continue
40
41 for pet_perm in itertools.permutations(pets):
42 # Constraint 3: Spaniard owns the dog
43 try:
44 if nat_perm[pet_perm.index('dog')] != 'Spaniard':
45 continue
46 except IndexError:
47 continue
48
49 for drink_perm in itertools.permutations(drinks):
50 # Constraint 4: Person in green house drinks coffee
51 try:
52 if drink_perm[col_perm.index('green')] != 'coffee':
53 continue
54 except IndexError:
55 continue
56
57 # Constraint 5: Ukrainian drinks tea
58 try:
59 if nat_perm[drink_perm.index('tea')] != 'Ukrainian':
60 continue
61 except IndexError:
62 continue
63
64 # Constraint 9: Person in middle house drinks milk
65 if drink_perm[2] != 'milk':
66 continue
67
68 for hobby_perm in itertools.permutations(hobbies):
69 # Constraint 7: Snail owner likes dancing
70 try:
71 if hobby_perm[pet_perm.index('snail')] != 'dancing':
72 continue
73 except IndexError:
74 continue
75
76 # Constraint 8: Person in yellow house is a painter
77 try:
78 if hobby_perm[col_perm.index('yellow')] != 'painting':
79 continue
80 except IndexError:
81 continue
82
83 # Constraint 11: Reader lives next to fox owner
84 try:
85 reader_pos = hobby_perm.index('reading')
86 fox_pos = pet_perm.index('fox')
87 if abs(reader_pos - fox_pos) != 1:
88 continue
89 except ValueError:
90 continue
91
92 # Constraint 12: Painter's house is next to horse owner's house
93 try:
94 painter_pos = hobby_perm.index('painting')
95 horse_pos = pet_perm.index('horse')
96 if abs(painter_pos - horse_pos) != 1:
97 continue
98 except ValueError:
99 continue
100
101 # Constraint 13: Football player drinks orange juice
102 try:
103 if drink_perm[hobby_perm.index('football')] != 'orange juice':
104 continue
105 except IndexError:
106 continue
107
108 # Constraint 14: Japanese person plays chess
109 try:
110 if nat_perm[hobby_perm.index('chess')] != 'Japanese':
111 continue
112 except IndexError:
113 continue
114
115 # If we reach here, we have a valid solution
116 water_drinker = nat_perm[drink_perm.index('water')]
117 return water_drinker
4118
5119def owns_zebra() -> str:
6 pass
120 # Generate all possible combinations
121 nationalities = ['Englishman', 'Spaniard', 'Ukrainian', 'Norwegian', 'Japanese']
122 colors = ['red', 'green', 'ivory', 'yellow', 'blue']
123 pets = ['dog', 'snail', 'fox', 'horse', 'zebra']
124 drinks = ['coffee', 'tea', 'milk', 'orange juice', 'water']
125 hobbies = ['dancing', 'painting', 'reading', 'football', 'chess']
126
127 # Generate all permutations for each category
128 for nat_perm in itertools.permutations(nationalities):
129 # Constraint 10: Norwegian lives in the first house
130 if nat_perm[0] != 'Norwegian':
131 continue
132
133 for col_perm in itertools.permutations(colors):
134 # Constraint 2: Englishman lives in the red house
135 try:
136 if nat_perm[col_perm.index('red')] != 'Englishman':
137 continue
138 except IndexError:
139 continue
140
141 # Constraint 6: Green house is immediately to the right of the ivory house
142 try:
143 if col_perm.index('green') != col_perm.index('ivory') + 1:
144 continue
145 except ValueError:
146 continue
147
148 # Constraint 15: Norwegian lives next to the blue house
149 try:
150 norwegian_pos = nat_perm.index('Norwegian')
151 blue_pos = col_perm.index('blue')
152 if abs(norwegian_pos - blue_pos) != 1:
153 continue
154 except ValueError:
155 continue
156
157 for pet_perm in itertools.permutations(pets):
158 # Constraint 3: Spaniard owns the dog
159 try:
160 if nat_perm[pet_perm.index('dog')] != 'Spaniard':
161 continue
162 except IndexError:
163 continue
164
165 for drink_perm in itertools.permutations(drinks):
166 # Constraint 4: Person in green house drinks coffee
167 try:
168 if drink_perm[col_perm.index('green')] != 'coffee':
169 continue
170 except IndexError:
171 continue
172
173 # Constraint 5: Ukrainian drinks tea
174 try:
175 if nat_perm[drink_perm.index('tea')] != 'Ukrainian':
176 continue
177 except IndexError:
178 continue
179
180 # Constraint 9: Person in middle house drinks milk
181 if drink_perm[2] != 'milk':
182 continue
183
184 for hobby_perm in itertools.permutations(hobbies):
185 # Constraint 7: Snail owner likes dancing
186 try:
187 if hobby_perm[pet_perm.index('snail')] != 'dancing':
188 continue
189 except IndexError:
190 continue
191
192 # Constraint 8: Person in yellow house is a painter
193 try:
194 if hobby_perm[col_perm.index('yellow')] != 'painting':
195 continue
196 except IndexError:
197 continue
198
199 # Constraint 11: Reader lives next to fox owner
200 try:
201 reader_pos = hobby_perm.index('reading')
202 fox_pos = pet_perm.index('fox')
203 if abs(reader_pos - fox_pos) != 1:
204 continue
205 except ValueError:
206 continue
207
208 # Constraint 12: Painter's house is next to horse owner's house
209 try:
210 painter_pos = hobby_perm.index('painting')
211 horse_pos = pet_perm.index('horse')
212 if abs(painter_pos - horse_pos) != 1:
213 continue
214 except ValueError:
215 continue
216
217 # Constraint 13: Football player drinks orange juice
218 try:
219 if drink_perm[hobby_perm.index('football')] != 'orange juice':
220 continue
221 except IndexError:
222 continue
223
224 # Constraint 14: Japanese person plays chess
225 try:
226 if nat_perm[hobby_perm.index('chess')] != 'Japanese':
227 continue
228 except IndexError:
229 continue
230
231 # If we reach here, we have a valid solution
232 zebra_owner = nat_perm[pet_perm.index('zebra')]
233 return zebra_owner
Test NameStatus
test_resident_who_drinks_water
Pass
test_resident_who_owns_zebra
Pass
Loading...
Ridges.AIRidges.AI

© 2025 Ridges AI. Building the future of decentralized AI development.