Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return {
- animals = function(heads, l)
- if 0 == heads and l == 0 then
- return {0,0}
- end
- hens = heads - (l-2*heads)/2
- cows = (l-2*heads)/2
- if (l <= 0 or heads <= 0) then
- return "No solutions"
- elseif (heads == 0 ) then
- return "No solutions"
- elseif ((cows < 0 or hens < 0) or (cows == 0 and hens == 0)) then
- return "No solutions"
- elseif (cows ~= math.floor(cows) or hens ~= math.floor(hens)) then
- return "No solutions"
- end
- return {hens, cows}
- end
- }
Add Comment
Please, Sign In to add comment