+ 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.

6th Feb 2019, 3:43 PM
Ross Hunter
9 Answers
+ 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.
7th Feb 2019, 4:25 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 10
that is happening because 12 is div. by 6, else we need to iterate through whole range & check for each integer. //time saved
7th Feb 2019, 8:45 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
Bennett Post so the loop will work like 6 18 30 42...........n+12 Really effective.
7th Feb 2019, 4:50 AM
nayan
nayan - avatar
0
https://code.sololearn.com/cE1LdLehSw7V/?ref=app I tried to implement both ways into a dynamic programming.
7th Feb 2019, 9:36 AM
nayan
nayan - avatar
7th Feb 2019, 10:10 AM
Ganiyu Olalekan
Ganiyu Olalekan - avatar
0
😂 😂 😂, I feel embarrassed Thanks for the correction Bennett Post Just wrote it, didn't even check it
7th Feb 2019, 12:04 PM
Ganiyu Olalekan
Ganiyu Olalekan - avatar
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)
7th Feb 2019, 1:00 PM
#!/usr/bin/python
#!/usr/bin/python - avatar
0
Or you can use this ; a=range(1000,10000) res=list[filter(lambda x: x%6==0,a)] print(res)
7th Feb 2019, 4:52 PM
#!/usr/bin/python
#!/usr/bin/python - avatar
0
https://code.sololearn.com/cWsepb21LdG7/?ref=app This also should reduce the time spent
11th Feb 2019, 4:35 PM
Lekan Adenusi
Lekan Adenusi - avatar