+ 5

Here is a Challenge [answer with a code] (01)

Anne and Bob were counting. Anne was counting slowly up to 2017. Everytime Anne would say a number Bob would add it to a running total. But everytime the number was a perfect square Bob would be so excited that he would add it twice. What is the total Bob gets to. P.S. The first one to answer gets the XP.

31st May 2017, 7:39 PM
Ulisses Cruz
Ulisses Cruz - avatar
13 Answers
31st May 2017, 7:49 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
31st May 2017, 8:14 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 7
@Kuba Siekierzyński I got this ^^ https://code.sololearn.com/cwEgOLjEIW40/?ref=app
31st May 2017, 8:55 PM
Dennis
Dennis - avatar
+ 6
https://code.sololearn.com/cZpAkjeEK0Og/?ref=app Just a bit too late :(. Still posting it anyway.
31st May 2017, 7:52 PM
Dennis
Dennis - avatar
+ 5
@Ulisses Cruz N * (N + 1) / 2 is the same as 1 + 2 + 3 + ... + N - 2 + N - 1 + N It gets the sum way faster than just iterating and adding. Then I just iterate over the square numbers and add that again so that they are added twice.
31st May 2017, 8:03 PM
Dennis
Dennis - avatar
+ 5
Anybody got this in Ruby? Or... ;)
31st May 2017, 8:40 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
@Dennis 👏👏👏
31st May 2017, 9:04 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Waw. I'm glad I posted this challenge. I learned a lot with you guys. EDITED Thas a new method I want to remembre @Dennis.
31st May 2017, 8:06 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
Good method for testing perfect square @Kuba Siekierzyñski.
31st May 2017, 7:55 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
@Dennis can you explain your algorithm, please.
31st May 2017, 7:59 PM
Ulisses Cruz
Ulisses Cruz - avatar
31st May 2017, 9:16 PM
Ulisses Cruz
Ulisses Cruz - avatar
31st May 2017, 11:32 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
https://code.sololearn.com/can1HMtoKeSI/?ref=app
8th Jun 2017, 2:05 PM
Ulisses Cruz
Ulisses Cruz - avatar