1/* 2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7unsigned loop(unsigned dog, unsigned cat, unsigned mouse, unsigned horse) 8{ 9 unsigned iterations = 0; 10 while (dog > 0 || cat > 0 || mouse > 0 || horse > 0) { 11 if (dog > horse) { 12 dog--; 13 } else if (horse > mouse) { 14 horse--; 15 } else if (cat > 0) { 16 cat--; 17 } else if (mouse > 0) { 18 mouse--; 19 } else if (dog > 0) { 20 dog--; 21 } else { 22 horse--; 23 } 24 iterations++; 25 } 26 return iterations; 27} 28 29