Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

SnakeEx - 98 bytes with Javascript, 44 without

This looked like a good problem to try my language from the Fortnightly ChallengeFortnightly Challenge on:

m:({e<>PE}\-[|\-]*<T>\+|[|\-]*<T>)+`\+ e:\+ 

The best place to try this out is my online interpreter.

SnakeEx matches patterns in text by using "snakes" that move around the text matching regexes. The code reads kind of like a regex, except:

  • The <T> instruction. That is a direction command that branches the snake left and right from its current direction.
  • {e<>PE} is like a subroutine call. It that spawns a snake with definition e moving forward (<>) and with parameters P (piggyback - the spawning snake follows the new snake) and E (exclusive - don't match anything that's already been matched). This exclusive check is the only thing that stops the snake from looping infinitely.
  • The prefix ` at the end indicates that what follows should be matched only if it has already been matched, which we can use to force the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m:({e<>PE}\\-[|\\-]*<T>\\+|[|\\-]*<T>)+`\\+\ne:\\+',s,1).length} 

Edit: fixed it up to work with blutorange's additional test cases

SnakeEx - 98 bytes with Javascript, 44 without

This looked like a good problem to try my language from the Fortnightly Challenge on:

m:({e<>PE}\-[|\-]*<T>\+|[|\-]*<T>)+`\+ e:\+ 

The best place to try this out is my online interpreter.

SnakeEx matches patterns in text by using "snakes" that move around the text matching regexes. The code reads kind of like a regex, except:

  • The <T> instruction. That is a direction command that branches the snake left and right from its current direction.
  • {e<>PE} is like a subroutine call. It that spawns a snake with definition e moving forward (<>) and with parameters P (piggyback - the spawning snake follows the new snake) and E (exclusive - don't match anything that's already been matched). This exclusive check is the only thing that stops the snake from looping infinitely.
  • The prefix ` at the end indicates that what follows should be matched only if it has already been matched, which we can use to force the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m:({e<>PE}\\-[|\\-]*<T>\\+|[|\\-]*<T>)+`\\+\ne:\\+',s,1).length} 

Edit: fixed it up to work with blutorange's additional test cases

SnakeEx - 98 bytes with Javascript, 44 without

This looked like a good problem to try my language from the Fortnightly Challenge on:

m:({e<>PE}\-[|\-]*<T>\+|[|\-]*<T>)+`\+ e:\+ 

The best place to try this out is my online interpreter.

SnakeEx matches patterns in text by using "snakes" that move around the text matching regexes. The code reads kind of like a regex, except:

  • The <T> instruction. That is a direction command that branches the snake left and right from its current direction.
  • {e<>PE} is like a subroutine call. It that spawns a snake with definition e moving forward (<>) and with parameters P (piggyback - the spawning snake follows the new snake) and E (exclusive - don't match anything that's already been matched). This exclusive check is the only thing that stops the snake from looping infinitely.
  • The prefix ` at the end indicates that what follows should be matched only if it has already been matched, which we can use to force the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m:({e<>PE}\\-[|\\-]*<T>\\+|[|\\-]*<T>)+`\\+\ne:\\+',s,1).length} 

Edit: fixed it up to work with blutorange's additional test cases

just golfing some more
Source Link
BMac
  • 2.1k
  • 1
  • 12
  • 16

SnakeEx - 10498 bytes with Javascript, 5044 without

This looked like a good problem to try my language from the Fortnightly Challenge on:

m:(\+\-{j<>PE}\+|{j<>PEe<>PE}\-[|\-]*<T>\+|[|\-]*<T>)+`\+ je:[`[|\-][|\-]]*<T>\+ 

The best place to try this out is my online interpreter.

SnakeEx matches patterns in text by using "snakes" that move around the text matching regexes. The code reads kind of like a regex, except:

  • The <T> instruction. That is a direction command that branches the snake left and right from its current direction of travel.
  • {j<>PEe<>PE} is like a subroutine call. It that spawns a snake with definition je moving forward (<>, an empty direction) and with parameters P (piggyback - the spawning snake follows the new snake) and E (exclusive - don't match anything that's already been matched). This exclusive check is the only thing that stops the snake from looping infinitely.
  • The prefix ` at the end indicates that what follows the + should be matched only if it has already been matched, which we can use to force the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m:(\\+\\-{j<>PE}\\+|{j<>PEe<>PE})+`\\+\nj:[`[|\\\\-][|\\[|\\-]]*<T>']*<T>\\+|[|\\-]*<T>)+`\\+\ne:\\+',s,1).length} 

Edit: golfed expression, added missing escapes in JS version.

Edit: fixed it up to work with blutorange's additional test cases

SnakeEx - 104 bytes with Javascript, 50 without

This looked like a good problem to try my language from the Fortnightly Challenge on:

m:(\+\-{j<>PE}\+|{j<>PE})+`\+ j:[`[|\-][|\-]]*<T> 

The best place to try this out is my online interpreter.

