Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • loop to increment a string variable

    I would like to create a file with every combination of letters out to 10 characters.

    For example, the first few lines

    a
    b
    c

    then eventually

    aa
    ab
    ac

    then eventually

    aaa
    aab
    aac

    and so on. Finally, it will end with

    zzzzzzzzzz


    This will create 26^10 lines. Is there a simple way to create a file like this with some kind of loop?

    Thanks in advance.





  • #2
    The algorithmic problem of generating these combinations in turn is interesting, but I don't believe you have 1.3 petabyte of RAM to waste for this. For the record, that's the amount of RAM available on the Tianhe-2 supercomputer. So, what are you really trying to do?

    Jean-Claude Arbaut
    Last edited by Jean-Claude Arbaut; 04 May 2019, 12:00.

    Comment


    • #3
      That’s asking for well over a trillion observations. Apart from the memory issue no Stata can oblige at present, I believe. See for your setup

      Code:
      help limits
      Last edited by Nick Cox; 04 May 2019, 12:03.

      Comment


      • #4
        Memory issues aside, see non-documented

        Code:
        mata : strlower(numtobase26((1..100)))
        also implemented in Stata as num2base26 (SSC).

        Best
        Daniel
        Last edited by daniel klein; 04 May 2019, 12:24.

        Comment


        • #5
          In thinking about this, I believe the problem is about 4% worse than stated in post #1.

          My calculator tells me 2610 = 141,167,095,653,376, and that is only the number of 10-character strings composed on letters from a 26-letter alphabet.

          The total number of strings of length 1 through 10 composed on these letters will be the sum of the geometric series 26 + 262 + ... + 2610 which is (26/25) * (2610 - 1) = 146,813,779,479,510.

          With apologies to https://youtu.be/QT9BeGNnCqw , you're gonna need a bigger supercomputer.

          Comment

          Working...
          X