Message Boards Message Boards


How to create a list from 100 to 0 decrementing?

Posted 1 month ago
7 Replies
3 Total Likes

Hi there !! I should feel embarrassed to ask such a simple question but I can not find any answers on the web....maybe because it is too simple... I use Nestlist[ floor[]] as in the lines below, but if I increase the number it won't give an answer, is there a simpler way to list from 100 to 0 {100,99,98,97,96...,3,2,1,0}? or from n->0?

7 Replies
Posted 1 month ago

Yes, there is a simple way. Range followed by Reverse

Range[0, 100] // Reverse

n = 1223
Range[n] // Reverse

Thank you so much Hans

Posted 1 month ago

Or Table with a negative increment

Table[x, {x, 100, 0, -1}]

Or Range[100, 0, -1]

Thank you all but they all have a system memory failure issue, I don't know if divisors in reverse will reverse the calculus of the division or if it will only reverse the is what I want to make the mod[a,n] n being the numbers down from n to 0... but for huge numbers until I find 0 for the result, a perfect divisor so to exclude the number from being a prime.

Posted 1 month ago

Well if n is a huge integer then generating a list of {n, n - 1, n - 2, ... 0} is of course going to exhaust memory. You could try something like this

p1000000 = Prime[1000000]

(* Can optimize to only check from Sqrt[n] *)
(n = p1000000; While[Mod[p1000000, n - 2] != 0, n = n - 2]; n - 2) // AbsoluteTiming
(* {6.72053, 1} *)

(n = p1000000 - 2; While[Mod[p1000000 - 2, n - 2] != 0, n = n - 2]; n - 2) // AbsoluteTiming
(* {6.75608, 910933} *)

Mod[p1000000 - 2, 910933]
(* 0 *)

If n is large, you are going to have to wait a long time. You could split the range and parallelize across available kernels, but still. You can probably estimate roughly how long it is going to take by computing the time to divide n by 1000 candidate divisors and extrapolating.

Thank you so much. God bless you.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract