Live data from Hacker News

Regex Golf

regex.alf.nu

111–120 of 189 posts

Re: Regex Golf

#111

Earlier quoted context omitted.

I don't get what this is all about. The title was (most probably) derived from Code Golf, which is a competition in coding something with as few characers as possible. Code Golf was derived from Golf, where you want to use as few turns as possible. The score going up and not down, which is done because you get more points the more objectives you fulfill, does not change the objective of this game or what it is based…

> The score going up and not down, which is done because you get more points the more objectives you fulfill, does not change the objective of this game or what it is based on. Golf scoring penalizes you with more "points" by how many strokes you take. If you are playing a Par 4 and it takes you 6 swings to get in the cup you just got _penalized_ +2 If your partner gets in the cup in 2 swings he is awarded -2 Therefo…

[deleted]

Re: Regex Golf

#112
post #43
post #31

I got Four for 196 with (.).*\1.\1.*\1 and Order for 156 with ^a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*$

Order for 198: ^[^o].....?$ Probably not what was wanted, but it works (or maybe it was to trick people onto a false path)

Makes my similarly off-track score of 184 seem foolish:

  ^[a-g][^airn]|[fs].*y$|ot$

Re: Regex Golf

#113
post #110

I figured out Ranges! abac|accede|adead|babe|bead|bebed|bedad|bedded|bedead|bedeaf|caba|caffa|dace|dade|daff|dead|deed|deface|faded|faff|feed Edit: /s

Prime:

    ^x{2,3}$|^x{5}$|^x{7}$|^x{11}$|^x{13}$|^x{17}$|^x{19}$|^x{23}$|^x{29}$|^x{31}$|x{33}

Re: Regex Golf

#114
post #110

I figured out Ranges! abac|accede|adead|babe|bead|bebed|bedad|bedded|bedead|bedeaf|caba|caffa|dace|dade|daff|dead|deed|deface|faded|faff|feed Edit: /s

[a-f]{4,} works as well... but I do like your solution!

Re: Regex Golf

#117

Does anybody know how to do math with regex? (triples) And conditionals don't seem to work?

My guess is that 147 must appear the same number of times as 258, but I'm not sure if that's even expressible in regexp.

Sadly that wouldn't work for: 140091876 147 = 4 times 258 = 1 time

Re: Regex Golf

#118
post #87

^(?!(..+)(\1)+$) Why does that work on primes? I got it by mistake when fiddling with the parenthesis locations but I was expecting to have to deal with xx separately.

Nice find. It works because it rejects "2 or more x's" repeated "2 or more times". So xx doesn't get rejected, but any multiple of that (xxxx, xxxxxx, ...) will be. The same way xxx doesn't get rejected, but any multiple of that (xxxxxx, xxxxxxxxx, ...) will be. You've solved it using the actual definition of prime numbers, no trickery needed. Well played. FYI, you don't need brackets around the \1, so can score 286.

Thanks, I was going for the definition of primes but was just going a bit loopy about the negation. I didn't want to trim surplus characters until I understood it but yes I can see those brackets are unnecessary.

Re: Regex Golf

#119
post #71

Earlier quoted context omitted.

Powers: ^((((((((((x)\10?)\9?)\8?)\7?)\6?)\5?)\4?)\3?)\2?)\1?$ I feel like there's gotta be a sneakier way of doing this.

Mine is a bit shorter, though a bit more "meh" as well. ^x{32}$|^(x{2}){1,8}$|^(x{64})+$|^x$

improved, gives 80

    ^(x|(xx){1,9}|x{32}|(x{64})+)$
Post reply on HN