I thought I had seen it before. Verified you can actually see the whole chapter in a nicer (book vs web) layout in Amazon's "Look inside" feature since it's at the beginning of the book.
I used to use this exact problem years ago when interviewing candidates at Google. At that time I thought it was a great question, but now I'm not that sure anymore if this approach to interviewing is the best way to assess candidates.
We software types must be masochists. It took Rob Pike an hour in the comfort of his private office to write this piece of code. How is this _at all_ like a typical software interview?
Have you seen that used for interviewing? Yes, some people can do it in a 1-hour interview, but wouldn't you rather ask something that can't be done from memory?
I know engineers who have asked it, yes. It really seems to be a test for "who was paying attention to that one lecture in CS205 near the end of the semester"
Wow. That's quite a tricky test, too -- if you study Thompson's original paper you can see plenty of pitfalls. E.g. his main code would loop forever on a star of a star, and he solves this in an appendix with a preprocessor to rewrite regexes of that kind, only it looked like that rewriting would blow up the size of the regex exponentially in the length of the stack of stars. No hire!
I have seen this one go by, which, from the perspective of someone who has been doing regex implementation for 14 years, more or less, is fairly amusing. It seems unfair, as someone aware of potential pitfalls of backtracking would presumably feel obligated to build a automata-based solution; someone aware also of the potential pitfalls of DFAs (failure to determinize quickly on some nasty patterns) might also feel obligated to build a Thompson or Glushkov NFA solution as well.
It's quite possible you might turn someone competent into a gibbering wreck (they are asking me to implement RE2 or Hyperscan in an hour!) :-)
Seeing code like this I can understand why the pioneers though C code could be pretty.
But now all I see there is something more akin to a demonstration of ice carving with chainsaws than something that should be used in a production system.
Part II: Impeachment Is A Diversion And Delay - Blocking of the "impeachment" witnesses was collusion planned before the new year. Listen to an FBI agent's disclosure from Jan 1, 2O2O here. President was to resign late summer securing election for DNC. See latest updates.
Here is the zip file, which was also made available in the 3Jan2O2O update. The file within is VID_20200101_201948.mp3. Turn up the volume and put on headphones.
The dialogue about the impeachment starts near the beginning. Having Biden in the White House is as good as Trump or anyone else in their organization. Obviously Schiff and Nadler pledged their allegiance to the organization by raping boys on the record, with their task being to drag out an impeachment designed to obstruct and delay any real efforts to remove the President, thus keeping Trump in power. The witness blocking was to cause an apparent uproar delaying things with legal actions until late Summer. Soon after, the President would resign, leaving any other candidate with not enough time or support to compete with an opportunistic Biden, who is as good as Trump or any other Illuminati friendly politician in the Presidency.
\Wag The Dog: first was feigned impeachment hearings meant to obstruct, now an attack on Iranians in Iraq. Here is what they are trying to distract from & cover up to retain power. $100+ billion in bribes to the highest offices in this country. 815+ deaths from child rapes to prove loyalty!
See the latest PDF updates: FBI Director Wray, AG Barr, SoD Shanahan, & SoS Pompeo each raped boys and were paid billions in bribes for a Soros & Koch funded child rape org. So did Trump & his "impeachment" team Nadler,Schiff,Mueller.So did media moguls Redstone,Murdoch,Moonves. What are they trying to set up? Who can arrest them since they are all bribed and in on it ?
Their strategy to stay in every office and obstruct until forced to leave no matter what. Feigning impeachment: see page 13O. erppmpoerwvfewq. ver verwbvoltwb.
\\if;Download the video/audio file, put on headphones and turn up the volume. You will hear these people committing these crimes. Audio was broadcast into my apartment by outdated surveillance equipment illegally embedded within my walls. This very same technology was being used to broadcast me to the internet for five years without my consent. I own this footage. Please use this to prosecute all found within. Note:: I am obliviously speaking throughout the video, and it can be quite loud at times relative to the desired content. The are dozens more links, including these, that can be found in this PDF last updated 4 FEB 2O2O:
These posts are great for history, but regular expression implementation has moved on considerably from early Thompson implementations whether backtracking or NFAs. There is a considerable body of literature about regex implementation, including many quite convincing implementations and alternate formulations, some of which weren't even done by people at, or from, Bell Labs!
We seem to have something of an Eternal September of regex implementation knowledge (abetted by Russ Cox's amazingly selective bibliography in his posts introducing RE2).
Skimming over it, the implementation looks inefficient:
int matchstar(int c, char *regexp, char *text)
{
do { /* a * matches zero or more instances */
if (matchhere(regexp, text))
return 1;
} while (*text != '\0' && (*text++ == c || c == '.'));
return 0;
}
That can be used to match short strings, but not to grep through a filesystem. A good regex matcher has runtime O(N*M) where N is the length of the regex (typically very short) and M is the length of the scanned text.
A surprising number of regex tools used in the wild employ a backtracking algorithm like this one. Some popular features such as lookaheada, lookbehinds, and backreferences can't always be matched using a finite automaton.
27 comments
[ 2.9 ms ] story [ 56.3 ms ] threadhttps://www.amazon.com/Beautiful-Code-Leading-Programmers-Pr...
Here’s the repo if anyone is interested in checking out the others:
https://github.com/marcpaq/b1fipl
It's quite possible you might turn someone competent into a gibbering wreck (they are asking me to implement RE2 or Hyperscan in an hour!) :-)
But now all I see there is something more akin to a demonstration of ice carving with chainsaws than something that should be used in a production system.
2013: https://news.ycombinator.com/item?id=5672875
2011: https://news.ycombinator.com/item?id=2723366
Maybe others?
p.s. these links are just for curious readers; reposts are ok after a year or so—see https://news.ycombinator.com/newsfaq.html.
BB10Mp3Footage31Dec1Jan.zip 122.4mb
https://drive.google.com/file/d/1IXOOhQhHybwky8Z5pGdr9ZXhWpI...
The dialogue about the impeachment starts near the beginning. Having Biden in the White House is as good as Trump or anyone else in their organization. Obviously Schiff and Nadler pledged their allegiance to the organization by raping boys on the record, with their task being to drag out an impeachment designed to obstruct and delay any real efforts to remove the President, thus keeping Trump in power. The witness blocking was to cause an apparent uproar delaying things with legal actions until late Summer. Soon after, the President would resign, leaving any other candidate with not enough time or support to compete with an opportunistic Biden, who is as good as Trump or any other Illuminati friendly politician in the Presidency.
162 page PDF [last updated: February|4|2O2O]:
https://drive.google.com/file/d/1S7T_kDv48E40eHzus6CTXHxcm0W...
Previously reported:
\Wag The Dog: first was feigned impeachment hearings meant to obstruct, now an attack on Iranians in Iraq. Here is what they are trying to distract from & cover up to retain power. $100+ billion in bribes to the highest offices in this country. 815+ deaths from child rapes to prove loyalty!
See the latest PDF updates: FBI Director Wray, AG Barr, SoD Shanahan, & SoS Pompeo each raped boys and were paid billions in bribes for a Soros & Koch funded child rape org. So did Trump & his "impeachment" team Nadler,Schiff,Mueller.So did media moguls Redstone,Murdoch,Moonves. What are they trying to set up? Who can arrest them since they are all bribed and in on it ?
Their strategy to stay in every office and obstruct until forced to leave no matter what. Feigning impeachment: see page 13O. erppmpoerwvfewq. ver verwbvoltwb.
\\if;Download the video/audio file, put on headphones and turn up the volume. You will hear these people committing these crimes. Audio was broadcast into my apartment by outdated surveillance equipment illegally embedded within my walls. This very same technology was being used to broadcast me to the internet for five years without my consent. I own this footage. Please use this to prosecute all found within. Note:: I am obliviously speaking throughout the video, and it can be quite loud at times relative to the desired content. The are dozens more links, including these, that can be found in this PDF last updated 4 FEB 2O2O:
https://drive.google.com/file/d/1S7T_kDv48E40eHzus6CTXHxcm0W...
All members of the "Illuminati"; "....an underground organization of homosexuals and child rapists..." (from pg 26: Barack Obama with Jack Dorsey).
President Donald Trump:
Demands a $4 billion dollar bribe here at 10:18am 4thJan2019:
3JanCh3_900-1100.avi
https://drive.google.com/file/d/1Grdr8xF2psKNsuYlEnl9dIRV-77...
3JanCh2_900-1100-avi
We seem to have something of an Eternal September of regex implementation knowledge (abetted by Russ Cox's amazingly selective bibliography in his posts introducing RE2).