9
\$\begingroup\$

A text that can be arranged triangularly in some fashion can be read back in some other fashion effectively enciphering it.

Narrowing down a set of plausible triangular numberings allows to individuate the set of plausible transpositions the text underwent.

Consider these 3 basic "scan-line" groupings

       -               /               \     
     -   -           /   /           \   \    
   -   -   -       /   /   /       \   \   \  
 -   -   -   -   /   /   /   /   \   \   \   \

each one can be traversed in 4 different ways (changing direction and orientation)
We have 12 basic numberings.

For example

         1        
       2   3      
     4   5   6    
   7   8   9  10  

 1) 1,2,3,4,5,6,7,8,9,10         -      
 2) 7,8,9,10,4,5,6,2,3,1       -   -    
 3) 1,3,2,6,5,4,10,9,8,7     -   -   -  
 4) 10,9,8,7,6,5,4,3,2,1   -   -   -   -

 5) 10,6,9,3,5,8,1,2,4,7         /      
 6) 1,2,4,7,3,5,8,6,9,10       /   /    
 7) 10,9,6,8,5,3,7,4,2,1     /   /   /  
 8) 7,4,2,1,8,5,3,9,6,10   /   /   /   /

 9) 7,8,4,9,5,2,10,6,3,1         \      
10) 10,6,3,1,9,5,2,8,4,7       \   \    
11) 7,4,8,2,5,9,1,3,6,10     \   \   \  
12) 1,3,6,10,2,5,9,4,8,7   \   \   \   \

Enciphering boils down in mapping a text via the inverse of any one of these mappings and then again through any other one (can be the same, yielding no cipher)

Turns out said 12 basic numberings allows for 22 distinct text transpositions.
Clearly this number doesn't depend on the size of the triangle (except for too small ones having less due to more collision).

Task

Given a positive integer n, n >= 4,
return in any order such 22 distinct triangular transpositions of an n-triangular long text as a list of lists of integers.

This is , shortest solution wins.

mpjheuoicsgdgitemshfairealipepitrycadchnhesid

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Update: considering any 2 of the 3 groupings yields the same transpositions \$\endgroup\$
    – Domenico
    Commented Jun 25 at 21:19
  • \$\begingroup\$ Related: Number triangle flip for just horizontal reflection \$\endgroup\$
    – xnor
    Commented Jun 25 at 21:32
  • \$\begingroup\$ related? puzzling.stackexchange.com/questions/132265/… \$\endgroup\$ Commented Jun 27 at 11:56
  • \$\begingroup\$ @Themoonisacheese they just share being ciphers \$\endgroup\$
    – Domenico
    Commented Jun 27 at 17:05

4 Answers 4

4
\$\begingroup\$

Jelly, 20 bytes

R€UZ$NƭƬ;Ṛ€$F€Ụ€Q;U$

A monadic Link that accepts a positive integer (works for \$<4\$), and yields a list of the permutations.

Try it online!

How?

Build fourteen triangles of integers that represent half (i.e. eleven, with some repetition) of the final permutations; grade them to get the permutations; add the reverse of these to complete the set with the other eleven:

R€UZ$NƭƬ;Ṛ€$F€Ụ€Q;U$ - Link: positive integer, N
R€                   - range of each of [1..N] -> [[1],[1,2],[1,2,3],...,[1..N]
       Ƭ             - collect until a fixed point under:
      ƭ              -   alternate between:
  UZ$                -     a) reverse each then transpose
     N               -     b) negate all elements
                       -> e.g. N=4:
                          [[[ 1], [ 1, 2], [ 1, 2, 3], [ 1, 2, 3, 4]],
                           [[ 1, 2, 3, 4], [ 1, 2, 3], [ 1, 2], [ 1]],
                           [[-1,-2,-3,-4], [-1,-2,-3], [-1,-2], [-1]],
                           [[-4,-3,-2,-1], [-3,-2,-1], [-2,-1], [-1]],
                           [[ 4, 3, 2, 1], [ 3, 2, 1], [ 2, 1], [ 1]],
                           [[ 1, 1, 1, 1], [ 2, 2, 2], [ 3, 3], [ 4]],
                           [[-1,-1,-1,-1], [-2,-2,-2], [-3,-3], [-4]]]
        ;Ṛ€$         - concatenate reverse of each (N.B.: U would reverse sublists)
            F€       - flatten each
                       -> e.g. N=4:
                          [[ 1, 1, 2, 1, 2, 3, 1, 2, 3, 4],
                           [ 1, 2, 3, 4, 1, 2, 3, 1, 2, 1],
                           [-1,-2,-3,-4,-1,-2,-3,-1,-2,-1],
                           [-4,-3,-2,-1,-3,-2,-1,-2,-1,-1],
                           [ 4, 3, 2, 1, 3, 2, 1, 2, 1, 1],
                           [ 1, 1, 1, 1, 2, 2, 2, 3, 3, 4],
                           [-1,-1,-1,-1,-2,-2,-2,-3,-3,-4],
                           [ 1, 2, 3, 4, 1, 2, 3, 1, 2, 1],
                           [ 1, 1, 2, 1, 2, 3, 1, 2, 3, 4],
                           [-1,-1,-2,-1,-2,-3,-1,-2,-3,-4],
                           [-1,-2,-1,-3,-2,-1,-4,-3,-2,-1],
                           [ 1, 2, 1, 3, 2, 1, 4, 3, 2, 1],
                           [ 4, 3, 3, 2, 2, 2, 1, 1, 1, 1],
                           [-4,-3,-3,-2,-2,-2,-1,-1,-1,-1]]
              Ụ€     - grade each (1-indices ordered by values)
                       -> e.g. N=4:
                          [[ 1, 2, 4, 7, 3, 5, 8, 6, 9,10], (a)
                           [ 1, 5, 8,10, 2, 6, 9, 3, 7, 4], (b)
                           [ 4, 3, 7, 2, 6, 9, 1, 5, 8,10],
                           [ 1, 2, 5, 3, 6, 8, 4, 7, 9,10],
                           [ 4, 7, 9,10, 3, 6, 8, 2, 5, 1],
                           [ 1, 2, 3, 4, 5, 6, 7, 8, 9,10], (c)
                           [10, 8, 9, 5, 6, 7, 1, 2, 3, 4],
                           [ 1, 5, 8,10, 2, 6, 9, 3, 7, 4], (dupe of b)
                           [ 1, 2, 4, 7, 3, 5, 8, 6, 9,10], (dupe of a)
                           [10, 6, 9, 3, 5, 8, 1, 2, 4, 7],
                           [ 7, 4, 8, 2, 5, 9, 1, 3, 6,10],
                           [ 1, 3, 6,10, 2, 5, 9, 4, 8, 7],
                           [ 7, 8, 9,10, 4, 5, 6, 2, 3, 1],
                           [ 1, 2, 3, 4, 5, 6, 7, 8, 9,10]] (dupe of c)
                Q    - deduplicate
                 ;U$ - concatenate reverse of each

