1313: "Regex Golf"

This forum is for the individual discussion thread that goes with each new comic.

Moderators: Moderators General, Prelates, Magistrates

User avatar
poxic
Eloquently Prismatic
Posts: 4718
Joined: Sat Jun 07, 2008 3:28 am UTC
Location: Left coast of Canada

1313: "Regex Golf"

Postby poxic » Mon Jan 06, 2014 5:29 am UTC

Image

Title text: "/bu|[rn]t|[coy]e|[mtg]a|j|iso|n[hl]|[ae]d|lev|sh|[lnd]i|[po]o|ls/ matches the last names of elected US presidents but not their opponents."

I almost understand, I think.
All empires fall.
Don't look back.
- The Secret Knots

User avatar
rhomboidal
Posts: 791
Joined: Wed Jun 15, 2011 5:25 pm UTC
Contact:

Re: 1313: "Regex Golf"

Postby rhomboidal » Mon Jan 06, 2014 5:31 am UTC

Down the regex hole for adventures in [1]derland...

elenaran
Posts: 3
Joined: Wed Jul 07, 2010 4:11 am UTC

Re: 1313: "Regex Golf"

Postby elenaran » Mon Jan 06, 2014 5:42 am UTC

Maybe I'm just missing something - how does /M | [TN]|B/ match Star Wars subtitles??

Harry Voyager
Posts: 52
Joined: Thu Nov 04, 2010 7:55 am UTC

Re: 1313: "Regex Golf"

Postby Harry Voyager » Mon Jan 06, 2014 5:49 am UTC

To quote Skin Horse,
"And if I solve this cunning riddle, what boon do I win?"
"This is real life. You just win more confusion."

User avatar
bachaddict
Handel Played it Better
Posts: 484
Joined: Wed Dec 19, 2012 7:18 am UTC
Location: Aotearoa

Re: 1313: "Regex Golf"

Postby bachaddict » Mon Jan 06, 2014 6:11 am UTC

elenaran wrote:Maybe I'm just missing something - how does /M | [TN]|B/ match Star Wars subtitles??


Hmm... I think it means the part after the colon in this list

Star Wars Episode IV: A New Hope
Star Wars Episode V: The Empire Strikes Back
Star Wars Episode VI: Return of the Jedi
Star Wars Episode I: The Phantom Menace
Star Wars Episode II: Attack of the Clones
Star Wars Episode III: Revenge of the Sith
Star Wars: The Clone Wars
slinches wrote:Also, the OTC isn't a disease. In fact, it's the cure. As we all know, Time heals all wounds.

Thanks for the molpish wig ggh!
he/him/his

Kirian
Posts: 2
Joined: Mon Feb 19, 2007 3:54 pm UTC

Re: 1313: "Regex Golf"

Postby Kirian » Mon Jan 06, 2014 6:20 am UTC

elenaran wrote:Maybe I'm just missing something - how does /M | [TN]|B/ match Star Wars subtitles??


This searches for:
"M ", which finds Phantom Menace
" N" or " T", which finds Attack of the Clones, Revenge of the Sith, A New Hope, and Return of the Jedi
"B", which finds The Empire Strikes Back

However,

The Motion Picture
The Wrath of Khan
The Search For Spock
The Voyage Home
The Final Frontier
The Undiscovered Country

contain M only at the start or middle of a word, and not the end; similarly contain N or T only at the middle or end of a word; and none contain B.

User avatar
Adacore
Posts: 2755
Joined: Fri Feb 20, 2009 12:35 pm UTC
Location: 한국 창원

Re: 1313: "Regex Golf"

Postby Adacore » Mon Jan 06, 2014 6:23 am UTC

I note that the Star Wars regex code does not work for The Clone Wars (Unless you count the space before the 'The', in which case it would match a heap of the Star Trek subtitles), but that's not one of the six main movies.

Also, if you count the 2009 Star Trek movie as being subtitled simply as 'Star Trek', then the code would find that because of the / T/.

jasper.a.visser
Posts: 4
Joined: Wed Sep 18, 2013 4:24 am UTC

Re: 1313: "Regex Golf"

