exercism / problem-specifications

Shared metadata for exercism exercises.
MIT License
320 stars 539 forks source link

Split Raindrops into two files #2371

Closed iHiD closed 6 months ago

iHiD commented 6 months ago

Prepares Raindrops for #48in24.

BethanyG commented 6 months ago

I will have to instruction append on this because %, math.remainder() and math.fmod() do not always return the same thing in Python.

floatingpointmathisfun

>>> remainder(20, 3)
Out[52]: -1.0

>>> fmod(20, 3)
Out[53]: 2.0

>>> 20 % 3
Out[54]: 2

Also, using remainder and fmod require an import, the operator does not. ๐Ÿคท๐Ÿฝโ€โ™€๏ธ

iHiD commented 6 months ago

@BethanyG Cool, thanks. I guess it's worth noting that math.remainder is very much not what an average person would expect and telling them just to use %? Or maybe just say "The modulo operator in Python is %"?

The reference to modulo/remainder hasn't really changed in this PR other than we stop telling peopleย that % means modulo, which it doesn't in most languages (e.g. Python and JavaScript being the two biggest beginner languages, and two languages where % doesn't mean modulo)

BethanyG commented 6 months ago

Python and JavaScript being the two biggest beginner languages, and two languages where % doesn't mean modulo

err. % DOES mean modulo in Python. But yes, agree that we need to make sure Pythonistas understand the difference between the three. ๐Ÿ˜„

I will PR at some point PST today.

meatball133 commented 6 months ago

As far as I know is the biggest languages where % isnt modulo is Swift and javascript.

meatball133 commented 6 months ago

But both in Swift and Crystal isn't % (modulo or remainder in this case) not the easiest and exemplary way to check divisibility. In Swift is it because the % is an actual remainder operator and can create some situations which another method avoids.

iHiD commented 6 months ago

err. % DOES mean modulo in Python. But yes, agree that we need to make sure Pythonistas understand the difference between the three. ๐Ÿ˜„

ChatGPT lies again! ๐Ÿ˜

Screenshot 2024-01-29 at 16 02 07
iHiD commented 6 months ago

I think we can safely say that % is ok for raindrops in any language that supports it, regardless of whether it's modulo or remainder?

meatball133 commented 6 months ago

Yeah, I mean as long as the exercise doesn't deal with signed integers so do all languages I know work the same with the % operator.

MatthijsBlom commented 6 months ago

I think we can safely say that % is ok for raindrops in any language that supports it, regardless of whether it's modulo or remainder?

Modulo and remainder differ only when the dividend and the divisor differ in sign. So in particular when both operands are nonnegative the modulo and remainder are the same.

 5 `rem`  3 =  2      5 `mod`  3 =  2
 5 `rem` -3 =  2      5 `mod` -3 = -1
-5 `rem`  3 = -2     -5 `mod`  3 =  1
-5 `rem` -3 = -2     -5 `mod` -3 = -2
glaxxie commented 6 months ago

err. % DOES mean modulo in Python. But yes, agree that we need to make sure Pythonistas understand the difference between the three. ๐Ÿ˜„

ChatGPT lies again! ๐Ÿ˜

In powershell depend on the context and placement, % could mean modulus or act as alias for foreach-object.

5 % 2  
=> 1

or

@(1,2,3,4,5) | % { $_ % 2 } 
=> @(1,0,1,0,1)

Generally I recommend using the fullname to avoid any possible confusion, and easier to read but this practice is still quite prevalent among more experienced user when they script in terminal. This shouldn't be much of an issue regarding this exercise I suppose.