Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Relative TreePath Hole #1116

Open
Kagre opened this issue Mar 1, 2024 · 1 comment
Open

Add Relative TreePath Hole #1116

Kagre opened this issue Mar 1, 2024 · 1 comment
Labels
hole-idea An idea for a new hole. idea

Comments

@Kagre
Copy link

Kagre commented Mar 1, 2024

Given the infinite binary tree formed by numbering the nodes starting at zero root to leaves left to right.

eg

                         0
                        / \
                       /   \
                      /     \
                     /       \
                    /         \
                   /           \
                  /             \
                 /               \
                /                 \
               /                   \
              /                     \
             /                       \
            /                         \
           1                           2
          / \                        /  \
         /   \                      /    \
        /     \                    /      \
       /       \                  /        \
      /         \                /          \
     3           4              5            6
    / \         / \            / \          / \
   /   \       /   \          /   \        /   \
  7     8     9     10      11     12     13    14
 / \   / \   / \   /  \    /  \   /  \   / \   /  \
15 16 17 18 19 20 21  22  23  24 25  26 27 28 29  30
...

Find the case-sensitive TreePath between two random non-negative integers A and B using the directions: L for left child, R for right child, and P for parent.

eg
between 1 and 2: PR
between 2 and 1: PL
between 0 and 30: RRRR
between 22 and 23: PPPPRLLL

Example input (if any)
These are provided by the hole and could be either hard-coded or generated, the first line is the number of cases, the the following lines are the two integers on a line per-case separated by a space.

4
1 2
2 1
0 30
22 23

Example output
the golfer's algorithm produces the string output line by line corresponding to the cases given by the hole

PR
PL
RRRR
PPPPRLLL

NegaTravel Variant

This time given the doubly infinite mostly-binary graph starting at trunk zero growing positive roots left to right and negative leaves right to left.

eg

...
-30  -29  -28  -27  -26  -25  -24   -23 -22   -21  -20   -19  -18   -17  -16   -15
  \  /      \  /      \  /      \  /       \  /       \  /       \  /       \  /
   -14      -13        -12      -11        -10         -8         -8        -7
     \      /            \      /             \      /              \      /
      \    /              \    /               \    /                \    /
       \  /                \  /                 \  /                  \  /
        -6                  -5                   -4                    -3
          \                /                       \                  /
           \              /                         \                /
            \            /                           \              /
             \          /                             \            /
              \        /                               \          /
               \      /                                 \        /
                \    /                                   \      /
                 \  /                                     \    /
                  -2                                        -1
                    \                                       /
                     -----------------   -------------------
                                      \ /
                                       0
                                      / \
                     -----------------   -------------------
                    /                                       \
                   1                                         2
                 /   \                                    /     \
                /     \                                  /       \
               /       \                                /         \
              /         \                              /           \
             /           \                            /             \
            /             \                          /               \
           /               \                        /                 \
          /                 \                      /                   \
         3                   4                    5                     6
       /   \               /   \                /   \                 /   \
      /     \             /     \              /     \               /     \
     /       \           /       \            /       \             /       \
    7         8         9         10        11         12         13         14
   / \       / \       / \       /  \      /  \       /  \       /  \       /  \
 15   16   17   18   19   20   21    22  23    24   25    26   27    28   29    30
 ...

Find the case-sensitive NegaTravel Path between two random integers A and B using the directions:

  • L for left positive child
  • R for right positive child
  • P for positive parent
  • l for negative left child
  • r for negative right child
  • p for negative parent

eg
between 1 and 2: PR
between 2 and 1: PL
between -1 and -2: pl
between -2 and -1: pr
between 1 and -1: Pr
between -1 and 2: pR
between -23 and 23: ppppRLLL

A Fruitful Imagination Variant

Given the hard to picture yet still countably infinite binary-esque graph starting at trunk zero growing growing positive roots left to right and negative leaves right to left, imagine at each root and leaf a negative fruit growing and positive vines hanging in and out (note: fruit/vies are mirrored not reversed like leaves/roots).

eg

    <--(l)eft                       Leaves                          (r)ight --> 
...
-30  -29  -28  -27  -26  -25  -24   -23 -22   -21  -20   -19  -18   -17  -16   -15  |
  \  /      \  /      \  /      \  /       \  /       \  /       \  /       \  /    |(p)arent
   -14      -13        -12      -11        -10         -8         -8        -7      v
     \      /            \      /             \      /              \      /
      \    /              \    /               \    /                \    /
       \  /                \  /                 \  /                  \  /
        -6                  -5                   -4                    -3
          \                /                       \                  /
           ------    ------                         ------      ------
                 \  /                                     \    /
                  -2                                        -1     Note: these are reversed
                    \                                       /            ------------------
                     -----------------   -------------------                 |
                                      \ /                                    |
                                       0                                     |
                                      / \                                    |
                     -----------------   -------------------                 |
                    /                                       \                |
                   1                                         2     <----------
                 /   \                                    /     \
           ------     ------                        ------       ------
          /                 \                      /                   \
         3                   4                    5                     6
       /   \               /   \                /   \                 /   \
      /     \             /     \              /     \               /     \
     /       \           /       \            /       \             /       \
    7         8         9         10        11         12         13         14     ^
   / \       / \       / \       /  \      /  \       /  \       /  \       /  \    |(P)arent
 15   16   17   18   19   20   21    22  23    24   25    26   27    28   29    30  |
 ...
    <--(L)eft                        Roots                          (R)ight -->


