Skip to main content
explanation
Source Link
ngn
  • 15.6k
  • 2
  • 45
  • 90

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!

output: 0=D 1=R 2=U 3=L 4=!

explanation{ } function with arguments x and y

x-97 convert "a".."z" to 0..25

(0,y)\ divmod by y, returns a pair of lists - one with the quotients and one with the remainders

+ flip - make it a bit laterlist of pairs

-': deltas - subtract each pair from the previous one; use 0 0 as an implicit pair before the first

( )' for each pair (let's call it (Δi;Δj)) do:

  • -:\ self and own negation: (Δi;Δj) -> ((Δi;Δj);(-Δi;-Δj))

  • ,/ concatenate: -> (Δi;Δj;-Δi;-Δj)

  • 0| max with 0

  • & "where" - for instance it would turn the list a:1 5 0 2 into 0 1 1 1 1 1 3 3, i.e. each index i is repeated a[i] times

  • 4, prepend a 4

  • | reverse

,/ concatenate

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!

output: 0=D 1=R 2=U 3=L 4=!

explanation - a bit later

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!

output: 0=D 1=R 2=U 3=L 4=!

{ } function with arguments x and y

x-97 convert "a".."z" to 0..25

(0,y)\ divmod by y, returns a pair of lists - one with the quotients and one with the remainders

+ flip - make it a list of pairs

-': deltas - subtract each pair from the previous one; use 0 0 as an implicit pair before the first

( )' for each pair (let's call it (Δi;Δj)) do:

  • -:\ self and own negation: (Δi;Δj) -> ((Δi;Δj);(-Δi;-Δj))

  • ,/ concatenate: -> (Δi;Δj;-Δi;-Δj)

  • 0| max with 0

  • & "where" - for instance it would turn the list a:1 5 0 2 into 0 1 1 1 1 1 3 3, i.e. each index i is repeated a[i] times

  • 4, prepend a 4

  • | reverse

,/ concatenate

better tests
Source Link
ngn
  • 15.6k
  • 2
  • 45
  • 90

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!Try it online!

output: 0=D 1=R 2=U 3=L 4=!

explanation - a bit later

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!

output: 0=D 1=R 2=U 3=L 4=!

explanation - a bit later

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!

output: 0=D 1=R 2=U 3=L 4=!

explanation - a bit later

added 29 characters in body
Source Link
ngn
  • 15.6k
  • 2
  • 45
  • 90

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!

output: 0=D 1=R 2=U 3=L 4=!

explanation - a bit later

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!

output: 0=D 1=R 2=U 3=L 4=!

K (ngn/k), 41 32 bytes

{,/(|4,&0|,/-:\)'-':+(0,y)\x-97} 

Try it online!

output: 0=D 1=R 2=U 3=L 4=!

explanation - a bit later

-9
Source Link
ngn
  • 15.6k
  • 2
  • 45
  • 90
Loading
Source Link
ngn
  • 15.6k
  • 2
  • 45
  • 90
Loading