2
$\begingroup$

I am very new to mathematica. I am trying to generate list of number sequence. I want to make 6 sequences. 1 - 10, 10 - 100, 100 - 1 000, 1 000 - 10 000, 10 000 - 100 000. All reversed. Is there any elegant to way how to approach that? I am trying to figure it out using documentation, but I can't. Thanks

$\endgroup$
4
  • 1
    $\begingroup$ Are you looking for Range, i.e. something like this: Range[10, 1, -1]? You may also be interested in PowerRange, and combine it with Range. $\endgroup$
    – MarcoB
    Nov 11, 2019 at 22:58
  • 1
    $\begingroup$ seqs = Range[10^Range[0, 4], 10^Range[1, 5]]. Then seqs[[1]] will be your first sequence, seqs[[2]] the second... Reverse/@seq will reverse them. rseqs=Range[10^Range[1, 5], 10^Range[0, 4], -1] will generate them already reversed. $\endgroup$
    – ciao
    Nov 11, 2019 at 23:02
  • $\begingroup$ Table[Range[10^(n + 1), 10^n, -10^n], {n, 0, 4}] Change the steps to -1 if that is what you actually want. $\endgroup$
    – Bob Hanlon
    Nov 12, 2019 at 1:21
  • $\begingroup$ Thanks for all the help. It helped me. :] $\endgroup$
    – Fyris
    Nov 12, 2019 at 13:00

1 Answer 1

2
$\begingroup$

The following uses a combination of Range and PowerRange:

Reverse /@ Range @@@ Partition[PowerRange[100000], 2, 1]

Here is an example of output (shortened using Shallow):

{{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, 
 {100, 99, 98, 97, 96, 95, 94, 93, 92, 91, <<81>>}, 
 {1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, <<891>>}, 
 {10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, <<8991>>}, 
 {100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, <<89991>>}, 
}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.