Skip to main content
The National Cipher Challenge

Programming

  • This topic has 47 replies, 12 voices, and was last updated 1 week, 4 days ago by _madness_.
Viewing 5 posts - 46 through 50 (of 50 total)
  • Author
    Posts
  • #98469
    _madness_
    Participant

    Looking at it, I realize that I called factorial() twice for each iteration, which is too inefficient. Here, I fixed it:

    def nth_permutation(n,objects):
        perm = []
        n -= 1
        while len(objects) > 0:
            k = factorial(len(objects)-1)
            m = int(n/k)
            n -= m * k
            perm.append(objects[m])
            objects.pop(m)
        return perm
    

    @ByteInBits, you said

    Normally I would smile and let it pass but I have to take issue with you
    to come to some understanding.

    In post #98171 you state:
    @ByteInBits, your MD5 sum is for the NEXT permutation. By my example, you should start with 1 and not 0.

    This make you incorrect with the entry number!!
    (standard practice doese not start at 1, and you never stated the deviation)

    But I did. When I said:

    Notice that I listed them in a sort of numerical order: 123, 132, 213, 231, 312, 321. There are 3! = 6 of them. If I were to ask you what is the fourth permutation of 1, 2, 3, you should answer “2, 3, 1”. OK, got it?

    I was very careful about making sure the list started at 1, so I said “fourth” instead of “third”. I even stopped to ask if everyone understood before I went on.

    Never wager against a Sicilian when death is on the line.

    #98468
    robb
    Participant

    @ByteInBits PROGRAMMING QUEST #4 #98187 and #98369

    Sorting the list of random numbers was an interesting challenge in this task; for example, the correct ordering of 6531, 65 in set 4. Here’s how I tackled that part:

    def cnvrtsort(s):
    #convert set s to a list with string values sorted in descending order
    sstr = [str(elem) for elem in s]
    sl = list(sorted(sstr, reverse=True))
    sc =compare(sl)
    #Combine sc to get a single number and print
    sf=”.join(sc)
    print(sf)

    def compare(s):
    #compare consecutive elements and swap if needed
    for i in range(0,len(s)-1):
    if s[i][:len(s[i+1])] == s[i+1]:
    a = s[i]
    b = s[i+1]
    rmv=a[len(str(b)):]

    if s[i+1]>rmv:
    #swap order
    s[i] = b
    s[i+1]=a
    return s

    #98486
    ByteInBits
    Participant

    @_madness_ Thank you, and sorry for my misunderstanding of your narrative which now make sense. @rob also helped get me there.

    #98494
    _madness_
    Participant

    @ByteInBits, It’s all cool.

    #98717
    _madness_
    Participant

    If anyone is interested in something almost as much fun as a seriated Polybius cipher, this programming challenge may or may not be hard. I don’t know. The challenge is to find a Pythagorean triple (x^2 + y^2 = z^2) where each number has more than 100 digits. To show you that it might be easy, here is one:

    5448316437483445534218637633951372103721472133084302800181196711700804618365736182804131733102336602000582925889704780559079553695392126450638360766858239249449202384020719285919431179599065584204861405445366919281541626876

    590954136213084844483425568023560779816003827176678161335509531818673831091741858041079741290341646336920339282126397662570865581372141104223408019010508444113688638386186080310786949311722657164655061901989505154837335335001963211536629992088337093907

    590954136213084844483425568023560779816003827176678161335534647263497664985816974232810815094373455008058948195003268779709416780329753566378275824425812622524697460051934566226668094855294530020882890470426060467302586456555110110607191094703028457845

    But then again, maybe it’s hard.

    What’s harder? Constructing examples or checking they are right?! Harry

Viewing 5 posts - 46 through 50 (of 50 total)
  • You must be logged in to reply to this topic.
Report a problem