Mappa della distanza minima del taxi


13

Descrizione della sfida

Nella metrica del taxi , una distanza tra due punti inserisci qui la descrizione dell'immagineè definita come:

inserisci qui la descrizione dell'immagine

Considera una matrice con solo zeri e uno:

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

Mappiamo ciascuno 1alla distanza dal più vicino diverso 1 nella matrice (ovviamente, supponendo che la distanza tra due file / colonne adiacenti sia uguale a 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

Per questa sfida, data una matrice, trova la sua mappa delle distanze come mostrato sopra.

Esempi

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

Appunti

  • È possibile accettare input in qualsiasi formato ragionevole
  • A parte 0e 1puoi scegliere due valori distinti
  • Si può presumere che una matrice non sia vuota (contiene almeno una riga di lunghezza maggiore o uguale a 1) e che sia rettangolare
  • Puoi anche supporre che nella matrice siano presenti almeno due valori di verità (altrimenti, l'output non è definito)
  • È possibile scrivere un programma completo o una funzione
  • Invece di restituire una nuova matrice, è possibile modificarne una esistente
  • Questo è , quindi rendi il tuo conteggio dei byte il più basso possibile!

3
Richiesta di più esempi per favore.
Magic Octopus Urn

9
Oh, una soluzione di taxi sarebbe probabilmente sopravvalutata> _>
Mr. Xcoder

Possiamo prendere l'input come un numero intero (che fornisce la larghezza) e un array piatto?
Arnauld,

1
@ Mr.Xcoder Una soluzione di taxi sarebbe anche un incubo ... sospira [apre TIO]
Ingegnere Toast

1
@Arnauld suona come un formato ragionevole per me
shooqie

Risposte:


5

MATL , 23 22 byte

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

Provalo online! Oppure verifica tutti i casi di test .

Spiegazione

Per visualizzare risultati intermedi, può essere utile inserire X#(display stack) tra due istruzioni.

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
È sorprendente. Non un solo comando di riorganizzazione dello stack, nonostante 4 se tnoM
Sanchises

5

Taxi , 14652 byte

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.

Provalo online!

Presumo che nessun essere umano voglia provare a leggere quel codice, quindi provalo online con commenti, etichette significative e output più leggibile!


Input: stringa che rappresenta un array. La stringa deve essere composta da 3 caratteri: 0, |rappresentando interruzioni di riga e ogni maggiore cifre positivo di uno (PDGTO). Mi piace usare 8. OP consente l'inserimento in qualsiasi formato ragionevole e credo che ciò sia idoneo. La stringa non deve essere formattata su una matrice rettangolare ma si presume che sia allineata a sinistra qualunque essa sia.

Output: matrice di valori che mostra la distanza minima del taxi da ciascuno PDGTOal più vicino all'altro PDGTO.

Esempio:

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

Il secondo formato di output è chiaramente molto più facile da leggere, ma aggiunge anche 7 byte al programma e questo è , dopo tutto. Sarebbe stato possibile tornare alla fine e rimuovere tutti gli zero finali invece di riempire semplicemente i 0valori, ma ciò avrebbe aggiunto ancora più byte e sarebbe stato ritenuto un costo inaccettabile.


Ecco il testo del codice non golfato con commenti, etichette migliori e output più chiaro:
(È lo stesso che ottieni con il link sopra.)

[ 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 Sei felice ora?
Ingegnere Toast

4

Python 3 + numpy , 102 byte

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*

Provalo online!

Accetta input come un numpyarray.


Python 3 , 127 byte

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)]

Provalo online!


2

Perl 5 , 197 byte

@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

Provalo online!


3
Sembra che l'evidenziatore SE per Perl abbia bisogno di molti miglioramenti.

@ThePirateBay $#, in sostanza ...
Erik the Outgolfer

2

JavaScript (ES6), 97 byte

Accetta input nella sintassi del curry (w)(a), dove w è la larghezza della matrice e a è una matrice piatta di zeri e di uno. Restituisce un altro array piatto.

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)

Casi test

Questo frammento include una funzione di supporto per formattare l'output per la leggibilità.


1

Ottava, 59 byte

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

Prende l'input come un array 2D.

Provalo online!

Spiegazione:

Per ogni posizione di 1s trovata nell'array, impostala su zero e calcola la trasformazione della distanza del blocco di città dell'array e infine imposta la posizione sulla distanza calcolata.



Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.