0

Algorithms Python

The numbers in the table below are the result of executing an algorithm that has one parameter N, a non-negative integer, and produces sequences of integers as outputs. For values of N from 0 to 5, the algorithm produces the following sequences of numbers as outputs: header header 0​ 1​ -​1 0 3 2​ -​4 -3 0 5 12 21 3​ -​9 -8 -5 0 7 16 27 40 55 4​ -​16 -15 -12 -7 0 9 20 33 48 65 84 105 5​ -​25 -24 -21 -16 -9 0 11 24 39 56 75 96 119 144 171 Determine the algorithm that was used to generate the numbers in this table. Execute it for N = 6 What is the sequence of numbers for N = 6?

1st Oct 2023, 4:39 AM
Nick
9 odpowiedzi
+ 1
If present in a string, it consists of 30 elements separated by a space. -36 -35 -32 -27 -20 -11 0 13 28 45 64 85 108 133 160 189 220 253 288 325 364 405 448 493 540 589 640 693 748 805 CORRECTION If present in a string, it consists of 18 elements separated by a space. -36 -35 -32 -27 -20 -11 0 13 28 45 64 85 108 133 160 189 220 253
1st Oct 2023, 5:23 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
GamerGeil Hd, not quite right. Your code give the first number correct, but others are wrong so as the length of the answer. You can try with the playground. OP asked for the sequence N = 6, and he did NOT ask for the code. This post is more like a challenge than a question, so I didn’t post the code, unless someone tried, failed and ask for pointer. Although title included “Python”, this problem can be solved with other language as well.
1st Oct 2023, 9:11 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Nick there is a proper Q&A thread specially designated for posting challenges. You may use your profile post or that thread. Otherwise, Sololearn discourages using Q&A for anything other than specific programming questions and questions about Sololearn. https://www.sololearn.com/Discuss/1270852/?ref=app
1st Oct 2023, 3:28 PM
Brian
Brian - avatar
+ 1
Thanks
1st Oct 2023, 4:24 PM
Nick
0
def generate_sequence(N): sequence = [] sequence.append(-(N*N)) for i in range(N + 1): sequence.append(-(N*N) + i) return sequence N = 6 sequence_N_6 = generate_sequence(N) print(sequence_N_6)
1st Oct 2023, 8:48 AM
D1M3
D1M3 - avatar
0
Ah K i try in c++
1st Oct 2023, 9:12 AM
D1M3
D1M3 - avatar
0
GamerGeil Hd, if you turn int N = 6 to N = 5 and run your code, you will found the result is not the same as Nick posted. Give it another try...
1st Oct 2023, 9:21 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
K
1st Oct 2023, 9:22 AM
D1M3
D1M3 - avatar