Carte de distance minimale des taxis


13

Description du défi

En métrique de taxi , une distance entre deux points entrez la description de l'image iciest définie comme:

entrez la description de l'image ici

Considérons une matrice avec uniquement des zéros et des uns:

0 0 0 1 0
1 0 0 0 0
0 0 0 0 0
1 0 0 1 0
1 0 0 0 0

Mappons chacun 1à la distance au plus proche différent 1 dans la matrice (bien sûr, en supposant que la distance entre deux lignes / colonnes adjacentes est égale à 1):

0 0 0 3 0
2 0 0 0 0
0 0 0 0 0
1 0 0 3 0
1 0 0 0 0

Pour ce défi, étant donné une matrice, trouvez sa carte des distances comme indiqué ci-dessus.

Exemples

0 0 1
0 0 0
0 0 0
0 1 0
0 0 0

0 0 4
0 0 0
0 0 0
0 4 0
0 0 0

-----

0 0 0 0 0 0 1
0 1 0 1 0 0 0
1 1 0 0 0 0 1
0 0 1 0 0 0 0
0 0 0 0 0 1 0
0 1 0 0 0 0 0
1 0 0 0 0 0 0
0 0 0 1 0 0 1

0 0 0 0 0 0 2
0 1 0 2 0 0 0
1 1 0 0 0 0 2
0 0 2 0 0 0 0
0 0 0 0 0 3 0
0 2 0 0 0 0 0
2 0 0 0 0 0 0
0 0 0 3 0 0 3

-----

1 1 1
1 1 1
1 1 1

1 1 1
1 1 1
1 1 1

-----

1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1

22 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 22

-----

0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0

0 0 9 0 0 0 0 0 0 0 0 2 0 0 0 4
0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0

-----
1 1

1 1

Remarques

  • Vous pouvez prendre des contributions dans n'importe quel format raisonnable
  • En dehors de 0et 1vous pouvez choisir deux valeurs distinctes
  • Vous pouvez supposer qu'une matrice n'est pas vide (contient au moins une ligne de longueur supérieure ou égale à 1), ainsi qu'elle est rectangulaire
  • Vous pouvez également supposer qu'il y a au moins deux valeurs véridiques présentes dans la matrice (sinon, la sortie n'est pas définie)
  • Vous pouvez écrire un programme complet ou une fonction
  • Au lieu de renvoyer une nouvelle matrice, vous pouvez modifier une matrice existante
  • C'est du , alors faites en sorte que votre nombre d'octets soit aussi bas que possible!

3
Demander plus d'exemples s'il vous plaît
Urne Magic Octopus

9
Oh, une solution de taxi serait probablement surévaluée> _>
M. Xcoder

Pouvons-nous prendre l'entrée comme un entier (donnant la largeur) et un tableau plat?
Arnauld

1
@ Mr.Xcoder Une solution de taxi serait aussi un cauchemar ... soupire [ouvre TIO]
Engineer Toast

1
@Arnauld me semble un format raisonnable
shooqie

Réponses:


5

MATL , 23 22 octets

