Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

71%
+3 −0
Challenges Find the IP address class

Python 3, 56 bytes lambda x:chr(65+f'{int(float(x[:3]))&~8:08b}'.find('0')) Try it online! Takes in the ip address as a string and returns the classification letter. Explanation: x[:...

posted 3y ago by dino‭  ·  edited 3y ago by dino‭

Answer
#14: Post edited by user avatar dino‭ · 2022-01-28T20:53:09Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 59 bytes
  • ```python
  • lambda x:chr(65+f'{int(x[:x.find(".")])&~8:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDNDoIwEITvPEXDwdJoNu22IMXwJOoBkAYSRQI9YAi@OuJPEN3NzuHLZJLZ@maLayVHEx/Gc3JJTwnpoqxovMBfG9qXlfW6fdSBKauT54LLjmx1DyMepgN9Q8opY6PNW5slbd6SmOwdMg0VHJCD5KA43XwQboFPK74gBIEg5aTbGWoBWgP6amHUCCIIQSHMPkT5m4ao/oDUf0DxZ0SgQXyZ78PiqHN0HHNtiCVlReZe0ctcN8@PGLc3nmXD1LW3g8t24wM "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:x.find(".")]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…&~8` sets the 8 bit (fourth to last) of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `117` becomes `'01110101'`)
  • - `….find('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python 3], 56 bytes
  • <!-- language-all: lang-python -->
  • lambda x:chr(65+f'{int(float(x[:3]))&~8:08b}'.find('0'))
  • [Try it online!][TIO-kyyvrix6]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-kyyvrix6]: https://tio.run/##XZDNDoIwEITvPEXjwbbRbNpt@SnGJ1EO@NNAgkCgBwzBV0c0BtTd7By@TCaZre8uq0o12v1xLNLb6ZKSLj5nDQv8jaV9Xjpmiyp1rDvEKuF8/YhiEZ0GCjYvL4wKyvnorq07p@21JXty8Mg0VApAAUqAFnT7QRiCmFYuIAKJoNSk4QyNBGMAff1lNAgyiEAjzD5E9ZuGqP@AMn9Ai1dEYEAuzPfh66iXeJ6tGuJIXpK5V/w21837HaveMseHqWvvhhXfjU8 "Python 3 – Try It Online"
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:3]` extracts the first 3 characters
  • - `int(float(…))` converts `str` to `int`, passing through `float` to handle cases like `1.2.3.4` -> `1.2` -> `1`
  • - `…&~8` sets the 8 bit (fourth to last) of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `117` becomes `'01110101'`)
  • - `….find('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#13: Post edited by user avatar dino‭ · 2021-12-16T20:33:48Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 59 bytes
  • ```python
  • lambda x:chr(65+f'{int(x[:x.find(".")])&~8:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDNDoIwEITvPEXDwdJoNu22IMXwJOoBkAYSRQI9YAi@OuJPEN3NzuHLZJLZ@maLayVHEx/Gc3JJTwnpoqxovMBfG9qXlfW6fdSBKauT54LLjmx1DyMepgN9Q8opY6PNW5slbd6SmOwdMg0VHJCD5KA43XwQboFPK74gBIEg5aTbGWoBWgP6amHUCCIIQSHMPkT5m4ao/oDUf0DxZ0SgQXyZ78PiqHN0HHNtiCVlReZe0ctcN8@PGLc3nmXD1LW3g8t24wM "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:x.find(".")]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…&~8` sets the 8 bit (fourth to last) of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `117` becomes `'01110101'`)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 59 bytes
  • ```python
  • lambda x:chr(65+f'{int(x[:x.find(".")])&~8:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDNDoIwEITvPEXDwdJoNu22IMXwJOoBkAYSRQI9YAi@OuJPEN3NzuHLZJLZ@maLayVHEx/Gc3JJTwnpoqxovMBfG9qXlfW6fdSBKauT54LLjmx1DyMepgN9Q8opY6PNW5slbd6SmOwdMg0VHJCD5KA43XwQboFPK74gBIEg5aTbGWoBWgP6amHUCCIIQSHMPkT5m4ao/oDUf0DxZ0SgQXyZ78PiqHN0HHNtiCVlReZe0ctcN8@PGLc3nmXD1LW3g8t24wM "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:x.find(".")]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…&~8` sets the 8 bit (fourth to last) of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `117` becomes `'01110101'`)
  • - `….find('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#12: Post edited by user avatar dino‭ · 2021-12-16T20:25:44Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 59 bytes
  • ```python
  • lambda x:chr(65+f'{int(x[:x.find(".")])&~8:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDNDoIwEITvPEXDwdJoNu22IMXwJOoBkAYSRQI9YAi@OuJPEN3NzuHLZJLZ@maLayVHEx/Gc3JJTwnpoqxovMBfG9qXlfW6fdSBKauT54LLjmx1DyMepgN9Q8opY6PNW5slbd6SmOwdMg0VHJCD5KA43XwQboFPK74gBIEg5aTbGWoBWgP6amHUCCIIQSHMPkT5m4ao/oDUf0DxZ0SgQXyZ78PiqHN0HHNtiCVlReZe0ctcN8@PGLc3nmXD1LW3g8t24wM "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:x.find(".")]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…&~8` sets the 8 bit (fourth to last) of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 59 bytes
  • ```python
  • lambda x:chr(65+f'{int(x[:x.find(".")])&~8:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDNDoIwEITvPEXDwdJoNu22IMXwJOoBkAYSRQI9YAi@OuJPEN3NzuHLZJLZ@maLayVHEx/Gc3JJTwnpoqxovMBfG9qXlfW6fdSBKauT54LLjmx1DyMepgN9Q8opY6PNW5slbd6SmOwdMg0VHJCD5KA43XwQboFPK74gBIEg5aTbGWoBWgP6amHUCCIIQSHMPkT5m4ao/oDUf0DxZ0SgQXyZ78PiqHN0HHNtiCVlReZe0ctcN8@PGLc3nmXD1LW3g8t24wM "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:x.find(".")]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…&~8` sets the 8 bit (fourth to last) of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `117` becomes `'01110101'`)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#11: Post edited by user avatar dino‭ · 2021-12-16T20:23:36Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 60 bytes
  • ```python
  • lambda x:chr(65+f'{int(x[:x.find(".")])&240:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDBDoIwEETvfEXDwdJoNtttQYrxS5QDoo0kigZ6wBC@HUENKrvZObxMJpm9P9z5Vqrebvf9JbsejhlrkvxcBVG4tLwtShc0u6QBW5THwAdfpGJBGhOMDx1/U45ciN6dapdn9almW7bz2DBcIhCCQtDIVx9Ea8Bh5RfEIAmUGnQ9QSPBGKBQ/xgNgYxi0ASTj0j9pxHpGVBmBjSOEZEB@WVhCD/HvdTz7K1ijhUlm3olL/O9Gl9i/dYGTnRD19Z1vtj0Tw "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:x.find(".")]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…&240` sets the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 59 bytes
  • ```python
  • lambda x:chr(65+f'{int(x[:x.find(".")])&~8:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDNDoIwEITvPEXDwdJoNu22IMXwJOoBkAYSRQI9YAi@OuJPEN3NzuHLZJLZ@maLayVHEx/Gc3JJTwnpoqxovMBfG9qXlfW6fdSBKauT54LLjmx1DyMepgN9Q8opY6PNW5slbd6SmOwdMg0VHJCD5KA43XwQboFPK74gBIEg5aTbGWoBWgP6amHUCCIIQSHMPkT5m4ao/oDUf0DxZ0SgQXyZ78PiqHN0HHNtiCVlReZe0ctcN8@PGLc3nmXD1LW3g8t24wM "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:x.find(".")]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…&~8` sets the 8 bit (fourth to last) of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#10: Post edited by user avatar dino‭ · 2021-12-16T19:43:22Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 62 bytes
  • ```python
  • lambda x:chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDLDoIwEEX3fEXDpm00k@m0IMXHj6gLfDSSKBDoAkP4dkRj8DGTuYuTm5vcqe7@UhZ6cOvdcM1uh1PG2vR4qUUczRzv8sKLFprqmnsRQii3uJebjVmtTIrJoefg8uIkOHIpB39u/DFrzg1bs23AxuEKgRA0gkE@fyNaAI6rPiABRaD1qIsJWgXWAkXmy2gJVJyAIZh8RPo3jcj8AW3/gMFnRGxBfVgUwdfxYB8ErqyZZ3nBpl7py1zVz6e4sHPCy37s2vk@lMvhAQ "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to set the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 60 bytes
  • ```python
  • lambda x:chr(65+f'{int(x[:x.find(".")])&240:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDBDoIwEETvfEXDwdJoNtttQYrxS5QDoo0kigZ6wBC@HUENKrvZObxMJpm9P9z5Vqrebvf9JbsejhlrkvxcBVG4tLwtShc0u6QBW5THwAdfpGJBGhOMDx1/U45ciN6dapdn9almW7bz2DBcIhCCQtDIVx9Ea8Bh5RfEIAmUGnQ9QSPBGKBQ/xgNgYxi0ASTj0j9pxHpGVBmBjSOEZEB@WVhCD/HvdTz7K1ijhUlm3olL/O9Gl9i/dYGTnRD19Z1vtj0Tw "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x[:x.find(".")]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…&240` sets the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#9: Post edited by user avatar dino‭ · 2021-12-16T15:20:56Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 69 bytes
  • ```python
  • def y(x):return chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDBasMwEETv/grhiyRaltVKdiw3zY@EHNrEIoaiGHkLMcbf7jqlOGl22Tk8hoHZbuDzJdp5PjVBDOqq69Twd4rieE6qLF6CHNvI6gp999WyyiHXezzo3c5tt67G6nOSENp4UhKl1jM3PR8/@qYX72KfiWWkQSAEi@BQvv4h2gAua@6gAkNg7aKbFXoD3gMV7sHoCUxZgSNYfUT2fxqRewLWPwGHt4jSg7mzooCHk9khy8IlCRZtFGuv@tfcpdtTQj4OivW0dB15yvXb/AM "Python 3 – Try It Online")
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to set the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 62 bytes
  • ```python
  • lambda x:chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDLDoIwEEX3fEXDpm00k@m0IMXHj6gLfDSSKBDoAkP4dkRj8DGTuYuTm5vcqe7@UhZ6cOvdcM1uh1PG2vR4qUUczRzv8sKLFprqmnsRQii3uJebjVmtTIrJoefg8uIkOHIpB39u/DFrzg1bs23AxuEKgRA0gkE@fyNaAI6rPiABRaD1qIsJWgXWAkXmy2gJVJyAIZh8RPo3jcj8AW3/gMFnRGxBfVgUwdfxYB8ErqyZZ3nBpl7py1zVz6e4sHPCy37s2vk@lMvhAQ "Python 3 – Try It Online")
  • Takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to set the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#8: Post edited by user avatar dino‭ · 2021-12-16T15:10:07Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 69 bytes
  • ```python
  • def y(x):return chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##Zc5dC4IwFAbg@36FeLON4HD24cfM/CPRTakkhIkZKOJvNyVcUxkbnJfnPazqmserlOOYZrnT0ZZFddZ86tK5P2rqe8ec9EXZ0Bbe1bNoqAsuu@CVJYmKYxVheBsI5EWZUoKEsbGqZ527HEEgSASFztnpO0qshLDBZaeDsSIAnA5f5DLvXAhcgJTTGxhrZVuvOWgNwlP/1Va00wK4H4ISYJZb0UYLoVZ/NvPWKZzrvgZuqBVtteeBdZfCOv11xi8)
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to set the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 69 bytes
  • ```python
  • def y(x):return chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##XZDBasMwEETv/grhiyRaltVKdiw3zY@EHNrEIoaiGHkLMcbf7jqlOGl22Tk8hoHZbuDzJdp5PjVBDOqq69Twd4rieE6qLF6CHNvI6gp999WyyiHXezzo3c5tt67G6nOSENp4UhKl1jM3PR8/@qYX72KfiWWkQSAEi@BQvv4h2gAua@6gAkNg7aKbFXoD3gMV7sHoCUxZgSNYfUT2fxqRewLWPwGHt4jSg7mzooCHk9khy8IlCRZtFGuv@tfcpdtTQj4OivW0dB15yvXb/AM "Python 3 – Try It Online")
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to set the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#7: Post edited by user avatar dino‭ · 2021-12-16T14:55:47Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 69 bytes
  • ```python
  • def y(x):return chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to set the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 69 bytes
  • ```python
  • def y(x):return chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • [Try it online!](https://tio.run/##Zc5dC4IwFAbg@36FeLON4HD24cfM/CPRTakkhIkZKOJvNyVcUxkbnJfnPazqmserlOOYZrnT0ZZFddZ86tK5P2rqe8ec9EXZ0Bbe1bNoqAsuu@CVJYmKYxVheBsI5EWZUoKEsbGqZ527HEEgSASFztnpO0qshLDBZaeDsSIAnA5f5DLvXAhcgJTTGxhrZVuvOWgNwlP/1Va00wK4H4ISYJZb0UYLoVZ/NvPWKZzrvgZuqBVtteeBdZfCOv11xi8)
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to set the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#6: Post edited by user avatar dino‭ · 2021-12-16T14:47:01Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 69 bytes
  • ```python
  • def y(x):return chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to "round down" to the nearest classification cutoff point
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `236` becomes `'11100000'` after rounding down in the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 69 bytes
  • ```python
  • def y(x):return chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to set the last 4 bits of the integer to `0`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `125` becomes `'01110000'` after taking into account the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#5: Post edited by user avatar dino‭ · 2021-12-16T14:42:50Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 77 bytes
  • ```python
  • def y(x):return chr(64+(f'{int(x.split(".")[0]):08b}'[:4].find('0')+1 or 5))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `4` becomes `'00000100'`)
  • - `[:4]` keeps only the first 4 digits of the binary string
  • - `….index('0')` finds the index of the first `'0'` character
  • - `64+(…+1 or 5)` converts -1 (not found) to 4 (to put it in the E slot) and adds 65 (the character code for 'A')
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 69 bytes
  • ```python
  • def y(x):return chr(65+f'{int(x.split(".")[0])>>4<<4:08b}'.find('0'))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `…>>4<<4` uses bitshift operations to "round down" to the nearest classification cutoff point
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `236` becomes `'11100000'` after rounding down in the last step)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `65+…` adds the character code for 'A'
  • - `chr(…)` converts the sum from the previous step to a character
