Guest User

Untitled

a guest
Jan 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. return {
  2. animals = function(heads, l)
  3. if 0 == heads and l == 0 then
  4. return {0,0}
  5. end
  6. hens = heads - (l-2*heads)/2
  7. cows = (l-2*heads)/2
  8. if (l <= 0 or heads <= 0) then
  9. return "No solutions"
  10. elseif (heads == 0 ) then
  11. return "No solutions"
  12. elseif ((cows < 0 or hens < 0) or (cows == 0 and hens == 0)) then
  13. return "No solutions"
  14. elseif (cows ~= math.floor(cows) or hens ~= math.floor(hens)) then
  15. return "No solutions"
  16. end
  17. return {hens, cows}
  18. end
  19. }
Add Comment
Please, Sign In to add comment