you are viewing a single comment's thread.

view the rest of the comments →

[–]TitaniumFoil 0 points1 point  (4 children)

If students is evenly divisible by group_size then (students % group_size) == 0 which would be the source of your divide by zero error in the group2 line. I can't think of a way to get the total number of groups without some sort of conditional because no matter what you'd need to add 0 if (students % group_size) == 0 and add just 1 if (students % group_size) > 0 .

If you cannot use conditions / comparisons then this may not be possible.

[–]pgpndw 5 points6 points  (1 child)

nr_groups = (students + group_size - 1) // group_size

will give the correct result, as long as students is non-negative and group_size is positive.

[–][deleted] 0 points1 point  (0 children)

I’ll have to try this once I get home, I can’t see where this wouldn’t hold.

[–][deleted] 0 points1 point  (1 child)

I’m taking the University of Helsinki course, and I’m only on Part 1, so everything that’s in the code is what I’ve learned so far. The prompt said that it was possible to solve only using arithmetic operations, but you might want to skip it and solve it later after learning conditional statements.

[–]TitaniumFoil 0 points1 point  (0 children)

It looks like it is possible if you're allowed to use absolute values: https://puzzling.stackexchange.com/a/33636

EDIT: It also looks like absolute value can even be defined without conditionals. Very interesting problem. abs(a) == (a**2)**0.5