Postby jasper.a.visser » Mon Jan 06, 2014 6:29 am UTC

Kirian wrote:The Motion Picture
The Wrath of Khan
The Search For Spock
The Voyage Home
The Final Frontier
The Undiscovered Country

You missed:
Generations
First Contact
Insurrection
Nemesis
- the one without a subtitle -
Into Darkness

Oddly, IMDB lists the one without a subtitle as Star Trek: The Future Begins, which, if true, would make it a violation of the pattern. Wikipedia doesn't agree with that subtitle. :)

bondsbw
Posts: 24
Joined: Mon Sep 19, 2011 6:37 pm UTC

Re: 1313: "Regex Golf"

Postby bondsbw » Mon Jan 06, 2014 6:47 am UTC

Adacore wrote:I note that the Star Wars regex code does not work for The Clone Wars (Unless you count the space before the 'The', in which case it would match a heap of the Star Trek subtitles), but that's not one of the six main movies.


Yeah, I think that would be considered a series and I think the comic is only intending movies. If we allowed series, then "The Next Generation" and "Deep Space Nine" would match.

enigmamf
Posts: 6
Joined: Mon Nov 14, 2011 5:44 am UTC

Re: 1313: "Regex Golf"

Postby enigmamf » Mon Jan 06, 2014 6:51 am UTC

Richard Nixon is both an "elected US president" and the opponent of an elected US president. It looks like he is matched by [lnd]i, so I assume he was manually excluded from the "opponents" list.

bondsbw
Posts: 24
Joined: Mon Sep 19, 2011 6:37 pm UTC

Re: 1313: "Regex Golf"

Postby bondsbw » Mon Jan 06, 2014 6:53 am UTC

jasper.a.visser wrote:Oddly, IMDB lists the one without a subtitle as Star Trek: The Future Begins, which, if true, would make it a violation of the pattern. Wikipedia doesn't agree with that subtitle. :)

Movie posters contain the words "The Future Begins" but that's not part of the name. The billing block (the credits block at the bottom of posters) simply says the name is "Star Trek". Into Darkness posters contain the full name "Star Trek Into Darkness", so I would expect to see "Star Trek: The Future Begins" in the billing block if that were the true name.

User avatar
glasnt
Posts: 539
Joined: Fri Jan 25, 2008 5:18 am UTC
Location: SQUEE!

Re: 1313: "Regex Golf"

Postby glasnt » Mon Jan 06, 2014 7:12 am UTC

Found one of these unintentionally today.

A script to query a webservice and ensure it was up and serving correct json when asked

By regexing a wget with '^\['

It gets the job done.. kinda..

Jamaican Castle
Posts: 151
Joined: Fri Nov 30, 2007 9:10 pm UTC

Re: 1313: "Regex Golf"

Postby Jamaican Castle » Mon Jan 06, 2014 7:17 am UTC

bondsbw wrote:
Adacore wrote:I note that the Star Wars regex code does not work for The Clone Wars (Unless you count the space before the 'The', in which case it would match a heap of the Star Trek subtitles), but that's not one of the six main movies.


Yeah, I think that would be considered a series and I think the comic is only intending movies. If we allowed series, then "The Next Generation" and "Deep Space Nine" would match.


There was an animated movie, but that's generally considered part of the series.

Well, actually, I discovered while looking this up that there are two animated Star Wars series of the 00s, Clone Wars and The Clone Wars (the movie began life as a three-part pilot for the latter). I guess it's very animate-able?

User avatar
orthogon
Posts: 3006
Joined: Thu May 17, 2012 7:52 am UTC
Location: The Airy 1830 ellipsoid

Re: 1313: "Regex Golf"

Postby orthogon » Mon Jan 06, 2014 7:56 am UTC

It's probably supposed to be obvious, but I guess the number if characters in the regex corresponds to the number of golf shots (or swings, or whatever - I subscribe to the "good walk spoiled" viewpoint).
xtifr wrote:... and orthogon merely sounds undecided.

jozwa
Posts: 141
Joined: Fri Sep 11, 2009 3:16 pm UTC
Location: Finland

Re: 1313: "Regex Golf"

Postby jozwa » Mon Jan 06, 2014 8:16 am UTC