#4: Post edited by user avatar dino‭ · 2021-12-16T14:09:39Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 73 bytes
  • ```python
  • def y(x):return chr(64+(f'{int(x.split(".")[0]):08b}'.find('0')+1 or 5))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `4` becomes `'00000100'`)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `64+(…+1 or 5)` converts -1 (not found) to 4 (to put it in the E slot) and adds 65 (the character code for 'A')
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 77 bytes
  • ```python
  • def y(x):return chr(64+(f'{int(x.split(".")[0]):08b}'[:4].find('0')+1 or 5))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `4` becomes `'00000100'`)
  • - `[:4]` keeps only the first 4 digits of the binary string
  • - `….index('0')` finds the index of the first `'0'` character
  • - `64+(…+1 or 5)` converts -1 (not found) to 4 (to put it in the E slot) and adds 65 (the character code for 'A')
  • - `chr(…)` converts the sum from the previous step to a character
#3: Post edited by user avatar dino‭ · 2021-12-15T20:49:28Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 64 bytes
  • ```
  • def y(x):return chr(65+f'{int(x.split(".")[0]):08b}'.index('0'))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `4` becomes `'00000100'`)
  • - `65 + ….index('0')` finds the index of the first `'0'` character and adds 65 (the character code for 'A')
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 73 bytes
  • ```python
  • def y(x):return chr(64+(f'{int(x.split(".")[0]):08b}'.find('0')+1 or 5))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `4` becomes `'00000100'`)
  • - `….index('0')` finds the index of the first `'0'` character
  • - `64+(…+1 or 5)` converts -1 (not found) to 4 (to put it in the E slot) and adds 65 (the character code for 'A')
  • - `chr(…)` converts the sum from the previous step to a character
