-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem 6: [Language] #16
Comments
Hi Jamie, Well, I think that rule is the english language! :-) The question is how to remember that List.range() is equivalent to 'until' and not 'to'? I never use List.range() and I confess that I would expect it to be inclusive. I just learn that this is not the case. Thanks! I would probably check the docs if I was about to use it or do a small check using the REPL. The problem of doing that in the context of Project Euler is that you don't immediately see you picked the wrong one. Because the test may be failing because of another reason and not because you have one more or one less item in your range. So, if you are looking for a rule of thumb, I can only say in doubt ask the REPL. :-) |
val sum1 = (1 to 100).sum
sum1 * sum1 - (1 to 100).map(x => x*x).sum First create a Range |
@jamiephillips0000 maybe this might help in remembering the difference between
and
I'm pretty sure you have no doubt that the body of the while loop is last executed with i = 100 (INCLUSIVE), and that the body of the repeat-until loop is last executed with i = 99 (EXCLUSIVE the 100). So as a rule of thumb: |
Hi Sam
|
So - just fooling around Just laughing about this - would have expected this to have Array(4) as a result ;-) |
Jamie, This works as advertised; for the first element in the Array, the predicate _ % 4 == 0 is false. Hence, takeWhile immediately ‘stops’ and returns an empty Array. On the other hand, an example of a case where the result is non-empty: scala> val a = Array(1,2,3,4,5) scala> a.takeWhile(el => el < 4) Regards, Eric
|
Hi Eric |
Hi Jamie, Got it ;-) Eric
|
i keep getting nailed by "to" and "until"
List.range(0, 100).sum << this is 0 - 99 inclusive
(0 to 100).sum << this is 0 - 100 inclusive
Is there any easy way of distinguishing these - some sort of rule of thumb?
The text was updated successfully, but these errors were encountered: