Skip to main content
deleted 39 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Retina, 147147 102 bytes

.$
$*$*	
¶
 ¶
{+s`s`((?<=N(.{7}...|.{11}|.{1813}|)?.{207})):|:(?=(.{7}|.{118}|(.{18}|.{20})N))(?=.*1)
m
+is`N(.{7}|.{11}|.{18}|.{2013})?N))\S(?=.*1*	)
n$1nn
Ts`1Nl`_Ts`	Nn`_:N`.*¶1

Try it online!Try it online! Takes input as an 8x8 board of :s with the knights marked with Ns, with a digit for the number of turns on the next line (it makes no sense to have more than 9 turns, but if you insist I can support it for an extra byte). Note that the output contains additional white space. Edit: Saved 45 bytes thanks to @MartinEnder. Explanation: The first stage converts the number of turns to unary, but using tab characters, so that they don't get matched later by accident, while the second stage adds some white spacespaces to the right of the board to stop the regexes from wrapping across the edge. The third stage then replaces all :s that are a knight's move away from an N with an m while the fourth stage replaces alls and N:s that are a knight's move away from an N or an n with an n. The fifth while the fourth stage then deletes any remaining Ns, changes the ms and ns to Ns, and subtracts 1 from the move count. This repeats until the move count is zero.

Retina, 147 bytes

.$
$*
¶
 ¶
{+s`((?<=N(.{7}|.{11}|.{18}|.{20})):|:(?=(.{7}|.{11}|.{18}|.{20})N))(?=.*1)
m
+is`N(.{7}|.{11}|.{18}|.{20})N(?=.*1)
n$1n
Ts`1Nl`_:N`.*¶1

Try it online! Takes input as an 8x8 board of :s with the knights marked with Ns, with a digit for the number of turns on the next line (it makes no sense to have more than 9 turns, but if you insist I can support it for an extra byte). Note that the output contains additional white space. Explanation: The first stage converts the number of turns to unary, while the second stage adds some white space to the right of the board to stop the regexes from wrapping across the edge. The third stage then replaces all :s that are a knight's move away from an N with an m while the fourth stage replaces all Ns that are a knight's move away from an N or an n with an n. The fifth stage then deletes any remaining Ns, changes the ms and ns to Ns, and subtracts 1 from the move count. This repeats until the move count is zero.

Retina, 147 102 bytes

.$
$*	
¶
 ¶
{s`((?<=N(....|.{11}|.{13})?.{7})|(?=.{8}(....|.{11}|.{13})?N))\S(?=.*	)
n
Ts`	Nn`_:N`.

Try it online! Takes input as an 8x8 board of :s with the knights marked with Ns, with a digit for the number of turns on the next line (it makes no sense to have more than 9 turns, but if you insist I can support it for an extra byte). Note that the output contains additional white space. Edit: Saved 45 bytes thanks to @MartinEnder. Explanation: The first stage converts the number of turns to unary, but using tab characters, so that they don't get matched later by accident, while the second stage adds some spaces to the right of the board to stop the regexes from wrapping across the edge. The third stage replaces all Ns and :s that are a knight's move away from an N with an n while the fourth stage deletes any remaining Ns, changes the ns to Ns, and subtracts 1 from the move count. This repeats until the move count is zero.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Retina, 147 bytes

.$
$*
¶
 ¶
{+s`((?<=N(.{7}|.{11}|.{18}|.{20})):|:(?=(.{7}|.{11}|.{18}|.{20})N))(?=.*1)
m
+is`N(.{7}|.{11}|.{18}|.{20})N(?=.*1)
n$1n
Ts`1Nl`_:N`.*¶1

Try it online! Takes input as an 8x8 board of :s with the knights marked with Ns, with a digit for the number of turns on the next line (it makes no sense to have more than 9 turns, but if you insist I can support it for an extra byte). Note that the output contains additional white space. Explanation: The first stage converts the number of turns to unary, while the second stage adds some white space to the right of the board to stop the regexes from wrapping across the edge. The third stage then replaces all :s that are a knight's move away from an N with an m while the fourth stage replaces all Ns that are a knight's move away from an N or an n with an n. The fifth stage then deletes any remaining Ns, changes the ms and ns to Ns, and subtracts 1 from the move count. This repeats until the move count is zero.