+ 7
(## CIRCULARY-MOVING-SUM##)merry go round//how's that sound ?//
input 1::: array of some integers("+ve or -ve") input 2::: a positive integer 'n' eg1--(task and outputs)--> array= [1,3,4] n=5 --1+3+4+1+3 = 12 --3+4+1+3+4=15 --4+1+3+4+1=13 output array= [12,15,13] eg2--(task and outputs)--> array= [1,6,7,8] n=3 --1+6+7=14 --6+7+8=21 --7+8+1=16 --8+1+6=15 output array= [14,21,16,15] eg3--(task and outputs)--> array= [4,5] n=5 --4+5+4+5+4=22 --5+4+5+4+5=23 output array= [22,23] SAMPLE INPUT: 2 -4 6 -7 5 SAMPLE OUTPUT: print the input [ -1 , -7, 3, -10] ## Thanks
16 ответов
+ 4
Here you go. Checks for valid input. Negatives come into play, but if they did, it would calculate correctly.
https://code.sololearn.com/cNcY5xSvmGg0/?ref=app
+ 3
https://code.sololearn.com/Wo4mdyjbvXn0/#js
Hello, thanks for the challenge. :)
+ 3
mine https://code.sololearn.com/WES8XsiH0sgQ/?ref=app
note: in the second example the sum of 8+1+6 is 15 ☺
note2: if you put the steps as array's length, the resultant array will have all the same terms
+ 3
@ysraelcon Actually any number that is a multiple of input array's length will give the same result. Nice catch though 👍
+ 3
Here is my code in Python 🐍
https://code.sololearn.com/cN3TDL6J4OO8/?ref=app
+ 2
Here's mine,
https://code.sololearn.com/ccQG23fFRN4K/?ref=app
Edit: simplified the two functions I had into one since the logic I went with didn't really need such structure.
+ 2
mine is a single-liner:
https://code.sololearn.com/c2aejV3Bt6Jd/?ref=app
+ 1
Here's my take:
https://code.sololearn.com/cLo05XIzFbs6
+ 1
Here is my take, Please have look and let me know your suggestions
https://code.sololearn.com/cgUs3kVC2T2u/#py
+ 1
Here's my C# implementation ✌
LINQ One-Liner〰
Enumerable.Range(0, len)
.Select(n =>
Enumerable.Range(n, count)
.Sum(i => numList[i % len]))
Once again, I must confess that I love LINQ so much. Enjoy!
https://code.sololearn.com/cC5Km6K82ysQ/?ref=app
0
Hey, 8+1+6=14 ???
I don't think so...
0
Here is mine:
https://code.sololearn.com/cKEf2tc841Bv
0
https://code.sololearn.com/Wc4KtRN62C6A/?ref=app
- 1
HERES A NEW CHALLENGE
CHECK IT AND TRY IF YOU WANT
https://www.sololearn.com/discuss/793924/?ref=app