IPv4 Address Iterator
Asked at OpenAI
Reported by the problem's creator, not verified
IPv4 addresses are written as four dotted decimal octets a.b.c.d, each from 0 to 255, such as 10.0.0.254. Read as a single 32-bit number, an address is a * 2^24 + b * 2^16 + c * 2^8 + d, and addresses are ordered by that number. The smallest address is 0.0.0.0 and the largest is 255.255.255.255.
Build the class IPv4Iterator. Each test drives one instance through a sequence of calls and checks every return value. When next() has no address left, it raises StopIteration.
Examples
Example 1
Input: init =
["10.0.0.254"], operations =[["has_next",[]],["next",[]],["next",[]],["next",[]],["has_next",[]],["next",[]]]Output:
[true,"10.0.0.254","10.0.0.255","10.0.1.0",true,"10.0.1.1"]Explanation: The last octet 254 becomes 255, then the next call carries into the third octet. After three returns
has_next()is stilltrueand the followingnext()returns10.0.1.1.