Post History
JavaScript, 43 bytes s=>"ABCDE"[Math.log2(s.slice(0,3)^255|8)^7] Try it online! Taking the first 3 characters of the string is always enough to include the first octet, while including at...
Answer
#1: Initial revision
# JavaScript, 43 bytes <!-- language-all: lang-javascript --> s=>"ABCDE"[Math.log2(s.slice(0,3)^255|8)^7] [Try it online!][TIO-kxbqkt5m] Taking the first 3 characters of the string is always enough to include the first octet, while including at most one full stop. Before the bitwise XOR, the substring is converted to a Number (if a full stop is present, it is interpreted as a decimal point) and then to a 32-bit integer (rounding towards zero), thus becoming the value of the first octet. XORing with 255 produces 128–255 for class A, 64–127 for class B, 32–63 for class C, 16–31 for class D, and 0–15 for class E. ORing with 8 narrows those ranges; in particular, class E is reduced to 8–15, which fits the pattern of the original ranges for the other classes. Taking the base-2 logarithm, and (implicitly) rounding towards zero, produces 7, 6, 5, 4, 3 for classes A, B, C, D, E; XORing with 7 changes those to 0, 1, 2, 3, 4, which is finally used as an index into the string "ABCDE" to produce the result. [TIO-kxbqkt5m]: https://tio.run/##VU7LCsIwELz3M3JqQZdkk7T1oODr6BcUC6VWrda2NCII/nvdJIrIMrAzuzPMpXgUphzq/j41fX2ohlvXXqvneJyPZr5gy9V6s2XZrrifoelOGBowTV1WIZ/IKEetX2mUJ/ux7FrTNZX9CbOAcXDDJgFLwY1dBSZOF56kECuQCCJ2XNOBc9Afn5gJoPwvvITkRlCWIJc2SkigJCegBEQkkBG5l5S9fuEkSV/a5qTa8xmgolRFLoVOIhrbMr4oalfqR/Vfrz3cij48RtH4Bg "JavaScript (SpiderMonkey) – Try It Online"