Can you solve this enigma?

Joined
Dec 1, 2021
Messages
11
Reaction score
0

Rules: The objective is to move the spaceship to the star marked square.
Commands:
left-arrow: turns the spaceship 90º to the left.
right-arrow: turns the spaceship 90º to the right.
move-forward-arrow: moves the spaceship one square forward.
f0: calls teh f0 (initial) fucntion.
You can add either the red or green colors to a command to make it an if then statement (Ex: If I add red to a move-foward-arrow the spaceship will only move foward when it is situated in a red square. This also applies to the f0 command).
If you can find a solution, either using your mind only or building a program that solves it please let me know!
:)
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
Hello! Sorry for the late reply. Is the original page available to the public? I need to tinker to figure it out, I can't just pull the solution out without testing.
 
Joined
Dec 1, 2021
Messages
11
Reaction score
0
Hello! Sorry for the late reply. Is the original page available to the public? I need to tinker to figure it out, I can't just pull the solution out without testing.
Unfortunately the page is not available to the public. I know it's hard to do it by brainpower only. Maybe you can program a similar game. I spent over 1 hour trying to solve this one and it seemed impossible. For the time being I dont have the know-how necessary to program a similar game and solve it by brute force, thats why I asked on a forum.
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
Can you use more than one function? If so, the following might work? If you only get one function, I'm proper stumped and can't even venture a guess.

Code:
f0
--
green straight
green f0
red f1

f1
--
right
straight
left
straight
f1
 
Joined
Dec 1, 2021
Messages
11
Reaction score
0
No. You can only use f0. And you only have 6 commands to add. On the image posted the initial f0 is set by default and cant be removed.
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
Do the left and right arrows just turn the ship or do they actually move the ship to the square it would face? If so, try something weird, like:

Code:
Right
Left
Green f0
Left
Right
f0

I'm kinda spitballing from my phone on this one, and making a weird assumption. But, if the turn arrows don't move the ship, too, I can't imagine six commands being enough. Does it come anywhere close?
 
Joined
Dec 1, 2021
Messages
11
Reaction score
0
Do the left and right arrows just turn the ship or do they actually move the ship to the square it would face? If so, try something weird, like:

Code:
Right
Left
Green f0
Left
Right
f0

I'm kinda spitballing from my phone on this one, and making a weird assumption. But, if the turn arrows don't move the ship, too, I can't imagine six commands being enough. Does it come anywhere close?
The arrows only turn the ship, they dont actually move the ship. It might be the case that this particular exercise was impossible, meaning the site where I was doing the challenge made a fluke. This was part of a series of tests similar to this one to gain admission into a programming school. Maybe I'll email them.
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
Seems unlikely to be a fluke. Alright, last guess before I build a simulator.

Code:
straight
green f0
right
straight
green left
f0
 
Joined
Dec 1, 2021
Messages
11
Reaction score
0
Seems unlikely to be a fluke. Alright, last guess before I build a simulator.

Code:
straight
green f0
right
straight
green left
f0
This code wont solve the problem. The ship will get stuck in one of the grey squares. I think we need 2 "loops": one for moving the ship in a straight line and then another one to zigzag it from the red square to the end square.
 
Joined
Dec 1, 2021
Messages
11
Reaction score
0
Blarg. Is it not allowed on the grey squares?
Its allowed but you lose control of the ship (cant use conditional colors). BTW it has never been the case that using the grey squares was part of the solution so I wouldnt bother considering it.
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
Alright, alright, are you sure? It's possible this code is wrong, forgive me if it is. I'm in a rush. I'm just gonna say, I'm WAY not proud of this code. It ain't my best. If this doesn't work, I'ma write a C++ version and intelligently brute force this sucker 'cause this is making my brain itch. By my count, it finishes after 85 iterations or so. It does do a wonky little loop around the goal there, but it makes its way home eventually. Again, it ain't great, there might be better ways. And my code might be wrong.

Perl:
#!/usr/bin/env perl

use warnings FATAL => 'all';
use strict;

use Scalar::Util qw(looks_like_number);