mpjheuoicsgdgitemshfairealipepitrycadchnhesid decipheringmethodsarehighlyspecificimjustapad

\$\endgroup\$
9
  • \$\begingroup\$ @Niel I didn't calculate 14, I just created the seven shown and their reversals, which results in some that represent the same order as others, giving eleven of the twenty-two, which may then be reflected to produce the remaining eleven. \$\endgroup\$ Commented Jun 26 at 13:00
  • \$\begingroup\$ Err "Neil", sorry! \$\endgroup\$ Commented Jun 26 at 13:17
  • \$\begingroup\$ The bit that confuses me is that there are 12 triangles in the OP so where does your algorithm magic up the other two from? \$\endgroup\$
    – Neil
    Commented Jun 26 at 14:25
  • \$\begingroup\$ I'm not making those triangles; I'm making half of the triangles that represent the final permutations. (Also note 14 is with three duplicates, so really it's eleven.) \$\endgroup\$ Commented Jun 26 at 14:34
  • \$\begingroup\$ Exactly you're somehow calculating these final permutations skipping the question entirely. \$\endgroup\$
    – Neil
    Commented Jun 26 at 15:34
3
\$\begingroup\$

JavaScript (ES10), 173 bytes

Returns a set of comma-separated strings. Values are 0-indexed.

There's probably a significantly shorter way with smarter math.

n=>new Set([...(g=i=>{for(a=[],r=n;r--;)for(x=y=i&2?n-r:r+1;x--;)a.push((X=i&1?y+~x:x,Y=n+~X,i<4?n-y:y+~X)-Y*~Y/2)})+0].map((_,i)=>g(i&7)||a.map(v=>a.indexOf(v),g(i/8))+""))

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ I'd love to know what @JonathanAllan's maths is... \$\endgroup\$
    – Neil
    Commented Jun 26 at 7:00
  • \$\begingroup\$ @Neil I did not really think in terms of math, I just built the orderings up (I did have a look into permutation indexing methods with no joy). \$\endgroup\$ Commented Jun 26 at 11:03
  • \$\begingroup\$ @JonathanAllan Well I don't even understand where you get 14 from in the first place... \$\endgroup\$
    – Neil
    Commented Jun 26 at 11:41
  • \$\begingroup\$ @Neil, transferring the conversation to my answer's comment thread. \$\endgroup\$ Commented Jun 26 at 13:01
2
\$\begingroup\$

Charcoal, 79 76 bytes

≔⟦⟦⁰⟧⟧θF⊖N⊞θE⊕Lθ⁺LΣθκF³«F⟦θ⮌θ⟧⊞⊞OυΣκ⮌Σκ≔⮌E⮌θ⮌Eκ§§⮌θνλθ»≔ΣEυEυEι⌕λνυ⭆¹Φυ⁼μ⌕υλ

Attempt This Online! Link is to verbose version of code. Explanation:

≔⟦⟦⁰⟧⟧θF⊖N⊞θE⊕Lθ⁺LΣθκ

Create the initial triangle.

F³«

Prepare to read it in three directions.

F⟦θ⮌θ⟧⊞⊞OυΣκ⮌Σκ

Read it forwards, backwards, up and down.

≔⮌E⮌θ⮌Eκ§§⮌θνλθ»

Rotate the triangle.

≔ΣEυEυEι⌕λνυ

Get all of the 144 transpositions.

⭆¹Φυ⁼μ⌕υλ

Output only those that are unique.

\$\endgroup\$
2
\$\begingroup\$

Wolfram Language (Mathematica), 182 144 bytes

r=Range;v=Reverse@*Flatten
a_~g~b_:=SortBy[v@l,a[[#]]&][[b]]
f@n_:={}⋃g@@@v[v/@{#,v@#}&/@{#,v/@#}&/@{l=r@#+#(#-1)/2&/@r@n,l~v~{2}},2]~Tuples~2

Just the direct approach

Try it online!

\$\endgroup\$

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.