orthogon wrote:It's probably supposed to be obvious, but I guess the number if characters in the regex corresponds to the number of golf shots (or swings, or whatever - I subscribe to the "good walk spoiled" viewpoint).

Well otherwise it would be easy as pie.

OP Tipping
Posts: 230
Joined: Thu Dec 13, 2007 6:23 am UTC

Re: 1313: "Regex Golf"

Postby OP Tipping » Mon Jan 06, 2014 8:48 am UTC

I was going to investigate what all this is about but then I realised life is too short and I already have too many hobbies

User avatar
Envelope Generator
Posts: 582
Joined: Sat Mar 03, 2012 8:07 am UTC
Location: pareidolia

Re: 1313: "Regex Golf"

Postby Envelope Generator » Mon Jan 06, 2014 9:46 am UTC

As golf is to a good walk, so regex golf is to _______?
I'm going to step off the LEM now... here we are, Pismo Beach and all the clams we can eat

eSOANEM wrote:If Fonzie's on the order of 100 zeptokelvin, I think he has bigger problems than difracting through doors.

User avatar
Charodei
Posts: 86
Joined: Fri Jul 21, 2006 8:29 pm UTC

Re: 1313: "Regex Golf"

Postby Charodei » Mon Jan 06, 2014 9:57 am UTC

The obvious problem with the title text is that several people who were elected president had previously run unsuccessfully, or failed to get re-elected. It would be more correct to describe it as matching the last names of all people who have been elected president, but not the names of people who were on a ballot but never elected.

Also, a number of presidents have been in office without ever being elected as president; does the regex match them or not?

alistair
Posts: 1
Joined: Mon Jan 06, 2014 9:56 am UTC

Re: 1313: "Regex Golf"

Postby alistair » Mon Jan 06, 2014 9:59 am UTC

For the next election, the regex matches Clinton, Bush and Santorum, but not Warren or Cruz.

If it helps, it matches Clinton in two ways.

Ehsanit
Posts: 50
Joined: Tue Nov 09, 2010 7:53 pm UTC

Re: 1313: "Regex Golf"

Postby Ehsanit » Mon Jan 06, 2014 10:48 am UTC

No president's name hasn't matched with...

campboy
Posts: 52
Joined: Wed Jun 18, 2008 1:54 am UTC

Re: 1313: "Regex Golf"

Postby campboy » Mon Jan 06, 2014 11:08 am UTC

Charodei wrote:Also, a number of presidents have been in office without ever being elected as president; does the regex match them or not?

Nine people have been president without previously being elected as president. Of those, five were subsequently re-elected, and another has the same surname as one of the five, so it must match all of those six. Ford was subsequently a defeated opponent, so must not be matched. That only leaves Tyler and Fillmore undetermined; neither of them are matched.

User avatar
Tualha
Posts: 69
Joined: Wed Dec 12, 2007 12:18 pm UTC

Re: 1313: "Regex Golf"

Postby Tualha » Mon Jan 06, 2014 11:27 am UTC

Envelope Generator wrote:As golf is to a good walk, so regex golf is to _______?

Readable, maintainable code.

User avatar
orthogon
Posts: 3006
Joined: Thu May 17, 2012 7:52 am UTC
Location: The Airy 1830 ellipsoid

Re: 1313: "Regex Golf"

Postby orthogon » Mon Jan 06, 2014 12:23 pm UTC

OP Tipping wrote:I was going to investigate what all this is about but then I realised life is too short and I already have too many hobbies

Well, you should know by know what the geeky part of the Internet is all about:

regex and bugs and grok and troll.
xtifr wrote:... and orthogon merely sounds undecided.

mathmünster
Posts: 1
Joined: Mon Jan 06, 2014 12:22 pm UTC

Re: 1313: "Regex Golf"

Postby mathmünster » Mon Jan 06, 2014 12:33 pm UTC

How come that the expression matches for the defeated candidates Aaron Burr and John C. Frémont? Obviously only the leading opponent is considered, since right in the first election there are Jay, etc., but Burr and Frémont shouldn't be matched.

User avatar
Klear
Posts: 1965
Joined: Sun Jun 13, 2010 8:43 am UTC
Location: Prague