my $BOARD = [
    # 0    1    2    3    4    5    6    7    8    9    0    1    2    3    4
    [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 0
    [' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 1
    [' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 2
    [' ', ' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 3
    [' ', ' ', ' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 4
    [' ', ' ', ' ', ' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 5
    [' ', ' ', ' ', ' ', ' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 6
    [' ', ' ', ' ', ' ', ' ', ' ', 'R', 'G', 'G', 'G', 'G', 'G', 'G', 'G', ' '], # 7
    [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 8
];
my %SHIP = (
    'l' => '<',
    'r' => '>',
    'u' => '^',
    'd' => 'v',
);
my %NEW_HEADING = (
    'l' => {'r' => 'u', 'l' => 'd'},
    'r' => {'r' => 'd', 'l' => 'u'},
    'u' => {'r' => 'r', 'l' => 'l'},
    'd' => {'r' => 'l', 'l' => 'r'},
);
sub print_board {
    my $board = shift;
    my $ship = shift;
    for (my $y=0;$y<9;$y++){
        for (my $x=0;$x<15;$x++){
            if ($ship && $x == $ship->[0] && $y == $ship->[1]){
                print($SHIP{$ship->[2]});
            } else {
                print($board->[$y][$x]);
            }
        }
        print("\n");
    }
}

my $code = [
    ['s', 'G0', 'r', 's', 'Gl', '0']
];
sub main {
    my $position_x = 13;
    my $position_y = 7;
    my $heading = 'l';
    print_board($BOARD);
    print_board($BOARD, [$position_x, $position_y, $heading]);
    my $iteration = 0;
    my $code_f = 0;
    my $code_i = 0;
    while ($BOARD->[$position_y][$position_x] ne '*' && $iteration++ < 100){
        my $this_code = $code->[$code_f][$code_i];
        my $this_f = $code_f;
        my $this_i = $code_i;
        if ($this_code =~ /^([GRB])?(.)$/){
            if (!$1 || $BOARD->[$position_y][$position_x] eq $1){
                if (looks_like_number($2)){
                    $code_f = int($2);
                    $code_i = 0;
                } else {
                    if ($2 eq 'r' || $2 eq 'l'){
                        $heading = $NEW_HEADING{$heading}{$2};
                    } else { # straight
                        if ($heading eq 'u'){
                            $position_y--;
                        } elsif ($heading eq 'd'){
                            $position_y++;
                        } elsif ($heading eq 'l'){
                            $position_x--
                        } elsif ($heading eq 'r'){
                            $position_x++;
                        }
                    }
                    $code_i++;
                }
            } else {
                $code_i++;
                if ($code_i >= @{$code->[$code_f]}){
                    print("out of code\n");
                    last;
                }
            }
            print("$iteration: $this_f,$this_i => $code_f,$code_i | $this_code\n");
            print_board($BOARD, [$position_x, $position_y, $heading]);
        } else {
            print("bad code: $code_f,$code_i $code->[$code_f][$code_i]\n");
            return 2;
        }
    }
    print("$iteration\n");
    print_board($BOARD, [$position_x, $position_y, $heading]);

    return $iteration < 100;
}

unless (caller){
    exit(main(@ARGV) || 0);
}
Code:
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGG<
              
1: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGG<G
              
2: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGG<G
              
3: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGG<GG
              
4: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGG<GG
              
5: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGG<GGG
              
6: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGG<GGG
              
7: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGG<GGGG
              
8: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGG<GGGG
              
9: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RG<GGGGG
              
10: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RG<GGGGG
              
11: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      R<GGGGGG
              
12: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      R<GGGGGG
              
13: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      <GGGGGGG
              
14: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      <GGGGGGG
              
15: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      ^GGGGGGG
              
16: 0,3 => 0,4 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     G^       
      RGGGGGGG
              
17: 0,4 => 0,5 | Gl
              
 *             
 GG           
  GG           
   GG         
    GG         
     G<       
      RGGGGGGG
              
18: 0,5 => 0,0 | 0
              
 *             
 GG           
  GG           
   GG         
    GG         
     G<       
      RGGGGGGG
              
19: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     <G       
      RGGGGGGG
              
20: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     <G       
      RGGGGGGG
              
21: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
    <GG       
      RGGGGGGG
              
22: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
    <GG       
      RGGGGGGG
              
23: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
   GG         
    GG         
    ^GG       
      RGGGGGGG
              
24: 0,3 => 0,4 | s
              
 *             
 GG           
  GG           
   GG         
    ^G         
     GG       
      RGGGGGGG
              
25: 0,4 => 0,5 | Gl
              
 *             
 GG           
  GG           
   GG         
    <G         
     GG       
      RGGGGGGG
              
26: 0,5 => 0,0 | 0
              
 *             
 GG           
  GG           
   GG         
    <G         
     GG       
      RGGGGGGG
              
27: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
   <GG         
     GG       
      RGGGGGGG
              
28: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
   GG         
   <GG         
     GG       
      RGGGGGGG
              
29: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
   GG         
   ^GG         
     GG       
      RGGGGGGG
              
30: 0,3 => 0,4 | s
              
 *             
 GG           
  GG           
   ^G         
    GG         
     GG       
      RGGGGGGG
              
31: 0,4 => 0,5 | Gl
              
 *             
 GG           
  GG           
   <G         
    GG         
     GG       
      RGGGGGGG
              
32: 0,5 => 0,0 | 0
              
 *             
 GG           
  GG           
   <G         
    GG         
     GG       
      RGGGGGGG
              
33: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
  <GG         
    GG         
     GG       
      RGGGGGGG
              
34: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
  <GG         
    GG         
     GG       
      RGGGGGGG
              
35: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
  ^GG         
    GG         
     GG       
      RGGGGGGG
              
36: 0,3 => 0,4 | s
              
 *             
 GG           
  ^G           
   GG         
    GG         
     GG       
      RGGGGGGG
              
37: 0,4 => 0,5 | Gl
              
 *             
 GG           
  <G           
   GG         
    GG         
     GG       
      RGGGGGGG
              
38: 0,5 => 0,0 | 0
              
 *             
 GG           
  <G           
   GG         
    GG         
     GG       
      RGGGGGGG
              
39: 0,0 => 0,1 | s
              
 *             
 GG           
 <GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
40: 0,1 => 0,2 | G0
              
 *             
 GG           
 <GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
41: 0,2 => 0,3 | r
              
 *             
 GG           
 ^GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
42: 0,3 => 0,4 | s
              
 *             
 ^G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
43: 0,4 => 0,5 | Gl
              
 *             
 <G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
44: 0,5 => 0,0 | 0
              
 *             
 <G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
45: 0,0 => 0,1 | s
              
 *             
<GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
46: 0,1 => 0,2 | G0
              
 *             
<GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
47: 0,2 => 0,3 | r
              
 *             
^GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
48: 0,3 => 0,4 | s
              
^*             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
49: 0,4 => 0,5 | Gl
              
^*             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
50: 0,5 => 0,0 | 0
              
^*             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
51: 0,0 => 0,1 | s
^             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
52: 0,1 => 0,2 | G0
^             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
53: 0,2 => 0,3 | r
>             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
54: 0,3 => 0,4 | s
 >             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
55: 0,4 => 0,5 | Gl
 >             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
56: 0,5 => 0,0 | 0
 >             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
57: 0,0 => 0,1 | s
  >           
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
58: 0,1 => 0,2 | G0
  >           
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
59: 0,2 => 0,3 | r
  v           
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
60: 0,3 => 0,4 | s
              
 *v           
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
61: 0,4 => 0,5 | Gl
              
 *v           
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
62: 0,5 => 0,0 | 0
              
 *v           
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
63: 0,0 => 0,1 | s
              
 *             
 Gv           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
64: 0,1 => 0,0 | G0
              
 *             
 Gv           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
65: 0,0 => 0,1 | s
              
 *             
 GG           
  vG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
66: 0,1 => 0,0 | G0
              
 *             
 GG           
  vG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
67: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
  vGG         
    GG         
     GG       
      RGGGGGGG
              
68: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
  vGG         
    GG         
     GG       
      RGGGGGGG
              
69: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
  <GG         
    GG         
     GG       
      RGGGGGGG
              
70: 0,3 => 0,4 | s
              
 *             
 GG           
  GG           
 < GG         
    GG         
     GG       
      RGGGGGGG
              
71: 0,4 => 0,5 | Gl
              
 *             
 GG           
  GG           
 < GG         
    GG         
     GG       
      RGGGGGGG
              
72: 0,5 => 0,0 | 0
              
 *             
 GG           
  GG           
 < GG         
    GG         
     GG       
      RGGGGGGG
              
73: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
<  GG         
    GG         
     GG       
      RGGGGGGG
              
74: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
<  GG         
    GG         
     GG       
      RGGGGGGG
              
75: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
^  GG         
    GG         
     GG       
      RGGGGGGG
              
76: 0,3 => 0,4 | s
              
 *             
 GG           
^ GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
77: 0,4 => 0,5 | Gl
              
 *             
 GG           
^ GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
78: 0,5 => 0,0 | 0
              
 *             
 GG           
^ GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
79: 0,0 => 0,1 | s
              
 *             
^GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
80: 0,1 => 0,2 | G0
              
 *             
^GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
81: 0,2 => 0,3 | r
              
 *             
>GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
82: 0,3 => 0,4 | s
              
 *             
 >G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
83: 0,4 => 0,5 | Gl
              
 *             
 ^G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
84: 0,5 => 0,0 | 0
              
 *             
 ^G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
85: 0,0 => 0,1 | s
              
 ^             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
85
              
 ^             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
 
Joined
Dec 1, 2021
Messages
11
Reaction score
0
Alright, alright, are you sure? It's possible this code is wrong, forgive me if it is. I'm in a rush. I'm just gonna say, I'm WAY not proud of this code. It ain't my best. If this doesn't work, I'ma write a C++ version and intelligently brute force this sucker 'cause this is making my brain itch. By my count, it finishes after 85 iterations or so. It does do a wonky little loop around the goal there, but it makes its way home eventually. Again, it ain't great, there might be better ways. And my code might be wrong.

Perl:
#!/usr/bin/env perl

use warnings FATAL => 'all';
use strict;

use Scalar::Util qw(looks_like_number);

my $BOARD = [
    # 0    1    2    3    4    5    6    7    8    9    0    1    2    3    4
    [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 0
    [' ', '*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 1
    [' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 2
    [' ', ' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 3
    [' ', ' ', ' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 4
    [' ', ' ', ' ', ' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 5
    [' ', ' ', ' ', ' ', ' ', 'G', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 6
    [' ', ' ', ' ', ' ', ' ', ' ', 'R', 'G', 'G', 'G', 'G', 'G', 'G', 'G', ' '], # 7
    [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], # 8
];
my %SHIP = (
    'l' => '<',
    'r' => '>',
    'u' => '^',
    'd' => 'v',
);
my %NEW_HEADING = (
    'l' => {'r' => 'u', 'l' => 'd'},
    'r' => {'r' => 'd', 'l' => 'u'},
    'u' => {'r' => 'r', 'l' => 'l'},
    'd' => {'r' => 'l', 'l' => 'r'},
);
sub print_board {
    my $board = shift;
    my $ship = shift;
    for (my $y=0;$y<9;$y++){
        for (my $x=0;$x<15;$x++){
            if ($ship && $x == $ship->[0] && $y == $ship->[1]){
                print($SHIP{$ship->[2]});
            } else {
                print($board->[$y][$x]);
            }
        }
        print("\n");
    }
}

my $code = [
    ['s', 'G0', 'r', 's', 'Gl', '0']
];
sub main {
    my $position_x = 13;
    my $position_y = 7;
    my $heading = 'l';
    print_board($BOARD);
    print_board($BOARD, [$position_x, $position_y, $heading]);
    my $iteration = 0;
    my $code_f = 0;
    my $code_i = 0;
    while ($BOARD->[$position_y][$position_x] ne '*' && $iteration++ < 100){
        my $this_code = $code->[$code_f][$code_i];
        my $this_f = $code_f;
        my $this_i = $code_i;
        if ($this_code =~ /^([GRB])?(.)$/){
            if (!$1 || $BOARD->[$position_y][$position_x] eq $1){
                if (looks_like_number($2)){
                    $code_f = int($2);
                    $code_i = 0;
                } else {
                    if ($2 eq 'r' || $2 eq 'l'){
                        $heading = $NEW_HEADING{$heading}{$2};
                    } else { # straight
                        if ($heading eq 'u'){
                            $position_y--;
                        } elsif ($heading eq 'd'){
                            $position_y++;
                        } elsif ($heading eq 'l'){
                            $position_x--
                        } elsif ($heading eq 'r'){
                            $position_x++;
                        }
                    }
                    $code_i++;
                }
            } else {
                $code_i++;
                if ($code_i >= @{$code->[$code_f]}){
                    print("out of code\n");
                    last;
                }
            }
            print("$iteration: $this_f,$this_i => $code_f,$code_i | $this_code\n");
            print_board($BOARD, [$position_x, $position_y, $heading]);
        } else {
            print("bad code: $code_f,$code_i $code->[$code_f][$code_i]\n");
            return 2;
        }
    }
    print("$iteration\n");
    print_board($BOARD, [$position_x, $position_y, $heading]);

    return $iteration < 100;
}

unless (caller){
    exit(main(@ARGV) || 0);
}
Code:
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGG<
              
1: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGG<G
              
2: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGG<G
              
3: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGG<GG
              
4: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGG<GG
              
5: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGG<GGG
              
6: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGG<GGG
              
7: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGG<GGGG
              
8: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGG<GGGG
              
9: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RG<GGGGG
              
10: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RG<GGGGG
              
11: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      R<GGGGGG
              
12: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      R<GGGGGG
              
13: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      <GGGGGGG
              
14: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      <GGGGGGG
              
15: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      ^GGGGGGG
              
16: 0,3 => 0,4 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     G^       
      RGGGGGGG
              
17: 0,4 => 0,5 | Gl
              
 *             
 GG           
  GG           
   GG         
    GG         
     G<       
      RGGGGGGG
              
18: 0,5 => 0,0 | 0
              
 *             
 GG           
  GG           
   GG         
    GG         
     G<       
      RGGGGGGG
              
19: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
     <G       
      RGGGGGGG
              
20: 0,1 => 0,0 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
     <G       
      RGGGGGGG
              
21: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
    GG         
    <GG       
      RGGGGGGG
              
22: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
   GG         
    GG         
    <GG       
      RGGGGGGG
              
23: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
   GG         
    GG         
    ^GG       
      RGGGGGGG
              
24: 0,3 => 0,4 | s
              
 *             
 GG           
  GG           
   GG         
    ^G         
     GG       
      RGGGGGGG
              
25: 0,4 => 0,5 | Gl
              
 *             
 GG           
  GG           
   GG         
    <G         
     GG       
      RGGGGGGG
              
26: 0,5 => 0,0 | 0
              
 *             
 GG           
  GG           
   GG         
    <G         
     GG       
      RGGGGGGG
              
27: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
   GG         
   <GG         
     GG       
      RGGGGGGG
              
28: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
   GG         
   <GG         
     GG       
      RGGGGGGG
              
29: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
   GG         
   ^GG         
     GG       
      RGGGGGGG
              
30: 0,3 => 0,4 | s
              
 *             
 GG           
  GG           
   ^G         
    GG         
     GG       
      RGGGGGGG
              
31: 0,4 => 0,5 | Gl
              
 *             
 GG           
  GG           
   <G         
    GG         
     GG       
      RGGGGGGG
              
32: 0,5 => 0,0 | 0
              
 *             
 GG           
  GG           
   <G         
    GG         
     GG       
      RGGGGGGG
              
33: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
  <GG         
    GG         
     GG       
      RGGGGGGG
              
34: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
  <GG         
    GG         
     GG       
      RGGGGGGG
              
35: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
  ^GG         
    GG         
     GG       
      RGGGGGGG
              
36: 0,3 => 0,4 | s
              
 *             
 GG           
  ^G           
   GG         
    GG         
     GG       
      RGGGGGGG
              
37: 0,4 => 0,5 | Gl
              
 *             
 GG           
  <G           
   GG         
    GG         
     GG       
      RGGGGGGG
              
38: 0,5 => 0,0 | 0
              
 *             
 GG           
  <G           
   GG         
    GG         
     GG       
      RGGGGGGG
              
39: 0,0 => 0,1 | s
              
 *             
 GG           
 <GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
40: 0,1 => 0,2 | G0
              
 *             
 GG           
 <GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
41: 0,2 => 0,3 | r
              
 *             
 GG           
 ^GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
42: 0,3 => 0,4 | s
              
 *             
 ^G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
43: 0,4 => 0,5 | Gl
              
 *             
 <G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
44: 0,5 => 0,0 | 0
              
 *             
 <G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
45: 0,0 => 0,1 | s
              
 *             
<GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
46: 0,1 => 0,2 | G0
              
 *             
<GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
47: 0,2 => 0,3 | r
              
 *             
^GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
48: 0,3 => 0,4 | s
              
^*             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
49: 0,4 => 0,5 | Gl
              
^*             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
50: 0,5 => 0,0 | 0
              
^*             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
51: 0,0 => 0,1 | s
^             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
52: 0,1 => 0,2 | G0
^             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
53: 0,2 => 0,3 | r
>             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
54: 0,3 => 0,4 | s
 >             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
55: 0,4 => 0,5 | Gl
 >             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
56: 0,5 => 0,0 | 0
 >             
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
57: 0,0 => 0,1 | s
  >           
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
58: 0,1 => 0,2 | G0
  >           
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
59: 0,2 => 0,3 | r
  v           
 *             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
60: 0,3 => 0,4 | s
              
 *v           
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
61: 0,4 => 0,5 | Gl
              
 *v           
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
62: 0,5 => 0,0 | 0
              
 *v           
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
63: 0,0 => 0,1 | s
              
 *             
 Gv           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
64: 0,1 => 0,0 | G0
              
 *             
 Gv           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
65: 0,0 => 0,1 | s
              
 *             
 GG           
  vG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
66: 0,1 => 0,0 | G0
              
 *             
 GG           
  vG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
67: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
  vGG         
    GG         
     GG       
      RGGGGGGG
              
68: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
  vGG         
    GG         
     GG       
      RGGGGGGG
              
69: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
  <GG         
    GG         
     GG       
      RGGGGGGG
              
70: 0,3 => 0,4 | s
              
 *             
 GG           
  GG           
 < GG         
    GG         
     GG       
      RGGGGGGG
              
71: 0,4 => 0,5 | Gl
              
 *             
 GG           
  GG           
 < GG         
    GG         
     GG       
      RGGGGGGG
              
72: 0,5 => 0,0 | 0
              
 *             
 GG           
  GG           
 < GG         
    GG         
     GG       
      RGGGGGGG
              
73: 0,0 => 0,1 | s
              
 *             
 GG           
  GG           
<  GG         
    GG         
     GG       
      RGGGGGGG
              
74: 0,1 => 0,2 | G0
              
 *             
 GG           
  GG           
<  GG         
    GG         
     GG       
      RGGGGGGG
              
75: 0,2 => 0,3 | r
              
 *             
 GG           
  GG           
^  GG         
    GG         
     GG       
      RGGGGGGG
              
76: 0,3 => 0,4 | s
              
 *             
 GG           
^ GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
77: 0,4 => 0,5 | Gl
              
 *             
 GG           
^ GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
78: 0,5 => 0,0 | 0
              
 *             
 GG           
^ GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
79: 0,0 => 0,1 | s
              
 *             
^GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
80: 0,1 => 0,2 | G0
              
 *             
^GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
81: 0,2 => 0,3 | r
              
 *             
>GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
82: 0,3 => 0,4 | s
              
 *             
 >G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
83: 0,4 => 0,5 | Gl
              
 *             
 ^G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
84: 0,5 => 0,0 | 0
              
 *             
 ^G           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
85: 0,0 => 0,1 | s
              
 ^             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
              
85
              
 ^             
 GG           
  GG           
   GG         
    GG         
     GG       
      RGGGGGGG
Thanks for the effort. Howeevr dont know what to do with this XD
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
Lol, sorry. The first is the code, you can ignore that. The second one is the output. It shows the iteration, the function number, and the step number. Then, the new ones of those after the actual step. Then, lastly, the actual command. Commands are l for left, r for right, s for straight, or a number to call a function. Commands can be prefixed with R, G, or B to check for the current tile color. Then, it shows the board, an asterisk being the goal, R/G/B being colored tiles, and v, <, >, and ^ for the spaceship. Just follow the little arrow around the boards as it goes down.
 
Joined
Dec 1, 2021
Messages
11
Reaction score
0
Lol, sorry. The first is the code, you can ignore that. The second one is the output. It shows the iteration, the function number, and the step number. Then, the new ones of those after the actual step. Then, lastly, the actual command. Commands are l for left, r for right, s for straight, or a number to call a function. Commands can be prefixed with R, G, or B to check for the current tile color. Then, it shows the board, an asterisk being the goal, R/G/B being colored tiles, and v, <, >, and ^ for the spaceship. Just follow the little arrow around the boards as it goes down.
Im a bit confused. What is the solution then, using the commands in the picture?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top