###############################################################################################


    <--(i)n                          Fruit                            (o)ut --> 
...
-15  -16  -17  -18  -19  -20  -21   -22 -23   -24  -25   -26  -27   -28  -29   -30  |
  \  /      \  /      \  /      \  /       \  /       \  /       \  /       \  /    |(h)ome
   -7       -8         -9       -10        -11        -12         -13       -14     v
     \      /            \      /             \      /              \      /
      \    /              \    /               \    /                \    /
       \  /                \  /                 \  /                  \  /
        -3                  -4                   -5                    -6
          \                /                       \                  /
           ------    ------                         ------      ------
                 \  /                                     \    /
                  -1                                        -2     Note: these are mirrored
                    \                                       /            ------------------
                     -----------------   -------------------                 |
                                      \ /                                    |
                        Fruit/Vines of 0 ,every integer has its own...       |
                                      / \                                    |
                     -----------------   -------------------                 |
                    /                                       \                |
                   1                                         2     <----------
                 /   \                                    /     \
           ------     ------                        ------       ------
          /                 \                      /                   \
         3                   4                    5                     6
       /   \               /   \                /   \                 /   \
      /     \             /     \              /     \               /     \
     /       \           /       \            /       \             /       \
    7         8         9         10        11         12         13         14     ^
   / \       / \       / \       /  \      /  \       /  \       /  \       /  \    |(H)ome
 15   16   17   18   19   20   21    22  23    24   25    26   27    28   29    30  |
 ...
    <--(I)n                          Vines                            (O)ut -->

Find the case-sensitive Path between two random integer valued complex numbers A and B using the directions:

  • P for root-parent
    • L for left root-child
    • R for right root-child
  • p for leaf-parent
    • l for left leaf-child
    • r for right leaf-child
  • H for vine-parent
    • I for left vine-child (hmm... I and l could get confusing)
    • O for right vine-child
  • h for fruit-parent
    • i for left fruit-child
    • o for right fruit-child

eg
between 1+0i and 2+0i: PR
between 2+0i and 1+0i: PL
between -1+0i and -2+0i: pl
between -2+0i and -1+0i: pr

between 0+1i and 0+2i: HO
between 0+2i and 0+1i: HI
between 0-1i and 0-2i: hi
between 0-2i and 0-1i: ho

between -23-23i and 23+23i: hhhhppppRLLLOIII

I'm not too sure what would work best for the input of the imaginary numbers maybe

9
1 0 2 0
2 0 1 0
-1 0 -2 0
-2 0 -1 0
0 1 0 2
0 2 0 1
0 -1 0 -2
0 -2 0 -1
-23 -23 23 23

Note

the diagram stops at 30, but the hole can easily be 64-bit integers since the string output length is at most two times the height of the positive tree.

between 7 and 8: PR
between 8 and 9: PPRL
between 9 and 10: PR

@Kagre Kagre added hole-idea An idea for a new hole. idea labels Mar 1, 2024
@Kagre
Copy link
Author

Kagre commented Mar 20, 2024

Looks like I forgot to specify a shortest condition:

Find the shortest case-sensitive ... Path ...

and a couple typos:

between 0-1i and 0-2i: ho
between 0-2i and 0-1i: hi