Re: 1313: "Regex Golf"

Postby Klear » Mon Jan 06, 2014 12:39 pm UTC

Tualha wrote:
Envelope Generator wrote:As golf is to a good walk, so regex golf is to _______?

Readable, maintainable code.


Nope. That would be the equivalent of a nicely trimmed and pleasant lawn.

MichaelKarnerfors
Posts: 94
Joined: Sun Jan 25, 2009 3:30 am UTC
Location: Sweden
Contact:

Re: 1313: "Regex Golf"

Postby MichaelKarnerfors » Mon Jan 06, 2014 1:03 pm UTC

For those that want to play some Regex Golf...

http://regex.alf.nu/

User avatar
Flumble
Yes Man
Posts: 2082
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: 1313: "Regex Golf"

Postby Flumble » Mon Jan 06, 2014 1:05 pm UTC

Envelope Generator wrote:As golf is to a good walk, so regex golf is to _______?

Headaches and bug-prone code

...except for excellent regex experts. I'm think I'm trying too hard.
What I wanted to say is that some people know how to regex and benefit from using them.


MichaelKarnerfors wrote:For those that want to play some Regex Golf...

http://regex.alf.nu/

Wow, it's actually a thing?

Zegnat
Posts: 1
Joined: Mon Jan 06, 2014 1:19 pm UTC

Re: 1313: "Regex Golf"

Postby Zegnat » Mon Jan 06, 2014 1:39 pm UTC

I couldn’t help but play on this. Including “The Clone Wars” but excluding “Star Trek”, the shortest I have gotten is: ^[ar]|m |[wb]a

I also created a Regex Golf-like page where you can test your solutions with instant feedback, but as I can’t post any links yet that will have to remain unknown.

User avatar
cellocgw
Posts: 1955
Joined: Sat Jun 21, 2008 7:40 pm UTC

Re: 1313: "Regex Golf"

Postby cellocgw » Mon Jan 06, 2014 2:58 pm UTC

Envelope Generator wrote:As golf is to a good walk, so regex golf is to _______?


Getting a life? :mrgreen:

ETA: there's a whole CodeGolf section over at StackExchange, too. Feel free to post regex-based solutions :twisted:
Last edited by cellocgw on Mon Jan 06, 2014 2:59 pm UTC, edited 1 time in total.
https://app.box.com/witthoftresume
Former OTTer
Vote cellocgw for President 2020. #ScienceintheWhiteHouse http://cellocgw.wordpress.com
"The Planck length is 3.81779e-33 picas." -- keithl
" Earth weighs almost exactly π milliJupiters" -- what-if #146, note 7

User avatar
da Doctah
Posts: 928
Joined: Fri Feb 03, 2012 6:27 am UTC

Re: 1313: "Regex Golf"

Postby da Doctah » Mon Jan 06, 2014 2:59 pm UTC

Charodei wrote:The obvious problem with the title text is that several people who were elected president had previously run unsuccessfully, or failed to get re-elected. It would be more correct to describe it as matching the last names of all people who have been elected president, but not the names of people who were on a ballot but never elected.

I think the point Randall might have trying to make wrt people like Nixon who both won and lost was that Nixon didn't lose when running against a president already in office, i.e. "the opponent of an elected president" (Kennedy wasn't yet elected during the 1960 campaign).

Otherwise there's no interpretation to allow for the case of two men running against one another repeatedly, with varying outcomes, as was the case in 1884-88-92 when Cleveland and Benjamin Harrison kept swapping the office back and forth between them.

Draco18s
Posts: 86
Joined: Fri Oct 03, 2008 7:50 am UTC

Re: 1313: "Regex Golf"

Postby Draco18s » Mon Jan 06, 2014 4:29 pm UTC

I figured I'd throw the regex in the comic up into http://regexpal.com/ and take a looksee at it, but Regex pal doesn't seem to like it for some reason.

Fauxedit:
Ah, I have to enter it like this: /|M | [TN]| B|/ or it only matches the [TN] part (and make it case insensitive, of course).

And now I'm stuck playing Regex Golf >..x

