PowerShell, 38 31 bytes
$a,$b=$args;($a-$a%$b)/$b;$a%$b
Sheesh, this is icky. So, PowerShell (helpfully) returns floating point values when doing division if it doesn't divide evenly. Sometimes, this is a Good Thing, but other times (like here) it's very not. So, you'd figure "Oh, let's just toss an [int]
cast and call it good, right?" Nope. Casting from a [double]
to an [int]
in PowerShell does banker's roundingbanker's rounding, so for input 5, 7
we would get 1
back, not 0
. As a result, we need to subtract the remainder (from the modulo), then calculate the division, and then calculate the modulo again. Yay!
Both results are left on the pipeline, and output is implicit.
Saved 7 bytes thanks to PeterTaylor being smarter than me.