96 points · by sid6376 · 13y ago · 45 comments
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;
}I recommend implementing this as an exercise, rarely do you see that much classic CS theory put to a practical use in one place.
match :: String -> String -> Bool
match ('^':rest) text = matchLocal rest text
match rex (c:rest) = matchLocal rex (c:rest) || match rex rest
match _ _ = False
matchLocal :: String -> String -> Bool
matchLocal [] _ = True
matchLocal "$" [] = True
matchLocal (c:'*':restR) (t:restT) = c == t && matchLocal restR (starSkip c (t:restT))
matchLocal (r:restR) (t:restT) = (r == '.' || r == t) && matchLocal restR restT
matchLocal _ _ = False
starSkip :: Char -> String -> String
starSkip c (t:rest) = if c == t then starSkip c rest else t:rest
starSkip _ [] = []Adding a few lines of css (setting body width, font-size to 16, line-height to 1.4, Georgia for font and larger font size for headings ) makes for a decent reading experience.
body {
width: 70%;
font-size: 20px;
margin: auto;
font-family: sans-serif;
line-height: 30px;
}Sans-serifs are generally harder to read. Note, for example, how virtually all books are set in serifs. The primary reason sans-serifs are widely used in computers is the lack of decent display resolution required to display the actual serifs. So if you are using a larger font size to read something off the screen, there is no reason not to use a serifed typeface.
Setting it as a percentage will obviously always make it look the same since it scales. However, a percentage on a huge screen usually makes it too wide to read lines comfortably.
You pretty much have to pick your poison, though IMO about 600 px is the maximum width for a line before it's horrible to read on a full hd screen.
But, having an extension like Stylebot installed and using a tiny custom CSS does offer an advantage - the CSS applies across the domain and takes effect every time the page is loaded.
For example, see this gallery - http://imgur.com/a/MxFtD
If you're going to judge this code based on both pathological haystacks but also pathological needle regexs, then you have to admit that this code, which has linear space usage in the pattern length is far better than PCRE, which has exponential time in the pattern length[1].
Considering its succinctness, I find that pretty impressive.
An equivalent would need to pass indexes to sub functions to avoid additional copies.
(I'd seen Pike's code years before in _The Practice of Programming_, so it's not independent.)
I will say that the problem is much easier if you have a good grounding in the basics of compilers, while that knowledge is not hugely useful very often. Any positive value as a test will come from correlation with interest in CS IMO.
The only bad part is that most candidates can't even write a correct strstr(3), so it becomes incredibly depressing.