User avatar
chridd
Has a vermicelli title
Posts: 830
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: 1313: "Regex Golf"

Postby chridd » Mon Jan 06, 2014 7:41 pm UTC

Draco18s wrote:I figured I'd throw the regex in the comic up into http://regexpal.com/ and take a looksee at it, but Regex pal doesn't seem to like it for some reason.

Fauxedit:
Ah, I have to enter it like this: /|M | [TN]| B|/ or it only matches the [TN] part (and make it case insensitive, of course).

And now I'm stuck playing Regex Golf >..x
It works fine for me if I just enter "M | [TN]|B". I suspect your problem is that you were surrounding the regexp with slashes, and it looks to me like it interprets those slashes as matching the character '/' rather than surrounding the regular expression.
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she(?)(?(?)(?))(?(?(?))(?))(?) · Forum game scores
mittfh wrote:I wish this post was very quotable...
chridd (on Discord) wrote:
Dummy wrote:Sorry You're Gay Dads
SYG'D
marionic (on Discord) wrote:sleep in grave

sudo make me a username
Posts: 20
Joined: Thu Jan 02, 2014 2:03 pm UTC

Re: 1313: "Regex Golf"

Postby sudo make me a username » Mon Jan 06, 2014 7:52 pm UTC

Not the strongest xkcd, but it gave me a little bit of entertainment editing the explain xkcd wikia. I generated the entire table of presidents (including making the matching part bold and adding which part of the regex was matched) with a little python script. It was fun :D
My lack of knowledge about US presidents made me use the entire list of presidents in the script. Then I saw three went unmatched and removed them after making sure they were indeed not elected. I found the other two superflous ones using this page. It's okay they were matched because both didn't run for presidency again (according to Wikipedia Chester A. Arthur retired and Andrew Johnson was impeached).

User avatar
pitareio
Posts: 128
Joined: Wed Sep 19, 2012 7:03 pm UTC
Location: the land of smelly cheese

Re: 1313: "Regex Golf"

Postby pitareio » Mon Jan 06, 2014 7:57 pm UTC

poxic wrote:Title text: "/bu|[rn]t|[coy]e|[mtg]a|j|iso|n[hl]|[ae]d|lev|sh|[lnd]i|[po]o|ls/ matches the last names of elected US presidents but not their opponents."



I felt like I had to check, so I looked up a list. This code actually matches Frémont who lost to Buchanan in 1856.

bu|rt|[coy]e|[mtgr]a|j|iso|n[hl]|[ae]d|lev|sh|[lnd]i|[po]o|ls should work.

Spoiler:

Code: Select all

pierrot@pamina:~/presidents$ egrep -i 'bu|rt|[coy]e|[mtgr]a|j|iso|n[hl]|[ae]d|lev|sh|[lnd]i|[po]o|ls' runnersup  | sort -u
Adams
Bush
Carter
Cleveland
Clinton
Harrison
Hoover
Jackson
Jefferson
Nixon
Roosevelt
Van Buren


Only returns runners-up who also were winners in another election.

protandeous
Posts: 2
Joined: Mon Jan 06, 2014 9:05 pm UTC

Re: 1313: "Regex Golf"

Postby protandeous » Mon Jan 06, 2014 9:07 pm UTC

Yes, I found the expression, well, wrong and found this works better

/M | [TNE]|[M] |/

on the set

A New Hope
The Empire Strikes Back
Return of the Jedi
The Phantom Menace
Attack of the Clones
Revenge of the Sith

The Motion Picture
The Wrath of Khan
The Search for Spock
The Voyage Home
The Final Frontier
The Undiscovered Country

Draco18s
Posts: 86
Joined: Fri Oct 03, 2008 7:50 am UTC

Re: 1313: "Regex Golf"

Postby Draco18s » Mon Jan 06, 2014 11:48 pm UTC

chridd wrote:It works fine for me if I just enter "M | [TN]|B". I suspect your problem is that you were surrounding the regexp with slashes, and it looks to me like it interprets those slashes as matching the character '/' rather than surrounding the regular expression.


Good catch. Sometimes I gone done fuck up like that.