function Validate-Solution{
   param(
       [string]$Path   = '' # the case sensitive path to take from start to end
      ,[int64] $StartR = 0  # the starting r position
      ,[int64] $StartI = 0  # the starting i position
      ,[int64] $EndR   = 0  # the expected ending r position
      ,[int64] $EndI   = 0  # the expected ending i position
   )

   $r = $StartR
   $i = $StartI
   
   #The shortest path will not back-track away/towards the zero
   $RootsTogg = $LeavesTogg = $VinesTogg = $FruitTogg = $false
   
#debug#>write-host "$r $i $path"
   foreach($d in $Path.ToCharArray()){
      $ok = switch -exact -CaseSensitive ($d) {
       'P'{$i -eq 0 -and $r -gt 0 -and !$RootsTogg                     ;break}
       'L'{$i -eq 0 -and $r -le ([int64]::MaxValue / 2) ;$RootsTogg  = $true;break}
       'R'{$i -eq 0 -and $r -le ([int64]::MaxValue / 2) ;$RootsTogg  = $true;;break}

       'p'{$i -eq 0 -and $r -lt 0 -and !$LeavesTogg                    ;break}
       'l'{$i -eq 0 -and $r -ge ([int64]::MinValue / 2) ;$LeavesTogg = $true;break}
       'r'{$i -eq 0 -and $r -ge ([int64]::MinValue / 2) ;$LeavesTogg = $true;break}

       'H'{$i -gt 0 -and !$VinesTogg                     ;break}
       'I'{$i -le ([int64]::MaxValue / 2) ;$VinesTogg = $true ;break}
       'O'{$i -le ([int64]::MaxValue / 2) ;$VinesTogg = $true ;break}

       'h'{$i -lt 0 -and !$FruitTogg                     ;break}
       'i'{$i -ge ([int64]::MinValue / 2) ;$FruitTogg = $true ;break}
       'o'{$i -ge ([int64]::MinValue / 2) ;$FruitTogg = $true ;break}
       
       default{ $false }
      }
      if(!$ok){ 
#debug#> write-host "Cannot move $d from $r $i    $ok :$RootsTogg,$LeavesTogg,$VinesTogg,$FruitTogg"
         return $false
      }

      switch -exact -CaseSensitive ($d) {
       'P'{$pos = $r + 1 ;$pos -= $pos % 2     ;$pos /= 2 ;$r = $pos - 1 ;break}
       'L'{$pos = $r + 1 ;$pos  = $pos * 2                ;$r = $pos - 1 ;break}
       'R'{$pos = $r + 1 ;$pos  = $pos * 2 + 1            ;$r = $pos - 1 ;break}

       'p'{$pos = 1 - $r ;$pos -= $pos % 2     ;$pos /= 2 ;$r = 1 - $pos ;break}
       'l'{$pos = 1 - $r ;$pos  = $pos * 2 + 1            ;$r = 1 - $pos ;break}
       'r'{$pos = 1 - $r ;$pos  = $pos * 2                ;$r = 1 - $pos ;break}

       'H'{$pos = $i + 1 ;$pos -= $pos % 2     ;$pos /= 2 ;$i = $pos - 1 ;break}
       'I'{$pos = $i + 1 ;$pos  = $pos * 2                ;$i = $pos - 1 ;break}
       'O'{$pos = $i + 1 ;$pos  = $pos * 2 + 1            ;$i = $pos - 1 ;break}

       'h'{$pos = 1 - $i ;$pos -= $pos % 2     ;$pos /= 2 ;$i = 1 - $pos ;break}
       'i'{$pos = 1 - $i ;$pos  = $pos * 2                ;$i = 1 - $pos ;break}
       'o'{$pos = 1 - $i ;$pos  = $pos * 2 + 1            ;$i = 1 - $pos ;break}
      }
#debug#>write-host "$d $r $i"
   }
   
   return $r -eq $EndR -and $i -eq $EndI
}
Validate-Solution 'hhhhppppRLLLOIII' -23 -23 23 23

@(# TreePath
   @{StartR =  1 ;EndR =  2 ;path = 'PR'}
   @{StartR =  2 ;EndR =  1 ;path = 'PL'}
   @{StartR =  0 ;EndR = 30 ;path = 'RRRR'}
   @{StartR = 22 ;EndR = 23 ;path = 'PPPPRLLL'}

  # NegaTravel
   @{StartR =   1 ;EndR =  2 ;path = 'PR'}
   @{StartR =   2 ;EndR =  1 ;path = 'PL'}

   @{StartR =  -1 ;EndR = -2 ;path = 'pl'}
   @{StartR =  -2 ;EndR = -1 ;path = 'pr'}

   @{StartR =   1 ;EndR = -1 ;path = 'Pr'}
   @{StartR =  -1 ;EndR =  2 ;path = 'pR'}

   @{StartR = -22 ;EndR = 23 ;path = 'ppppRLLL'}
   
  # Fruitful Imagination
   @{StartR =   1 ;StartI =  0 ;EndR =  2 ;EndI =  0 ;path = 'PR'}
   @{StartR =   2 ;StartI =  0 ;EndR =  1 ;EndI =  0 ;path = 'PL'}
   @{StartR =  -1 ;StartI =  0 ;EndR = -2 ;EndI =  0 ;path = 'pl'}
   @{StartR =  -2 ;StartI =  0 ;EndR = -1 ;EndI =  0 ;path = 'pr'}

   @{StartR =   0 ;StartI =  1 ;EndR =  0 ;EndI =  2 ;path = 'HO'}
   @{StartR =   0 ;StartI =  2 ;EndR =  0 ;EndI =  1 ;path = 'HI'}
   @{StartR =   0 ;StartI = -1 ;EndR =  0 ;EndI = -2 ;path = 'ho'}
   @{StartR =   0 ;StartI = -2 ;EndR =  0 ;EndI = -1 ;path = 'hi'}

   @{StartR = -23 ;StartI = -23 ;EndR = 23 ;EndI = 23 ;path = 'hhhhppppRLLLOIII'}
) | % { $splat = $_; Validate-Solution @splat ;write-host ''}

Looks like the validator could still use some back-tracking refinement though

Validate-Solution -Path 'PPLR' -StartR 3 -EndR 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hole-idea An idea for a new hole. idea
Projects
None yet
Development

No branches or pull requests

1 participant