SnakeEx matches patterns in text by using "snakes" that move around the text matching regexes. The code reads kind of like a regex, except:

  • The <T> instruction. That is a direction command that branches the snake left and right from its current direction of travel.
  • {j<>PE} is like a subroutine call. It that spawns a snake with definition j moving forward (<>, an empty direction) and with parameters P (piggyback - the spawning snake follows the new snake) and E (exclusive - don't match anything that's already been matched).
  • The prefix ` indicates that what follows the + should be matched only if it has already been matched, which we can use to force the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m:(\\+\\-{j<>PE}\\+|{j<>PE})+`\\+\nj:[`[|\\-][|\\-]]*<T>',s,1).length} 

Edit: golfed expression, added missing escapes in JS version.

Edit: fixed it up to work with blutorange's additional test cases

SnakeEx - 98 bytes with Javascript, 44 without

This looked like a good problem to try my language from the Fortnightly Challenge on:

m:({e<>PE}\-[|\-]*<T>\+|[|\-]*<T>)+`\+ e:\+ 

The best place to try this out is my online interpreter.

SnakeEx matches patterns in text by using "snakes" that move around the text matching regexes. The code reads kind of like a regex, except:

  • The <T> instruction. That is a direction command that branches the snake left and right from its current direction.
  • {e<>PE} is like a subroutine call. It that spawns a snake with definition e moving forward (<>) and with parameters P (piggyback - the spawning snake follows the new snake) and E (exclusive - don't match anything that's already been matched). This exclusive check is the only thing that stops the snake from looping infinitely.
  • The prefix ` at the end indicates that what follows should be matched only if it has already been matched, which we can use to force the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m:({e<>PE}\\-[|\\-]*<T>\\+|[|\\-]*<T>)+`\\+\ne:\\+',s,1).length} 

Edit: fixed it up to work with blutorange's additional test cases

fixing for additional test cases
Source Link
BMac
  • 2.1k
  • 1
  • 12
  • 16

SnakeEx -108 104 bytes with Javascript, 4850 without

This looked like a good problem to try my language from the Fortnightly Challenge on.:

m{E}:(\+\-[`[^ ][^ ]]*<T>\+|[`[^ ][^ ]]*<T>{j<>PE}\+|{j<>PE})+`\+ j:[`[|\-][|\-]]*<T> 

The best place to try this out is my online interpreter.

SnakeEx usesmatches patterns in text by using "snakes" that move around the text matching regexes. This problem only requires one snake to trace around the shape. The code essentially reads kind of like a regex, except for the <T> instruction. That is a direction command that branches the snake left and right from its current direction of travel. Also, the prefix ` used at the end indicates that the + should be matched only if it has already been matched, forcing the loop to close.:

  • The <T> instruction. That is a direction command that branches the snake left and right from its current direction of travel.
  • {j<>PE} is like a subroutine call. It that spawns a snake with definition j moving forward (<>, an empty direction) and with parameters P (piggyback - the spawning snake follows the new snake) and E (exclusive - don't match anything that's already been matched).
  • The prefix ` indicates that what follows the + should be matched only if it has already been matched, which we can use to force the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m{E}:(\\+\\-[`[^ ][^ ]]*<T>\\+|[`[^ ][^ ]]*<T>{j<>PE}\\+|{j<>PE})+`\\+'+`\\+\nj:[`[|\\-][|\\-]]*<T>',s,1).length} 

Edit: golfed expression, added missing escapes in JS version.

Edit: fixed it up to work with blutorange's additional test cases

SnakeEx -108 bytes with Javascript, 48 without

This looked like a good problem to try my language from the Fortnightly Challenge on.

m{E}:(\+\-[`[^ ][^ ]]*<T>\+|[`[^ ][^ ]]*<T>)+`\+ 

The best place to try this out is my online interpreter.

SnakeEx uses "snakes" that move around the text matching regexes. This problem only requires one snake to trace around the shape. The code essentially reads like a regex, except for the <T> instruction. That is a direction command that branches the snake left and right from its current direction of travel. Also, the prefix ` used at the end indicates that the + should be matched only if it has already been matched, forcing the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m{E}:(\\+\\-[`[^ ][^ ]]*<T>\\+|[`[^ ][^ ]]*<T>)+`\\+',s,1).length} 

Edit: golfed expression, added missing escapes in JS version.

SnakeEx - 104 bytes with Javascript, 50 without

This looked like a good problem to try my language from the Fortnightly Challenge on:

m:(\+\-{j<>PE}\+|{j<>PE})+`\+ j:[`[|\-][|\-]]*<T> 

The best place to try this out is my online interpreter.

SnakeEx matches patterns in text by using "snakes" that move around the text matching regexes. The code reads kind of like a regex, except:

  • The <T> instruction. That is a direction command that branches the snake left and right from its current direction of travel.
  • {j<>PE} is like a subroutine call. It that spawns a snake with definition j moving forward (<>, an empty direction) and with parameters P (piggyback - the spawning snake follows the new snake) and E (exclusive - don't match anything that's already been matched).
  • The prefix ` indicates that what follows the + should be matched only if it has already been matched, which we can use to force the loop to close.

Because SnakeEx is like regex and doesn't technically output the results as desired by itself, I guess we need to wrap it in some Javascript calling the interpreter:

function e(s){return snakeEx.run('m:(\\+\\-{j<>PE}\\+|{j<>PE})+`\\+\nj:[`[|\\-][|\\-]]*<T>',s,1).length} 

Edit: golfed expression, added missing escapes in JS version.

Edit: fixed it up to work with blutorange's additional test cases

fixed self-crossing loops
Source Link
BMac
  • 2.1k
  • 1
  • 12
  • 16
Loading
added 46 characters in body
Source Link
BMac
  • 2.1k
  • 1
  • 12
  • 16
Loading
deleted 3 characters in body
Source Link
BMac
  • 2.1k
  • 1
  • 12
  • 16
Loading
deleted 4 characters in body
Source Link
BMac
  • 2.1k
  • 1
  • 12
  • 16
Loading
Source Link
BMac
  • 2.1k
  • 1
  • 12
  • 16
Loading