Also:
Someone wrote a program that plays Regex Golf with arbitrary lists:
http://nbviewer.ipython.org/url/norvig. ... 1313.ipynb

User avatar
Pfhorrest
Posts: 5007
Joined: Fri Oct 30, 2009 6:11 am UTC
Contact:

Re: 1313: "Regex Golf"

Postby Pfhorrest » Tue Jan 07, 2014 2:24 am UTC

jasper.a.visser wrote:
Kirian wrote:The Motion Picture
The Wrath of Khan
The Search For Spock
The Voyage Home
The Final Frontier
The Undiscovered Country

You missed:
Generations
First Contact
Insurrection
Nemesis
- the one without a subtitle -
Into Darkness

Technically, "Into Darkness" isn't a subtitle. I really hate to be arguing that point because I really wish it wasn't so, but in the Great How-To-Title-The-Wikipedia-Article-For-That-Movie-War of 2013, it was revealed that the producers of the movie are stupid and irrationally hate colons and grammar and that the title of the film is simply "Star Trek Into Darkness" as a unified whole; as in, "Trek" is apparently a verb, "Star" is something like an adverb describing the manner of Trek to be embarked upon, "Into Darkness" is a prepositional phrase indicating where to Trek, and the whole title is an imperative exhorting one to Trek, that is to embark upon a Trek, specifically a Trek of the Star variety, Into the Darkness. Trek, I beseech you! Trek Starly! Go forth, and Star Trek, outward, beyond the light! Star Trek Into Darkness, I command thee!

sigh
Forrest Cameranesi, Geek of All Trades
"I am Sam. Sam I am. I do not like trolls, flames, or spam."
The Codex Quaerendae (my philosophy) - The Chronicles of Quelouva (my fiction)

dreamwalker007
Posts: 8
Joined: Tue Jan 22, 2008 4:59 am UTC

Re: 1313: "Regex Golf"

Postby dreamwalker007 » Tue Jan 07, 2014 2:53 am UTC

I decided to take a shot at some Meta Regex Golf. It's far from bug-free or the most efficient approach, but this is what I came up with.

http://jsfiddle.net/3SX6H/15/

User avatar
orthogon
Posts: 3006
Joined: Thu May 17, 2012 7:52 am UTC
Location: The Airy 1830 ellipsoid

Re: 1313: "Regex Golf"

Postby orthogon » Tue Jan 07, 2014 11:20 am UTC

Flumble wrote:
MichaelKarnerfors wrote:For those that want to play some Regex Golf...

http://regex.alf.nu/

Wow, it's actually a thing?

I was surprised too; I assumed that Randall had invented it as part of the joke.

I've got as far as "5. Abba", but my current regex is 100% wrong: it matches everything in the right list and nothing in the left, which sounds like it should be easy to fix, but... It does however contain a nice pair of ASCII breasts.
xtifr wrote:... and orthogon merely sounds undecided.

sudo make me a username
Posts: 20
Joined: Thu Jan 02, 2014 2:03 pm UTC

Re: 1313: "Regex Golf"

Postby sudo make me a username » Tue Jan 07, 2014 11:38 am UTC

protandeous wrote:Yes, I found the expression, well, wrong and found this works better

/M | [TNE]|[M] |/

on the set

A New Hope
The Empire Strikes Back
Return of the Jedi
The Phantom Menace
Attack of the Clones
Revenge of the Sith

The Motion Picture
The Wrath of Khan
The Search for Spock
The Voyage Home
The Final Frontier
The Undiscovered Country


Why do you say the original regex doesn't work? It works just fine. Anyways I don't understand why did you put |[M] | in yours, it seems superflous when there's already M |. Without it it seems like it'd work even with the extended list of Star Trek movies, and it's shorter then the original so it's a better solution.

Anyways, as someone that knows little about US politics and history I'm not sure who counts as the "opponents" of the presidents, it's a little more confusing at the period there were more than two candidates. I tried to find a list, and the closest I got was this. I assumed the losing candidates were the "opponents" but John Jay appears in the first few elections and his name clearly matches the "j" in the regex. So can someone sort it out for me?


Return to “Individual XKCD Comic Threads”

Who is online

Users browsing this forum: April191774 and 36 guests