+ 1
Need help to write a program that prints all numbers between 1,000 and 10,000 that are divisible by 6 but not 12.
9 odpowiedzi
+ 11
basic way is to use condition (a%6==0&&a%12!=0) & run through all integers in range, though Bennett Post idea is more efficient as it removes the need to check condition for every integer in range & reduce the number of iterations in loop.
+ 10
that is happening because 12 is div. by 6, else we need to iterate through whole range & check for each integer.
//time saved
+ 2
Bennett Post so the loop will work like
6 18 30 42...........n+12
Really effective.
0
https://code.sololearn.com/cE1LdLehSw7V/?ref=app
I tried to implement both ways into a dynamic programming.
0
😂 😂 😂, I feel embarrassed
Thanks for the correction Bennett Post
Just wrote it, didn't even check it
0
you can use numpy to solve this problem
import numpy as np
arr=np.array(range(1000,10000))
arr2=arr[arr%6==0]
print(arr2)
0
Or you can use this ;
a=range(1000,10000)
res=list[filter(lambda x: x%6==0,a)]
print(res)
0
https://code.sololearn.com/cWsepb21LdG7/?ref=app
This also should reduce the time spent