HACKER Q&A
📣 nomilk

Generate sequence 10, 20, 50, 100, 200 ... 5,000,000,000,000,000,000,000


The R code that generates this sequence seems very beautiful.

How you would generate the sequence in your language of choice?

Full sequence:

                     10                     20                     50
                    100                    200                    500
                   1000                   2000                   5000
                  10000                  20000                  50000
                 100000                 200000                 500000
                1000000                2000000                5000000
               10000000               20000000               50000000
              100000000              200000000              500000000
             1000000000             2000000000             5000000000
            10000000000            20000000000            50000000000
           100000000000           200000000000           500000000000
          1000000000000          2000000000000          5000000000000
         10000000000000         20000000000000         50000000000000
        100000000000000        200000000000000        500000000000000
       1000000000000000       2000000000000000       5000000000000000
      10000000000000000      20000000000000000      50000000000000000
     100000000000000000     200000000000000000     500000000000000000
    1000000000000000000    2000000000000000000    5000000000000000000
   10000000000000000000   20000000000000000000   50000000000000000000
  100000000000000000000  200000000000000000000  500000000000000000000
 1000000000000000000000 2000000000000000000000 5000000000000000000000
R code:

options(scipen=99);(rep(c(1,2,5), 10) * (10 ^ (sort(rep(1:30, 3)))))[1:63]


  👤 techdragon Accepted Answer ✓
I think it looks quite elegant in Python if you use the modern f-strings and pragmatic inline calculations.

  >>> for i in range(21):
  ...     print(f"{10*10**i:>23}{20*10**i:>23}{50*10**i:>23}")
  ... 
                       10                     20                     50
                      100                    200                    500
                     1000                   2000                   5000
                    10000                  20000                  50000
                   100000                 200000                 500000
                  1000000                2000000                5000000
                 10000000               20000000               50000000
                100000000              200000000              500000000
               1000000000             2000000000             5000000000
              10000000000            20000000000            50000000000
             100000000000           200000000000           500000000000
            1000000000000          2000000000000          5000000000000
           10000000000000         20000000000000         50000000000000
          100000000000000        200000000000000        500000000000000
         1000000000000000       2000000000000000       5000000000000000
        10000000000000000      20000000000000000      50000000000000000
       100000000000000000     200000000000000000     500000000000000000
      1000000000000000000    2000000000000000000    5000000000000000000
     10000000000000000000   20000000000000000000   50000000000000000000
    100000000000000000000  200000000000000000000  500000000000000000000
   1000000000000000000000 2000000000000000000000 5000000000000000000000
  >>>
Edit: fixed the asterisks for HN formatting

👤 nomilk
This study compares how concise 14 programming languages are (it places R third, after mathematica and clojure):

https://blog.revolutionanalytics.com/2012/11/which-programmi...

Source of R code: https://github.com/stevecondylios/iteratoR/blob/main/R/itera...


👤 dublin
I'm amazed at how many people who build graphs never learned the very basic rule that used to be taught in freshman engineering classes: Unless there is a really good reason, always scale the axes of your graphs using a range from the 1,2,5,10... sequence. (e.g., With a max Y-axis value of 38, graph on a scale maxing at 50, 1546 on 2000, etc).

Since most data science developers are not engineers, we see a lot of crap graphs these days...


👤 nh23423fefe

     scanl (*) 1 (cycle [2, 5%2, 10%5])
in haskell