# 采摘编程面试问题。

2020年4月19日。提起下python58

Write a program that prints the numbers from 1 to 100.But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”.For numbers which are multiples of both three and five print “FizzBuzz”.

`对于i在范围（100）：div_3 = I％3 == 0 div_5 = I％5 == 0如果div_3和div_5：打印（ “Fizzbuzz”）的elif div_5：打印（ “嗡嗡”）的elif div_3：打印（”费兹“）其他：打印（STR（I））`

``Hey @lethain, did you know about a #typo on page 24 of your book?``

``[ {kind: "mention", name: "lethain", start: 5, end: 7}, ...]``

`TXT =“嘿@lethain，你知道你的书的第24页上#typo？” WORD = 'word' MENTION = 'mention' HASH = 'hash' HASH_START = '#' MENTION_START = '@' WHITESPACE_START = ' ' PUNCTUATION = '!?,;:' def make_token(kind, txt, start, end): return (kind, txt, start, end) def tokenize(txt): tokens = [] acc = "" start = 0 kind = WORD for i, ch in enumerate(txt): if ch in WHITESPACE_START or ch in PUNCTUATION: if acc: token = make_token(kind, acc, start, i) tokens.append(token) acc = "" start = i kind = WORD elif acc == "" and ch == HASH_START: kind = HASH elif acc == "" and ch == MENTION_START: kind = MENTION else: acc += ch if len(acc) > 0: token = make_token(kind, acc, start, len(txt)) tokens.append(token) return tokens print(tokenize(txt))`

The other concern I have with this specific problem is that it is the sort of problem that can be fairly easy while all the pieces are fitting into your head, but once you make one mental slip then all the pieces come crumbling down around you.I confused myself a bit writing this code alone in a room, and could easily imagine getting stuck during a timed interview with someone watching you.

AtCalm, we've historically relied on having a single staging environment where software was tested against a complete environment, but recently the team rolled out multiple staging environments.This is a major improvement, and opened up an interesting question: how should we assign staging environments to people?

The good enough solution is to assign one staging environment to each team, but the theoretically ideal solution might be having a queue of folks who want to use an environment, and then assign them across the pool of environments as they become available.

I was thinkingthatmight be an interesting interview problem.It's a fairly real problem, doesn't require much backstory to answer, and it avoids the mental load or context-specific experience of something like tokenizing text.

`POOL = ['a', 'b', 'c', 'd'] ASSIGNMENTS = {key: None for key in POOL} WAITING = [] def status(): txt = "Status\n" for key in POOL: val = ASSIGNMENTS[key] val_txt = val if val else "" txt += "\t" + key + ": " + val_txt + "\n" txt += "\nwaiting: %s" % (WAITING,) print(txt) def queue(name): for key, val in ASSIGNMENTS.items(): if val is None: print("UPDATE") ASSIGNMENTS[key] = name return WAITING.append(name) def pop(name): for key, val in ASSIGNMENTS.items(): if val == name: first = None if len(WAITING) > 0: first = WAITING.pop(0) ASSIGNMENTS[key] = first return ops = [ (queue, "will"), (pop, "will"), (queue, "will"), (queue, "jill"), (queue, "bill"), (queue, "phil"), (queue, "chill"), (queue, "quill"), (queue, "fill"), (pop, "chill"), (pop, "bill"), (pop, "chill"), ] status() for cmd, val in ops: cmd(val) status()`

This is a problem where it's easy to write something that works, and watch someone debug the issues they run into along the way.Then once someone writes an intial solution, you can imagine a bunch of ways to continue adding complexity to it that require them to refactor their code.For example, you could add a maximum allowed time to use an environment, after which you'd automatically get removed, and so on.

## Requirements for a good problem

Putting all of this together, I think what makes good problems to evaluate programming experience of senior and Staff-plus candidates are:

1. Support simple initial solutions and compounding requirements
2. Are solvable with a few dozen lines of code
3. Require algorithmic thinking but not knowing a specific algorithm