Stage 1 of 4: Counting up
Background. An IPv4 address is written as four numbers from 0 to 255 joined by dots, and stands for one 32-bit number whose most significant byte comes first. So the addresses form one ordered line from 0.0.0.0 up to 255.255.255.255, and 91.203.48.0 follows 91.203.47.255.
Implement the class AscendingAddresses(from_address) in addresses.py, an iterator over the addresses from from_address up through 255.255.255.255, both included.
iter(it)returnsititself, and eachnext(it)returns one address as a dotted string.- After
255.255.255.255the iterator is exhausted:next(it)raisesStopIteration, then and on every later call. - Instances are independent: each keeps its own place.
- Addresses are worked out as they are asked for. Creating an iterator and reading up to 5,000 addresses from it takes less than a second altogether, even when billions are left.
Example
it = AscendingAddresses("91.203.47.254")
next(it) # "91.203.47.254"
next(it) # "91.203.47.255"
next(it) # "91.203.48.0"
Notes
- Inputs are always valid: four numbers from 0 to 255, with no spaces and no leading zeros. Addresses are returned in the same form.
- On the starter, all 9 tests in
tests/test_part1.pyfail.
Done when Submit goes green.
Constraints
- Python 3.12 standard library only
- Editable:
addresses.py - Read-only:
test_helpers.pyand alltests/test_*.pyfiles - Inputs are always valid
What comes after stage 1
The next stages open once the tests for the one before them pass. Each raises the bar, the way an interviewer does in the room.
- Stage 2: Counting down. The same walk in the other direction, down to the lowest address.
- Stage 3: CIDR blocks. Prefix lengths arrive, up to blocks of billions of addresses, and both walks have to cope.
- Stage 4: A run as blocks. Any run of consecutive addresses, written in as few blocks as possible.
The files you get
- Yours to edit: addresses.py.
- Read-only: test_helpers.py.
- Tests you can read and run: tests/test_part1.py. Hidden tests run on Submit.
The round: no AI, an assistant that only answers
OpenAI runs this round without AI. Here the closest format is answer-only: the assistant answers your questions and reviews your code when you ask, the way an interviewer would, and never writes a line of it. The interviewer asks about your decisions as you go, and the report states the format. You can switch to the agent format when you press Begin.
Frequently asked, briefly answered
Is IPv4 Addresses and Blocks free?
It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.
Which company asks something like this?
OpenAI. It is modelled on OpenAI's coding round, which runs without AI. Based on candidates' reports of OpenAI interviews. Nyrion wrote this version, so the question you get may differ.
Do I bring my own AI tool?
No. The real round has no AI, so this one opens answer-only: an assistant that answers your questions and can't write code. You can switch to an agent that proposes changes when you press Begin.
What does the interviewer ask?
3 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.
Start the problem
Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.
More like it: every practice problem, OpenAI's interviews, the AI coding interview guide.