#2: Post edited by user avatar dino‭ · 2021-12-15T20:27:44Z (about 3 years ago)
  • # [Python3](https://www.python.org/), 69 bytes
  • ```
  • def y(x):return chr(65+format(int(x.split('.')[0]),'08b').index('0'))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `format(…, '08b')` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `4` becomes `'00000100'`)
  • - `65 + ….index('0')` finds the index of the first `'0'` character and adds 65 (the character code for 'A')
  • - `chr(…)` converts the sum from the previous step to a character
  • # [Python3](https://www.python.org/), 64 bytes
  • ```
  • def y(x):return chr(65+f'{int(x.split(".")[0]):08b}'.index('0'))
  • ```
  • Creates a function `y` which takes in the ip address as a string and returns the classification letter.
  • ## Explanation:
  • - `x.split('.')[0]` extracts everything before the first `'.'` character
  • - `int(…)` converts `str` to `int`
  • - `f'{…:08b}'` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `4` becomes `'00000100'`)
  • - `65 + ….index('0')` finds the index of the first `'0'` character and adds 65 (the character code for 'A')
  • - `chr(…)` converts the sum from the previous step to a character
#1: Initial revision by user avatar dino‭ · 2021-12-15T20:07:42Z (about 3 years ago)
# [Python3](https://www.python.org/), 69 bytes
```
def y(x):return chr(65+format(int(x.split('.')[0]),'08b').index('0'))
```

Creates a function `y` which takes in the ip address as a string and returns the classification letter.

## Explanation:

- `x.split('.')[0]` extracts everything before the first `'.'` character
- `int(…)` converts `str` to `int`
- `format(…, '08b')` converts the integer to a binary string, left-padded to 8 characters (e.g. `192` becomes `'11000000'` and `4` becomes `'00000100'`)
- `65 + ….index('0')` finds the index of the first `'0'` character and adds 65 (the character code for 'A')
- `chr(…)` converts the sum from the previous step to a character