Thursday 16 January 2014

RE Golf

http://regex.alf.nu/ has a fabby little puzzle 'regular expression golf' which has taken up far too much of my time, but got a tidy score of 3673 and learned all about backreferences.

My Answers:

  • Plain Strings (207) - foo
  • Anchors (208) - k$
  • Ranges (199) - ^[abcdef]*$
  • Backrefs (195) - (.)([^a]).*\1\2
  • Abba (190) - ^((?!(.)(.)\3\2).)*$
  • A man, a plan (168) - (.)(.)(.)?.?(\3?\2\1)$
  • Prime (201) - ^x(x*)\1$
  • Four (198) - (.).\1.\1.\1
  • Order (198) - ^.....[^e]?$
  • Triples (561) - [031][0][3694]|[053][126][25]|[7][14][4]|^0*$|217|422|895|914|177|734
  • Glob (349) - err|lle|tud|ogi|ide|ris|hob|ney|orl|tef|igh|ark|tog|rom|ial|ppe|der|thw
  • Balance (267) - ^((?!<<>>>|<><>>|<<<<<<)<(<>|<<|>>|><)*>)?$
  • Powers (63) - ^(((((((x|xxxxxxxx)\7?)\6?)\5?)\4?)\3?)\2?)\1?$
  • Long count (192) - 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 111
  • Long count v2 (212) - 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 101
  • Alphabetical (265) - te [ea][aes][sr]|st ar|nt ass|rn re|at en|(ne|et|ar|ta) te|(st|er) sn|ee ta
I probably cheated on Glob, having given up with trying to match the subtleties of the semantics of a glob * on the left & right.

No comments:

Post a Comment