tt0*&v&fht1&ZPtg/X<yf(

Essayez-le en ligne! Ou vérifiez tous les cas de test .

Explication

Pour voir les résultats intermédiaires, il peut être utile d'insérer X#(afficher la pile) entre deux états quelconques.

t      % Implicit input: matrix. Duplicate
t0*    % Duplicate and multiply by 0. Gives a matrix of zeros
&v     % Concatenate vertically to input matrix. This is needed
       % in case the input is a row vector, because in that case the
       % subsequent &f would give row vectors, not column vectors
&f     % Push two column vectors with the row and column indices of
       % nonzero elements
h      % Concatenate into a 2-column matrix. Each row gives the
       % coordinates of a nonzero entry in the input matrix
t      % Duplicate
1&ZP   % Taxicab distance between the two copies of the 2-column
       % matrix containing the coordinates. The diagonal contains
       % zeros (distance of each point to itself)
tg     % Duplicate, convert to logical (turn nonzeros into 1)
/      % Divide, element-wise. This leaves off-diagonal entries in
       % the distance matrix unchanged, and sets the diagonal to NaN
X<     % Minimum of each column. NaN values are ignored. The 
       % resulting vector contains the new values to be written in
       % the input matrix
y      % Duplicate from below: push input matrix again
f      % Linear indices of nonzero entries
(      % Assignment indexing: write specified values at specified
       % positions. Implicitly display

1
C'est étonnant. Pas une seule commande de réarrangement de pile, malgré 4 ts et nonM
Sanchises

5

Taxi , 14652 octets

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:s 1 r 1 l 2 r.Pickup a passenger going to Auctioneer School.Pickup a passenger going to Chop Suey.Go to Auctioneer School:n 1 r.1 is waiting at Starchild Numerology.1 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 l.Pickup a passenger going to Rob's Rest.Pickup a passenger going to Bird's Bench.Go to Rob's Rest:w 1 r 2 l 1 r.Go to Bird's Bench:s.Go to Chop Suey:n 1 r 1 l 2 r 1 r 3 r.[a]Switch to plan "d" if no one is waiting.Pickup a passenger going to Crime Lab.'|' is waiting at Writer's Depot.Go to Writer's Depot:n 1 l 3 l.Pickup a passenger going to Crime Lab.Go to Zoom Zoom:n.Go to Crime Lab:w 1 l 2 r.Switch to plan "b" if no one is waiting.Pickup a passenger going to Firemouth Grill.Go to Rob's Rest:s 1 r 1 l 1 l 1 r 1 r.Pickup a passenger going to Firemouth Grill.1 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 l 1 r 2 l.Pickup a passenger going to Cyclone.Go to Cyclone:w 1 r 4 l.Pickup a passenger going to Rob's Rest.Go to Rob's Rest:n 1 r 2 r 1 r.Go to Bird's Bench:s.Pickup a passenger going to Addition Alley.Go to Firemouth Grill:n 1 r 1 l 1 r 1 l 1 r.Go to Cyclone:w 1 l 1 r 2 r.Pickup a passenger going to Addition Alley.Go to Addition Alley:n 2 r 1 r.Pickup a passenger going to Bird's Bench.Go to Bird's Bench:n 1 l 1 l 1 l 2 r 1 l.Switch to plan "c".[b]Go to Rob's Rest:s 1 r 1 l 1 l 1 r 1 r.Pickup a passenger going to Cyclone.Go to Bird's Bench:s.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 r 1 l 2 l.Pickup a passenger going to Trunkers.Pickup a passenger going to Addition Alley.Pickup a passenger going to Sunny Skies Park.Go to Trunkers:s 1 l.1 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 l 2 l.Pickup a passenger going to Addition Alley.Go to Addition Alley:w 1 r 3 r 1 r 1 r.Pickup a passenger going to Rob's Rest.Go to Cyclone:n 1 l 1 l.Pickup a passenger going to Bird's Bench.Go to Sunny Skies Park:n 1 r.Go to Rob's Rest:s 2 r 1 r.Go to Bird's Bench:s.[c]Go to Chop Suey:n 1 r 1 l 2 r 1 r 3 r.Switch to plan "a".[d]Go to Rob's Rest:n 1 l 3 l 1 l 2 r 1 r.Pickup a passenger going to Firemouth Grill.Go to Bird's Bench:s.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:n 1 r 1 l 1 r 1 l 1 r.Go to Auctioneer School:w 1 l 1 r 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:n 4 l.Pickup a passenger going to Auctioneer School.Pickup a passenger going to Chop Suey.Go to Auctioneer School:n 1 r.0 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 l.Pickup a passenger going to Addition Alley.Go to Chop Suey:w 1 r 3 r 1 r 3 r.[e]Switch to plan "g" if no one is waiting.Pickup a passenger going to Cyclone.Go to Zoom Zoom:n 1 l 3 r.Go to Cyclone:w.Pickup a passenger going to Crime Lab.'|' is waiting at Writer's Depot.Go to Writer's Depot:s.Pickup a passenger going to Crime Lab.Go to Zoom Zoom:n.Go to Crime Lab:w 1 l 2 r.Switch to plan "f" if no one is waiting.Pickup a passenger going to Firemouth Grill.Go to Cyclone:n 4 l 2 l.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:s 1 l 2 l 1 r.Go to Chop Suey:e 1 l 4 r 1 l.Switch to plan "e".[f]Go to Cyclone:n 4 l 2 l.Pickup a passenger going to Joyless Park.1 is waiting at Starchild Numerology.Go to Starchild Numerology:s 2 l 2 r.Pickup a passenger going to Addition Alley.Go to Addition Alley:w 1 r 3 r 1 r 1 r.Pickup a passenger going to Addition Alley.Go to Joyless Park:n 1 r 1 r 2 l.Go to Chop Suey:w 1 r 1 r 1 l.Switch to plan "e".[g]Go to Addition Alley:n 1 l 2 l.Pickup a passenger going to Rounders Pub.Go to Rounders Pub:n 1 r 1 r 2 r 1 l.Go to Joyless Park:n 1 r.Pickup a passenger going to KonKat's.[h]Switch to plan "i" if no one is waiting.Pickup a passenger going to KonKat's.Go to Zoom Zoom:w 1 r 2 l 2 r.Go to KonKat's:w 1 l 2 r.Pickup a passenger going to KonKat's.Go to Joyless Park:s 2 l.Switch to plan "h".[i]Go to KonKat's:w 1 r.Pickup a passenger going to Tom's Trims.Go to Tom's Trims:s 3 r 1 l.1 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 r 1 l 1 l 2 l.Pickup a passenger going to Joyless Park.Go to Joyless Park:w 1 r 2 r 1 r 2 l 4 r.[j]Pickup a passenger going to Cyclone.Go to Cyclone:w 1 r 2 l 2 l.Pickup a passenger going to Joyless Park.Pickup a passenger going to The Underground.Go to Joyless Park:n 2 r 2 r 2 l.Go to Tom's Trims:w 1 l 1 r 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:s 1 r 1 l 2 r.Pickup a passenger going to Tom's Trims.Pickup a passenger going to Chop Suey.Go to Tom's Trims:s 1 l 2 r 1 l.Go to Chop Suey:n 1 r 1 l 4 r 1 l.Go to The Underground:s 1 r 1 l.[k]Switch to plan "l" if no one is waiting.Pickup a passenger going to The Underground.Go to Chop Suey:n 2 r 1 l.Pickup a passenger going to Firemouth Grill.Go to Zoom Zoom:n 1 l 3 r.Go to Firemouth Grill:w 3 l 2 l 1 r.Go to The Underground:e 1 l.Switch to plan "k".[l]Go to Chop Suey:n 2 r 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 r 1 l.Go to Chop Suey:n 6 r 1 l.[m]Switch to plan "o" if no one is waiting.Pickup a passenger going to Firemouth Grill.Switch to plan "n" if no one is waiting.Pickup a passenger going to Firemouth Grill.Switch to plan "n" if no one is waiting.Pickup a passenger going to Firemouth Grill.[n]Go to Zoom Zoom:n 1 l 3 r.Go to Firemouth Grill:w 3 l 2 l 1 r.Go to Chop Suey:e 1 l 4 r 1 l.Switch to plan "m".[o]Go to The Babelfishery:s 1 r 1 l.Pickup a passenger going to The Underground.Go to The Underground:n.Switch to plan "p" if no one is waiting.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:s 1 r.Go to Joyless Park:e 1 l 3 r.Switch to plan "q".[p]' 0' is waiting at Writer's Depot.Go to Writer's Depot:s 2 r 1 l 2 l.Pickup a passenger going to Heisenberg's.Go to Heisenberg's:n 3 r 3 r.Go to Joyless Park:s 1 r 1 l 1 l.Switch to plan "4".[q]Pickup a passenger going to Cyclone.Go to Cyclone:w 1 r 2 l 2 l.Pickup a passenger going to Joyless Park.Pickup a passenger going to The Underground.Go to Joyless Park:n 2 r 2 r 2 l.Go to Trunkers:w 1 l 2 r 1 l.[r]Pickup a passenger going to Cyclone.Go to Sunny Skies Park:w 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l.Pickup a passenger going to Trunkers.Pickup a passenger going to Rob's Rest.Go to Trunkers:s 1 l.Go to Rob's Rest:w 1 l 1 r 1 r.Go to Cyclone:s 1 l 1 l 2 l.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Bird's Bench.Go to Zoom Zoom:n.Go to Sunny Skies Park:w 2 l.Go to Bird's Bench:s 2 r 1 l.Go to The Underground:n 1 r 1 l 1 r 1 r 2 l.Switch to plan "s" if no one is waiting.Pickup a passenger going to The Underground.Go to Rob's Rest:s 2 r 1 l 1 l 1 r 1 r.Pickup a passenger going to Firemouth Grill.Go to Bird's Bench:s.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:n 1 r 1 l 1 r 1 l 1 r.Go to Trunkers:w 1 l 1 r.Switch to plan "r".[s]Go to Rounders Pub:n 1 l 1 l.Pickup a passenger going to Cyclone.Go to Joyless Park:n 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:w 1 r 2 l 2 l.Pickup a passenger going to Rounders Pub.Pickup a passenger going to What's The Difference.Pickup a passenger going to Joyless Park.Go to Rounders Pub:n 2 r 2 r 2 r 1 l.Go to Joyless Park:n 1 r.Go to Cyclone:w 1 r 2 l 2 l.Pickup a passenger going to What's The Difference.1 is waiting at Starchild Numerology.Go to Starchild Numerology:s 2 l 2 r.Pickup a passenger going to Addition Alley.Go to What's The Difference:w 1 r 3 r 1 l.Pickup a passenger going to Addition Alley.Go to Addition Alley:e 2 r.Pickup a passenger going to The Underground.Go to The Underground:n 1 r 1 r.[t]Switch to plan "u" if no one is waiting.Pickup a passenger going to The Underground.Go to Trunkers:s 2 r 1 l.Pickup a passenger going to Trunkers.Go to Sunny Skies Park:w 1 r.Pickup a passenger going to Sunny Skies Park.Go to Zoom Zoom:n 1 r.Go to The Underground:w 1 l 2 r.Switch to plan "t".[u]Go to Trunkers:s 2 r 1 l.Go to Sunny Skies Park:w 1 r.Go to Tom's Trims:s 1 l 1 r 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:s 1 r 1 l 2 r.Pickup a passenger going to Tom's Trims.Pickup a passenger going to Chop Suey.Go to Tom's Trims:s 1 l 2 r 1 l.Go to Chop Suey:n 1 r 1 l 4 r 1 l.[v]Switch to plan "0" if no one is waiting.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 r 1 l.Pickup a passenger going to The Underground.Go to The Underground:n.Switch to plan "z" if no one is waiting.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:s 1 r.Go to Trunkers:w 1 l 1 r.Pickup a passenger going to Cyclone.Go to Rob's Rest:w 1 l 1 r 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:s 1 l 1 l 2 l.Pickup a passenger going to Trunkers.Pickup a passenger going to What's The Difference.Pickup a passenger going to Rob's Rest.Go to Trunkers:s 1 l.Go to Rob's Rest:w 1 l 1 r 1 r.1 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 l 1 r 2 l.Pickup a passenger going to Addition Alley.Go to Cyclone:w 1 r 4 l.Pickup a passenger going to What's The Difference.Go to Zoom Zoom:n.Go to What's The Difference:w 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:e 1 r.Pickup a passenger going to Addition Alley.Pickup a passenger going to Multiplication Station.Go to Addition Alley:n 2 r 1 r.Pickup a passenger going to The Underground.Go to The Underground:n 1 r 1 r.Switch to plan "w" if no one is waiting.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:s 1 r.-1 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 l 1 r 1 l 2 l.Pickup a passenger going to Multiplication Station.Go to The Underground:w 1 r 2 r 1 r 2 l.[w]Go to Multiplication Station:s 1 l 1 r.Go to Sunny Skies Park:s 1 r 2 l 1 r.Pickup a passenger going to Cyclone.Go to Bird's Bench:s 2 r 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 r 1 l 2 l.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to What's The Difference.Pickup a passenger going to Bird's Bench.Go to Sunny Skies Park:n 1 r.Go to Bird's Bench:s 2 r 1 l.1 is waiting at Starchild Numerology.Go to Starchild Numerology:n 1 r 1 r 2 l.Pickup a passenger going to Addition Alley.Go to Cyclone:w 1 r 4 l.Pickup a passenger going to What's The Difference.Go to What's The Difference:n 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:e 1 r.Pickup a passenger going to Addition Alley.Pickup a passenger going to Multiplication Station.Go to Addition Alley:n 2 r 1 r.Pickup a passenger going to The Underground.Go to The Underground:n 1 r 1 r.Switch to plan "x" if no one is waiting.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:s 1 r.-1 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 l 1 r 1 l 2 l.Pickup a passenger going to Multiplication Station.Go to The Underground:w 1 r 2 r 1 r 2 l.[x]Go to Multiplication Station:s 1 l 1 r.Pickup a passenger going to Addition Alley.Pickup a passenger going to Addition Alley.-1 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 r 2 l 1 l 2 l.Pickup a passenger going to Multiplication Station.Go to Addition Alley:w 1 r 3 r 1 r 1 r.Pickup a passenger going to Multiplication Station.Go to Multiplication Station:n 1 r 1 r 3 l 1 r.Pickup a passenger going to Addition Alley.1 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 r 2 l 1 l 2 l.Pickup a passenger going to Addition Alley.Go to Addition Alley:w 1 r 3 r 1 r 1 r.Pickup a passenger going to The Underground.Go to The Underground:n 1 r 1 r.Switch to plan "y" if no one is waiting.Pickup a passenger going to Narrow Path Park.[y]Go to Narrow Path Park:n 4 l.Go to Chop Suey:e 1 r 1 l 1 r.Switch to plan "v".[z]Go to Trunkers:s 2 r 1 l.Pickup a passenger going to Trunkers.Go to Sunny Skies Park:w 1 r.Pickup a passenger going to Sunny Skies Park.Go to Zoom Zoom:n 1 r.Go to Trunkers:w 3 l.Go to Sunny Skies Park:w 1 r.Go to Chop Suey:n 1 r 1 r 3 r.Switch to plan "v".[0]Go to Rob's Rest:n 1 l 3 l 1 l 2 r 1 r.Pickup a passenger going to Firemouth Grill.Go to Bird's Bench:s.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:n 1 r 1 l 1 r 1 l 1 r.Go to Narrow Path Park:e 1 l 4 l.Pickup a passenger going to Writer's Depot.[1]Switch to plan "3" if no one is waiting.Pickup a passenger going to Cyclone.Go to Zoom Zoom:w 1 l 1 r 1 r.Go to Writer's Depot:w.Pickup a passenger going to Magic Eight.Go to Cyclone:n.Pickup a passenger going to Magic Eight.Go to Magic Eight:s 1 l 2 r.Switch to plan "2" if no one is waiting.Pickup a passenger going to Writer's Depot.Go to Cyclone:n 1 l 2 r.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:s 1 l 2 l 1 r.Go to Narrow Path Park:e 1 l 4 l.Switch to plan "1".[2]Go to Cyclone:n 1 l 2 r.Pickup a passenger going to Writer's Depot.Go to Narrow Path Park:n 2 r 1 l 1 r.Switch to plan "1".[3]Go to Writer's Depot:w 1 l 1 r 2 l.Pickup a passenger going to The Babelfishery.' ' is waiting at Writer's Depot.Pickup a passenger going to KonKat's.Go to The Babelfishery:n 1 r 2 r 1 r.Pickup a passenger going to KonKat's.Go to KonKat's:n.Pickup a passenger going to Heisenberg's.Go to Heisenberg's:n 1 r 1 r.Go to Joyless Park:s 1 r 1 l 1 l.[4]Pickup a passenger going to Magic Eight.Go to Rounders Pub:w 2 l.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 r 1 l 2 l 2 l.Pickup a passenger going to Rounders Pub.Pickup a passenger going to Magic Eight.Go to Rounders Pub:n 2 r 2 r 2 r 1 l.Go to Magic Eight:n 1 r 1 r 2 r.Switch to plan "5" if no one is waiting.Pickup a passenger going to Addition Alley.1 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 l 1 l 2 l.Pickup a passenger going to Addition Alley.Go to Addition Alley:w 1 r 3 r 1 r 1 r.Pickup a passenger going to Joyless Park.Go to Joyless Park:n 1 r 1 r 2 l.Switch to plan "j".[5]Go to Auctioneer School:w 1 l 1 l.Pickup a passenger going to Chop Suey.Go to Chop Suey:n 3 r 1 r 3 r.[6]Switch to plan "9" if no one is waiting.Pickup a passenger going to Crime Lab.'|' is waiting at Writer's Depot.Go to Writer's Depot:n 1 l 3 l.Pickup a passenger going to Crime Lab.Go to Zoom Zoom:n.Go to Crime Lab:w 1 l 2 r.Switch to plan "7" if no one is waiting.Pickup a passenger going to Firemouth Grill.Go to Firemouth Grill:n 1 l.'\n' is waiting at Writer's Depot.Go to Writer's Depot:w 1 l 1 r 2 l.Pickup a passenger going to KonKat's.Go to KonKat's:n 3 r 2 r.Switch to plan "8".[7]Go to Heisenberg's:n 5 r 1 l.Pickup a passenger going to KonKat's.Go to KonKat's:n 1 l 1 l.[8]Pickup a passenger going to KonKat's.Go to Chop Suey:n 1 r 1 r.Switch to plan "6".[9]Go to KonKat's:n 1 l 1 l.Pickup a passenger going to Post Office.Go to Post Office:s 3 r 1 l.

Essayez-le en ligne!

Je suppose qu'aucun humain ne veut essayer de lire ce code, alors essayez-le en ligne avec des commentaires, des étiquettes significatives et une sortie plus lisible!


Entrée: chaîne représentant un tableau. La chaîne doit être composée de 3 caractères: 0, |représentant sauts de lignes, et tout plus de chiffres positifs d'une (PDGTO). J'aime utiliser 8. OP permet la saisie dans n'importe quel format raisonnable et je pense que cela est admissible. La chaîne n'a pas à être formatée en un tableau rectangulaire, mais elle sera supposée alignée à gauche quelle qu'elle soit.

Sortie: tableau de valeurs indiquant la distance minimale de la cabine de taxi de chacune PDGTOà l'autre la plus proche PDGTO.

Exemple:

OP's Input:         OP's Output:
-------------       -------------
0 0 0 0 0 0 1       0 0 0 0 0 0 2
0 1 0 1 0 0 0       0 1 0 2 0 0 0
1 1 0 0 0 0 1       1 1 0 0 0 0 2
0 0 1 0 0 0 0       0 0 2 0 0 0 0
0 0 0 0 0 1 0       0 0 0 0 0 3 0
0 1 0 0 0 0 0       0 2 0 0 0 0 0
1 0 0 0 0 0 0       2 0 0 0 0 0 0
0 0 0 1 0 0 1       0 0 0 3 0 0 3

Taxi Input: 0000008|0808000|8800008|0080000|0000080|0800000|8000000|0008008

Taxi Output: (golfed)
------------------------------------
 0 0 0 0 0 0 2.000000
 0 1.000000 0 2.000000 0 0 0
 1.000000 1.000000 0 0 0 0 2.000000
 0 0 2.000000 0 0 0 0
 0 0 0 0 0 3.000000 0
 0 2.000000 0 0 0 0 0
 2.000000 0 0 0 0 0 0
 0 0 0 3.000000 0 0 3.000000

Taxi Output: (ungolfed version)
------------------------------------
 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 2.000000
 0.000000 1.000000 0.000000 2.000000 0.000000 0.000000 0.000000
 1.000000 1.000000 0.000000 0.000000 0.000000 0.000000 2.000000
 0.000000 0.000000 2.000000 0.000000 0.000000 0.000000 0.000000
 0.000000 0.000000 0.000000 0.000000 0.000000 3.000000 0.000000
 0.000000 2.000000 0.000000 0.000000 0.000000 0.000000 0.000000
 2.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
 0.000000 0.000000 0.000000 3.000000 0.000000 0.000000 3.000000

Le deuxième format de sortie est clairement beaucoup plus facile à lire, mais il ajoute également 7 octets au programme et c'est du , après tout. Il aurait été possible de revenir en arrière à la fin et de supprimer tous les zéros de fin au lieu de simplement remplir les 0valeurs, mais cela aurait ajouté encore plus d'octets et était considéré comme un coût inacceptable.


Voici le texte du code non-golfé avec des commentaires, de meilleures étiquettes et une sortie plus claire:
(C'est la même chose que vous obtenez avec le lien ci-dessus.)

[ Minimal Taxi Cab Distance ]
[ Inspired by: /codegolf//q/138311 ]

[ INPUT:  String of 8 & 0 using a pipe | as a delineator for each row of the array                  ]
[ OUTPUT: String formatted as an array showing min taxi distance from each 8 to the nearest other 8 ]
[ Note:   Any single digit > 1 may be substituted for 8. I.E., it must be 2 <= i <= 9               ]

[ PROCESS:                                                                 ]
[ Store STDIN exactly as input and keep it around until the end            ]
[ Store 3 arrays: Input, X Positions, Y Positions                          ]
[ Store a count of how many elements are in Input                          ]
[ For each element in Input, create an array of minimal taxi cab distances ]
[ Find the minimum value greater than zero in that array and store it      ]
[ Pad with a space and, if it's the last element in the row, a line break  ]
[ Repeat for each element, storing the minimums each time                  ]
[ Concatenate all the results and output                                   ]

[ DATA                     LOCATION              REASON                    ]
[ Input                    Auctioneer School     Close to Cyclone          ]
[ Input w/o Delineator     Tom's Trims           Running out of options    ]
[ Elements in Input        Rounders Pub          Close to Joyless Park     ]
[ Iteration                Joyless Park          Close to The Underground  ]
[ X Positions              Trunkers              Close to Rob's Rest       ]
[ Y Positions              Sunny Skies Park      Close to Bird's Bench     ]
[ Element's X              Rob's Rest            Easy to remember          ]
[ Element's Y              Bird's Bench          Easy to remember          ]
[ Array of distances       Narrow Path Park      LIFO is OK for this       ]
[ Array of minimums        Heisenberg's          Close to KonKat's         ]

[ Note: We use the Input w/o Delineator to keep track of iteration             ]
[ By storing it at Chop Suey, we can keep going until we run out of passengers ]

[ Note: When using arrays other than the Input w/o Delineator, is it critical  ]
[ that we clone each element and enque it again. The iteration tracking will   ]
[ let us stop before we go through the array again.                            ]

[ Some things I learned about Taxi in TIO while writing this:                            ]
[  - You can store any passenger at Writer's Depot and Starchild Numerology              ]
[  - You can store any passenger at Heisenberg's and even pick them up again *in order*  ]
[    (You don't start picking up random integers until that queue is gone)               ]
[  - If you try to drop someone at Rob's Rest or Bird's Bench but it's already occupied, ]
[    it won't error out. The passenger just stays in the Taxi which will probably cause  ]
[    a "Too Many Passengers" error eventually. It cost me a week figuring that one out.  ]




[ Pickup stdin and split it into elements ]
Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to Cyclone.
Go to Cyclone: south 1st right 1st left 2nd right.
Pickup a passenger going to Auctioneer School.
Pickup a passenger going to Chop Suey.
Go to Auctioneer School: north 1st right.
1 is waiting at Starchild Numerology.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st left.
Pickup a passenger going to Rob's Rest.
Pickup a passenger going to Bird's Bench.
Go to Rob's Rest: west 1st right 2nd left 1st right.
Go to Bird's Bench: south.
Go to Chop Suey: north 1st right 1st left 2nd right 1st right 3rd right.

[ Create the arrays of X & Y positions ]
[NextInputElement]
Switch to plan "XYCreated" if no one is waiting.
Pickup a passenger going to Crime Lab.
'|' is waiting at Writer's Depot.
Go to Writer's Depot: north 1st left 3rd left.
Pickup a passenger going to Crime Lab.
Go to Zoom Zoom: north.
Go to Crime Lab: west 1st left 2nd right.
Switch to plan "NextColumn" if no one is waiting.

[ Next Row ]
[ Set X = 1 and Y = Y + 1 ]
Pickup a passenger going to Firemouth Grill.
Go to Rob's Rest: south 1st right 1st left 1st left 1st right 1st right.
Pickup a passenger going to Firemouth Grill.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st left 1st right 2nd left.
Pickup a passenger going to Cyclone.
Go to Cyclone: west 1st right 4th left.
Pickup a passenger going to Rob's Rest.
Go to Rob's Rest: north 1st right 2nd right 1st right.
Go to Bird's Bench: south.
Pickup a passenger going to Addition Alley.
Go to Firemouth Grill: north 1st right 1st left 1st right 1st left 1st right.
Go to Cyclone: west 1st left 1st right 2nd right.
Pickup a passenger going to Addition Alley.
Go to Addition Alley: north 2nd right 1st right.
Pickup a passenger going to Bird's Bench.
Go to Bird's Bench: north 1st left 1st left 1st left 2nd right 1st left.
Switch to plan "EndOfElement".

[NextColumn]
[ Set X = X + 1, Store X & Y positions ]
Go to Rob's Rest: south 1st right 1st left 1st left 1st right 1st right.
Pickup a passenger going to Cyclone.
Go to Bird's Bench: south.
Pickup a passenger going to Cyclone.
Go to Cyclone: north 1st right 1st left 2nd left.
Pickup a passenger going to Trunkers.
Pickup a passenger going to Addition Alley.
Pickup a passenger going to Sunny Skies Park.
Go to Trunkers: south 1st left.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: west 1st left 2nd left.
Pickup a passenger going to Addition Alley.
Go to Addition Alley: west 1st right 3rd right 1st right 1st right.
Pickup a passenger going to Rob's Rest.
Go to Cyclone: north 1st left 1st left.
Pickup a passenger going to Bird's Bench.
Go to Sunny Skies Park: north 1st right.
Go to Rob's Rest: south 2nd right 1st right.
Go to Bird's Bench: south.

[EndOfElement]
Go to Chop Suey: north 1st right 1st left 2nd right 1st right 3rd right.
Switch to plan "NextInputElement".

[XYCreated]
[ Clean up the leftovers ]
Go to Rob's Rest: north 1st left 3rd left 1st left 2nd right 1st right.
Pickup a passenger going to Firemouth Grill.
Go to Bird's Bench: south.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: north 1st right 1st left 1st right 1st left 1st right.

[ Create the Input w/o Delineator string ]
Go to Auctioneer School: west 1st left 1st right 1st left.
Pickup a passenger going to Cyclone.
Go to Cyclone: north 4th left.
Pickup a passenger going to Auctioneer School.
Pickup a passenger going to Chop Suey.
Go to Auctioneer School: north 1st right.
0 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st left.
Pickup a passenger going to Addition Alley.
Go to Chop Suey: west 1st right 3rd right 1st right 3rd right.

[NextInputWithoutDelineatorElement]
Switch to plan "DelineatorRemoved" if no one is waiting.
Pickup a passenger going to Cyclone.
Go to Zoom Zoom: north 1st left 3rd right.
Go to Cyclone: west.
Pickup a passenger going to Crime Lab.
'|' is waiting at Writer's Depot.
Go to Writer's Depot: south.
Pickup a passenger going to Crime Lab.
Go to Zoom Zoom: north.
Go to Crime Lab: west 1st left 2nd right.
Switch to plan "NotAPipe" if no one is waiting.
Pickup a passenger going to Firemouth Grill.
Go to Cyclone: north 4th left 2nd left.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: south 1st left 2nd left 1st right.
Go to Chop Suey: east 1st left 4th right 1st left.
Switch to plan "NextInputWithoutDelineatorElement".

[NotAPipe]
Go to Cyclone: north 4th left 2nd left.
Pickup a passenger going to Joyless Park.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 2nd left 2nd right.
Pickup a passenger going to Addition Alley.
Go to Addition Alley: west 1st right 3rd right 1st right 1st right.
Pickup a passenger going to Addition Alley.
Go to Joyless Park: north 1st right 1st right 2nd left.
Go to Chop Suey: west 1st right 1st right 1st left.
Switch to plan "NextInputWithoutDelineatorElement".

[DelineatorRemoved]
Go to Addition Alley: north 1st left 2nd left.
Pickup a passenger going to Rounders Pub.
Go to Rounders Pub: north 1st right 1st right 2nd right 1st left.
Go to Joyless Park: north 1st right.
Pickup a passenger going to KonKat's.

[NextBit]
Switch to plan "EndOfBits" if no one is waiting.
Pickup a passenger going to KonKat's.
Go to Zoom Zoom: west 1st right 2nd left 2nd right.
Go to KonKat's: west 1st left 2nd right.
Pickup a passenger going to KonKat's.
Go to Joyless Park: south 2nd left.
Switch to plan "NextBit".

[EndOfBits]
Go to KonKat's: west 1st right.
Pickup a passenger going to Tom's Trims.
Go to Tom's Trims: south 3rd right 1st left.

[ Start with the first character ]
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st right 1st left 1st left 2nd left.
Pickup a passenger going to Joyless Park.
Go to Joyless Park: west 1st right 2nd right 1st right 2nd left 4th right.



[ At this point, we have the following data structure: ]
[ Input                           Auctioneer School    ]
[ Input w/o Delineator (IwoD)     Tom's Trims          ]
[ Elements in Input               Rounders Pub         ]
[ Iteration = 1                   Joyless Park         ]
[ X Positions                     Trunkers             ]
[ Y Positions                     Sunny Skies Park     ]
[                                                      ]
[ Now, we use Joyless Park to track our starting point ]
[ and IwoD to iterate through all the destinations. If ]
[ the starting point's value is <=1, then add '0 ' to  ]
[ Heisenberg's and go to the next element. If value    ]
[ is >1, then calculate the distance to every other    ]
[ element. IwoD will start full and be emptied as we   ]
[ iterate through all the possible destinations. Once  ]
[ that's done, cycle back through those results until  ]
[ we find the smallest value >0 and add that to        ]
[ Heisenberg's. Either way, in order to move to        ]
[ the next starting point, we add 1 to Joyless Park,   ]
[ check that it's less than Rounders Pub, and loop. If ]
[ it's not less, then we're done so we can go build    ]
[ the output with the passengers at Heisenberg's.      ]
[ We'll use the Auctioneer School to find pipes so we  ]
[ can add line breaks to the output as needed.         ]

[NextElementForStartingPoint]

[ Extract this element's value ]
Pickup a passenger going to Cyclone.
Go to Cyclone: west 1st right 2nd left 2nd left.
Pickup a passenger going to Joyless Park.
Pickup a passenger going to The Underground.
Go to Joyless Park: north 2nd right 2nd right 2nd left.
Go to Tom's Trims: west 1st left 1st right 1st left.
Pickup a passenger going to Cyclone.
Go to Cyclone: south 1st right 1st left 2nd right.
Pickup a passenger going to Tom's Trims.
Pickup a passenger going to Chop Suey.
Go to Tom's Trims: south 1st left 2nd right 1st left.
Go to Chop Suey: north 1st right 1st left 4th right 1st left.
Go to The Underground: south 1st right 1st left.

[GetTheNextElement]
Switch to plan "FoundThisElement" if no one is waiting.
Pickup a passenger going to The Underground.
Go to Chop Suey: north 2nd right 1st left.
Pickup a passenger going to Firemouth Grill.
Go to Zoom Zoom: north 1st left 3rd right.
Go to Firemouth Grill: west 3rd left 2nd left 1st right.
Go to The Underground: east 1st left.
Switch to plan "GetTheNextElement".

[FoundThisElement]
Go to Chop Suey: north 2nd right 1st left.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: south 1st right 1st left.
Go to Chop Suey: north 6th right 1st left.

[TrashNextElement]
Switch to plan "ElementsAllTrashed" if no one is waiting.
Pickup a passenger going to Firemouth Grill.
Switch to plan "AllRiders" if no one is waiting.
Pickup a passenger going to Firemouth Grill.
Switch to plan "AllRiders" if no one is waiting.
Pickup a passenger going to Firemouth Grill.
[AllRiders]
Go to Zoom Zoom: north 1st left 3rd right.
Go to Firemouth Grill: west 3rd left 2nd left 1st right.
Go to Chop Suey: east 1st left 4th right 1st left.
Switch to plan "TrashNextElement".

[ElementsAllTrashed]
Go to The Babelfishery: south 1st right 1st left.
Pickup a passenger going to The Underground.
Go to The Underground: north.
Switch to plan "ItsAZero" if no one is waiting.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: south 1st right.
Go to Joyless Park: east 1st left 3rd right.
Switch to plan "ExtractXY".

[ItsAZero]
' 0.000000' is waiting at Writer's Depot.
Go to Writer's Depot: south 2nd right 1st left 2nd left.
Pickup a passenger going to Heisenberg's.
Go to Heisenberg's: north 3rd right 3rd right.
Go to Joyless Park: south 1st right 1st left 1st left.
Switch to plan "GotoNextStartingPoint".

[ Extract the X & Y values for this element ]
[ExtractXY]
Pickup a passenger going to Cyclone.
Go to Cyclone: west 1st right 2nd left 2nd left.
Pickup a passenger going to Joyless Park.
Pickup a passenger going to The Underground.
Go to Joyless Park: north 2nd right 2nd right 2nd left.
Go to Trunkers: west 1st left 2nd right 1st left.

[GetNextXY]
Pickup a passenger going to Cyclone.
Go to Sunny Skies Park: west 1st right.
Pickup a passenger going to Cyclone.
Go to Cyclone: north 1st left.
Pickup a passenger going to Trunkers.
Pickup a passenger going to Rob's Rest.
Go to Trunkers: south 1st left.
Go to Rob's Rest: west 1st left 1st right 1st right.
Go to Cyclone: south 1st left 1st left 2nd left.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Bird's Bench.
Go to Zoom Zoom: north.
Go to Sunny Skies Park: west 2nd left.
Go to Bird's Bench: south 2nd right 1st left.
Go to The Underground: north 1st right 1st left 1st right 1st right 2nd left.
Switch to plan "FoundXY" if no one is waiting.
Pickup a passenger going to The Underground.
Go to Rob's Rest: south 2nd right 1st left 1st left 1st right 1st right.
Pickup a passenger going to Firemouth Grill.
Go to Bird's Bench: south.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: north 1st right 1st left 1st right 1st left 1st right.
Go to Trunkers: west 1st left 1st right.
Switch to plan "GetNextXY".

[FoundXY]
[ Keep rotating the arrays until they're back to normal ]
Go to Rounders Pub: north 1st left 1st left.
Pickup a passenger going to Cyclone.
Go to Joyless Park: north 1st right.
Pickup a passenger going to Cyclone.
Go to Cyclone: west 1st right 2nd left 2nd left.
Pickup a passenger going to Rounders Pub.
Pickup a passenger going to What's The Difference.
Pickup a passenger going to Joyless Park.
Go to Rounders Pub: north 2nd right 2nd right 2nd right 1st left.
Go to Joyless Park: north 1st right.
Go to Cyclone: west 1st right 2nd left 2nd left.
Pickup a passenger going to What's The Difference.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 2nd left 2nd right.
Pickup a passenger going to Addition Alley.
Go to What's The Difference: west 1st right 3rd right 1st left.
Pickup a passenger going to Addition Alley.
Go to Addition Alley: east 2nd right.
Pickup a passenger going to The Underground.
Go to The Underground: north 1st right 1st right.

[RotateXY]
Switch to plan "XYareRotated" if no one is waiting.
Pickup a passenger going to The Underground.
Go to Trunkers: south 2nd right 1st left.
Pickup a passenger going to Trunkers.
Go to Sunny Skies Park: west 1st right.
Pickup a passenger going to Sunny Skies Park.
Go to Zoom Zoom: north 1st right.
Go to The Underground: west 1st left 2nd right.
Switch to plan "RotateXY".


[XYareRotated]
[ At this point, we have the following data structure: ]
[ Input                           Auctioneer School    ]
[ Input w/o Delineator (IwoD)     Tom's Trims          ]
[ Elements in Input               Rounders Pub         ]
[ Iteration                       Joyless Park         ]
[ X Positions                     Trunkers             ]
[ Y Positions                     Sunny Skies Park     ]
[ Element's X                     Rob's Rest           ]
[ Element's Y                     Bird's Bench         ]

[ Now we need to compute the distance to each point greater than one ]
[ IwoD will start full and be emptied as we iterate through all the  ]
[ possible destinations. Once that's done, cycle back through those  ]
[ results until we find the smallest value >0 and add that to the    ]
[ result at Heisenberg's.                                            ]

[ Finish the RotateXY process by dropping off the passengers ]
[ They have been carried around to raise money for gas       ]
Go to Trunkers: south 2nd right 1st left.
Go to Sunny Skies Park: west 1st right.

[ Split IwoD into pieces ]
Go to Tom's Trims: south 1st left 1st right 1st left.
Pickup a passenger going to Cyclone.
Go to Cyclone: south 1st right 1st left 2nd right.
Pickup a passenger going to Tom's Trims.
Pickup a passenger going to Chop Suey.
Go to Tom's Trims: south 1st left 2nd right 1st left.
Go to Chop Suey: north 1st right 1st left 4th right 1st left.

[NextDestination]
Switch to plan "EndOfDestinations" if no one is waiting.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: south 1st right 1st left.
Pickup a passenger going to The Underground.
Go to The Underground: north.
Switch to plan "DestinationIsZero" if no one is waiting.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: south 1st right.

[ Calculate the X distance ]
Go to Trunkers: west 1st left 1st right.
Pickup a passenger going to Cyclone.
Go to Rob's Rest: west 1st left 1st right 1st right.
Pickup a passenger going to Cyclone.
Go to Cyclone: south 1st left 1st left 2nd left.
Pickup a passenger going to Trunkers.
Pickup a passenger going to What's The Difference.
Pickup a passenger going to Rob's Rest.
Go to Trunkers: south 1st left.
Go to Rob's Rest: west 1st left 1st right 1st right.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st left 1st right 2nd left.
Pickup a passenger going to Addition Alley.
Go to Cyclone: west 1st right 4th left.
Pickup a passenger going to What's The Difference.
Go to Zoom Zoom: north.
Go to What's The Difference: west 1st right.
Pickup a passenger going to Cyclone.
Go to Cyclone: east 1st right.
Pickup a passenger going to Addition Alley.
Pickup a passenger going to Multiplication Station.
Go to Addition Alley: north 2nd right 1st right.
Pickup a passenger going to The Underground.
Go to The Underground: north 1st right 1st right.
Switch to plan "XDiffIsNegative" if no one is waiting.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: south 1st right.
-1 is waiting at Starchild Numerology.
Go to Starchild Numerology: west 1st left 1st right 1st left 2nd left.
Pickup a passenger going to Multiplication Station.
Go to The Underground: west 1st right 2nd right 1st right 2nd left.
[XDiffIsNegative]
Go to Multiplication Station: south 1st left 1st right.

[ Calculate the Y distance ]
Go to Sunny Skies Park: south 1st right 2nd left 1st right.
Pickup a passenger going to Cyclone.
Go to Bird's Bench: south 2nd right 1st left.
Pickup a passenger going to Cyclone.
Go to Cyclone: north 1st right 1st left 2nd left.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to What's The Difference.
Pickup a passenger going to Bird's Bench.
Go to Sunny Skies Park: north 1st right.
Go to Bird's Bench: south 2nd right 1st left.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: north 1st right 1st right 2nd left.
Pickup a passenger going to Addition Alley.
Go to Cyclone: west 1st right 4th left.
Pickup a passenger going to What's The Difference.
Go to What's The Difference: north 1st left.
Pickup a passenger going to Cyclone.
Go to Cyclone: east 1st right.
Pickup a passenger going to Addition Alley.
Pickup a passenger going to Multiplication Station.
Go to Addition Alley: north 2nd right 1st right.
Pickup a passenger going to The Underground.
Go to The Underground: north 1st right 1st right.
Switch to plan "YDiffIsNegative" if no one is waiting.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: south 1st right.
-1 is waiting at Starchild Numerology.
Go to Starchild Numerology: west 1st left 1st right 1st left 2nd left.
Pickup a passenger going to Multiplication Station.
Go to The Underground: west 1st right 2nd right 1st right 2nd left.
[YDiffIsNegative]
Go to Multiplication Station: south 1st left 1st right.

[ Add the two negative distances and multiply by -1 ]
Pickup a passenger going to Addition Alley.
Pickup a passenger going to Addition Alley.
-1 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st right 2nd left 1st left 2nd left.
Pickup a passenger going to Multiplication Station.
Go to Addition Alley: west 1st right 3rd right 1st right 1st right.
Pickup a passenger going to Multiplication Station.
Go to Multiplication Station: north 1st right 1st right 3rd left 1st right.

[ Do not record the distance if it's zero     ]
[ i.e., if start and destination are the same ]
Pickup a passenger going to Addition Alley.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st right 2nd left 1st left 2nd left.
Pickup a passenger going to Addition Alley.
Go to Addition Alley: west 1st right 3rd right 1st right 1st right.
Pickup a passenger going to The Underground.
Go to The Underground: north 1st right 1st right.
Switch to plan "IgnoreZeroDistance" if no one is waiting.
Pickup a passenger going to Narrow Path Park.
[IgnoreZeroDistance]
Go to Narrow Path Park: north 4th left.
Go to Chop Suey: east 1st right 1st left 1st right.
Switch to plan "NextDestination".

[DestinationIsZero]
[ Rotate X & Y and keep going ]
Go to Trunkers: south 2nd right 1st left.
Pickup a passenger going to Trunkers.
Go to Sunny Skies Park: west 1st right.
Pickup a passenger going to Sunny Skies Park.
Go to Zoom Zoom: north 1st right.
Go to Trunkers: west 3rd left.
Go to Sunny Skies Park: west 1st right.
Go to Chop Suey: north 1st right 1st right 3rd right.
Switch to plan "NextDestination".

[EndOfDestinations]
[ Clean up the leftovers ]
Go to Rob's Rest: north 1st left 3rd left 1st left 2nd right 1st right.
Pickup a passenger going to Firemouth Grill.
Go to Bird's Bench: south.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: north 1st right 1st left 1st right 1st left 1st right.

[ Run through all the passengers are Narrow Path Park  ]
[ None of them should be 0 because we dropped those    ]
[ Find the smallest value and store it at Heisenberg's ]
Go to Narrow Path Park: east 1st left 4th left.
Pickup a passenger going to Writer's Depot.

[CheckNextDistance]
Switch to plan "FoundMinDistance" if no one is waiting.
Pickup a passenger going to Cyclone.
Go to Zoom Zoom: west 1st left 1st right 1st right.
Go to Writer's Depot: west.
Pickup a passenger going to Magic Eight.
Go to Cyclone: north.
Pickup a passenger going to Magic Eight.
Go to Magic Eight: south 1st left 2nd right.
Switch to plan "SecondIsLess" if no one is waiting.

[ Keep the first passenger b/c it's less and dump the second ]
Pickup a passenger going to Writer's Depot.
Go to Cyclone: north 1st left 2nd right.
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: south 1st left 2nd left 1st right.
Go to Narrow Path Park: east 1st left 4th left.
Switch to plan "CheckNextDistance".

[SecondIsLess]
[ Go pickup the second passenger's clone b/c it's less or equal ]
Go to Cyclone: north 1st left 2nd right.
Pickup a passenger going to Writer's Depot.
Go to Narrow Path Park: north 2nd right 1st left 1st right.
Switch to plan "CheckNextDistance".

[FoundMinDistance]
[ Store the results ]
Go to Writer's Depot: west 1st left 1st right 2nd left.
Pickup a passenger going to The Babelfishery.
' ' is waiting at Writer's Depot.
Pickup a passenger going to KonKat's.
Go to The Babelfishery: north 1st right 2nd right 1st right.
Pickup a passenger going to KonKat's.
Go to KonKat's: north.
Pickup a passenger going to Heisenberg's.
Go to Heisenberg's: north 1st right 1st right.
Go to Joyless Park: south 1st right 1st left 1st left.

[GotoNextStartingPoint]
[ Start at Joyless Park ]
Pickup a passenger going to Magic Eight.
Go to Rounders Pub: west 2nd left.
Pickup a passenger going to Cyclone.
Go to Cyclone: north 1st right 1st left 2nd left 2nd left.
Pickup a passenger going to Rounders Pub.
Pickup a passenger going to Magic Eight.
Go to Rounders Pub: north 2nd right 2nd right 2nd right 1st left.
Go to Magic Eight: north 1st right 1st right 2nd right.
Switch to plan "GoDoOutput" if no one is waiting.

[ We're not done yet so start over ]
Pickup a passenger going to Addition Alley.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: west 1st left 1st left 2nd left.
Pickup a passenger going to Addition Alley.
Go to Addition Alley: west 1st right 3rd right 1st right 1st right.
Pickup a passenger going to Joyless Park.
Go to Joyless Park: north 1st right 1st right 2nd left.
Switch to plan "NextElementForStartingPoint".



[ At this point, we have the following data structure: ]
[ (The queues not listed here aren't needed any more)  ]
[ Input                           Auctioneer School    ]
[ Array of minimums               Heisenberg's         ]

[GoDoOutput]
[ Split the original input at Chop Suey ]
Go to Auctioneer School: west 1st left 1st left.
Pickup a passenger going to Chop Suey.
Go to Chop Suey: north 3rd right 1st right 3rd right.

[OutputNextResult]
Switch to plan "PrintOutput" if no one is waiting.
Pickup a passenger going to Crime Lab.
'|' is waiting at Writer's Depot.
Go to Writer's Depot: north 1st left 3rd left.
Pickup a passenger going to Crime Lab.
Go to Zoom Zoom: north.
Go to Crime Lab: west 1st left 2nd right.
Switch to plan "OutputThisResult" if no one is waiting.

[ Output line breaks where every pipe was in the input ]
Pickup a passenger going to Firemouth Grill.
Go to Firemouth Grill: north 1st left.
'\n' is waiting at Writer's Depot.
Go to Writer's Depot: west 1st left 1st right 2nd left.
Pickup a passenger going to KonKat's.
Go to KonKat's: north 3rd right 2nd right.
Switch to plan "GoToNextOutput".

[OutputThisResult]
[ Output the actual result, which will include space padding ]
Go to Heisenberg's: north 5th right 1st left.
Pickup a passenger going to KonKat's.
Go to KonKat's: north 1st left 1st left.

[GoToNextOutput]
Pickup a passenger going to KonKat's.
Go to Chop Suey: north 1st right 1st right.
Switch to plan "OutputNextResult".

[PrintOutput]
Go to KonKat's: north 1st left 1st left.
Pickup a passenger going to Post Office.
Go to Post Office: south 3rd right 1st left.

@ Mr.Xcoder Êtes-vous heureux maintenant?
Ingénieur Toast

4

Python 3 + numpy , 102 octets

def f(M):
 x,y=where(M)
 for i,j in zip(x,y):d=abs(x-i)+abs(y-j);M[i,j]=min(d[d>0])
from numpy import*

Essayez-le en ligne!

Prend l'entrée comme un numpytableau.


Python 3 , 127 octets

lambda M,e=enumerate:[[v*min(abs(x-i)+abs(y-j)for x,r in e(M)for y,a in e(r)if(x!=i or y!=j)*a)for j,v in e(r)]for i,r in e(M)]

Essayez-le en ligne!


2

Perl 5 , 197 octets

@a=map{[/\d/g]}<>;for$r(0..$#a){for$c(0..$#{$a[$r]}){$d=@a*@{$a[0]}*$a[$r][$c];for$y(0..$#a){$a[$r][$c]=$d=$a[$y][$_]&&($t=abs($y-$r)+abs($_-$c))&&$t<$d?$t:$d for 0..$#{$a[$y]}}}}$,=$";say@$_ for@a

Essayez-le en ligne!


3
Il semble que le surligneur SE pour Perl nécessite de nombreuses améliorations.

@ThePirateBay $#, en gros ...
Erik the Outgolfer

2

JavaScript (ES6), 97 octets

Prend la saisie dans la syntaxe de curry (w)(a), où w est la largeur de la matrice et a est un tableau plat de zéros et de uns. Renvoie un autre tableau plat.

w=>a=>a.map((c,i)=>c*Math.min(...a.map((d,j)=>d&&A((j/w|0)-(i/w|0))+A(j%w-i%w)||1/0)),A=Math.abs)

Cas de test

Cet extrait de code comprend une fonction d'aide pour formater la sortie pour la lisibilité.


1

Octave, 59 octets

for f=find(a=input(''))'a(f)=0;a(f)=bwdist(a,'ci')(f);end;a

Prend l'entrée comme un tableau 2D.

Essayez-le en ligne!

Explication:

Pour chaque emplacement de 1 trouvé dans le tableau, réglez-le sur zéro et calculez la transformation de distance de bloc de ville du tableau et définissez enfin l'emplacement sur la distance calculée.



En utilisant notre site, vous reconnaissez avoir lu et compris notre politique liée aux cookies et notre politique de confidentialité.
Licensed under cc by-sa 3.0 with attribution required.