@flawr The thing about that is that it uses (almost) all English characters, and one can see from a first glance approximately what it means (Imperfections is an English word, and francais is pretty well-known to mean French)
@StepHen adding ifs were the hardest thing because it was the first block statement that I added. Everything else got easier as I got used to my parser's pattern matching engine
@StepHen ah ok. I used to do char-by-char languages and then char-by-char lexers, but I find regex lexers so much easier to use and much more extendable and maintainable.
def read_literal(self):
result = ""
while self.cur is not None and self.cur != LITERAL_QUOTE:
result += self.cur
self.advance()
return Token(LITERAL, result)
@StepHen No, it's not... I don't post easy challenges in the SB anymore, because then people like Peter Taylor complain that I leave it there for a very short period of time :(
The Self-Referential Algorithm
Most people are familiar with Tupper's self-referential formula. When the formula is graphed on a calculator it magically graphs itself. Wouldn't it be interesting if we could do something similar with a programming language?
Your task
Write a small program that ...
Not really. In logic terms it's basically "There exists a sector X, such that #heads % X is 0, and either (#head / X is 1 or the hydra with #head/X+heads per turn is still killable)"
And so to see if there exists and X, it tries the first element in the list first.
We'd need to reverse the input, then loop down from the number, checking each time if it's prime and if it's a divisor, add that to an array if so and divide out the number. Yeah, somewhere around 150 or so.
I see this room is active, so does anyone want to play Contact once more? (Maybe it's not ok to play twice in a day, but I'm bored and if you don't have anything better to do..)
“You should downvote people’s answers if they are irrelevant, or low-quality, or if you agree with the author on the subject of Russian StackExchange question titles.”
Factors in Common
Based on a chat message
Given an input number n > 999, output a list of all prime factors that the number and its reverse have in common. Note that if the factors of one number are [2, 2, 3, ...] and the other has [2, 3, ...] only one 2 should be output. Obviously a palindromi...