Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
You can start the stream on 3, no need to test values below that.
Both are slow as you can just use math instead of any loop/stream.
Of course you don't NEED to iterate through. It's a really quick solution to a really quick problem, that's why it's good. The Intstream solution takes 1.3s if the input is 1 billion, but since the tests were way smaller, that ain't a problem. If coding a real project, then of course everyone should think twice if their solution is really the most efficient or not. Here it's not necessary.
Learned something new !
Nop.
I just run a benchmark to be sure, with smallNumber = 25 and bigNumber = Integer.MAX_SIZE.
Here are the results :
Benchmark Mode Cnt Score Error Units
MultiplesOf3And5Test.withForLoopAndBigNumber avgt 5 2.680 ± 0.055 s/op
MultiplesOf3And5Test.withForLoopAndSmallNumber avgt 5 28.495 ± 4.046 ns/op
MultiplesOf3And5Test.withParallelStreamAndBigNumber avgt 5 1.044 ± 0.184 s/op
MultiplesOf3And5Test.withParallelStreamAndSmallNumber avgt 5 11284.553 ± 1710.007 ns/op
MultiplesOf3And5Test.withStreamAndBigNumber avgt 5 3.013 ± 0.049 s/op
MultiplesOf3And5Test.withStreamAndSmallNumber avgt 5 94.385 ± 3.109 ns/op
(Yes I used warmup steps to remove JIT and CPU bias)
Here are my interpretations :
Nop, the text says "below n" and not "equals or below n".
So for n=9, then 14 is the correct answer (3 + 5 + 6).
Also, if you really want inclusive IntStream, use
IntStream.rangeClosed(start, end)
Please use spoiler flag next time.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
THis is the best solution I have seen so far. well done. Will be using the IntStream from here on out.
I really liked it. Learned something new. Nice job!
Nice solution!
Java8 Streams
Like stream solution!:)
You can really do the range from [1, number) since 0 will not have an affect on it at all (even though it is passes the check of being a multiple it will not contribute to the sum)
Loading more items...