Activity for Karl Knechtelâ€
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Comment | Post #292376 |
I'm not sure what you mean by "keywords, function names, *constants* or identifiers provided by the language's standard/default libraries" - since the value of the constant wouldn't be part of the source code, but rather its name. Do you intend to allow letters that form part of the syntax for a cons... (more) |
— | 3 months ago |
Comment | Post #292356 |
I noticed and have updated. (more) |
— | 3 months ago |
Comment | Post #292362 |
Same length and perhaps easier to understand: `a=>a.reduce((s,a)=>s+a%2)` (more) |
— | 3 months ago |
Edit | Post #292356 |
Post edited: Update because I didn't notice the friendly input specification |
— | 3 months ago |
Edit | Post #292356 |
Post edited: Bitwise-complementing the mask is wrong; rather the input value would be bitwise-complemented in that hypothetical. |
— | 3 months ago |
Edit | Post #292356 | Initial revision | — | 3 months ago |
Answer | — |
A: How many odd digits? Python, 37 27 bytes First, with input as an integer: ``` lambda i:sum(ord(x)&1for x in str(i)) ``` This converts the number to string (in the base-10 default) and processes each character. It exploits the fact that digit symbols `0`..`9` are consecutive in Unicode and `0` corresponds to an e... (more) |
— | 3 months ago |
Edit | Post #289604 | Initial revision | — | about 1 year ago |
Answer | — |
A: Knight safe squares Python, 143 bytes ```python def r(i): y,z=65537,1+(1>10|(i&254s)z>>17|(i&127s)z>>15|(i&63s)y>>6)&(1<<64)-1 return 64-n.bitcount() ``` This is a port of trichoplax's Rust answer, written with relatively little comprehension. Because Python's integers are arbitrary sized, they cannot implic... (more) |
— | about 1 year ago |
Comment | Post #286282 |
This approach also works in 3.x, if parentheses are added to the `print` usage - of course, this only ties the result from the simpler-to-understand approach, while that approach would waste a byte here (due to the need to separate `_` from `print`). (more) |
— | about 1 year ago |
Edit | Post #289601 | Initial revision | — | about 1 year ago |
Answer | — |
A: Reverse the bits in a Byte Python (3.6 and up), 32 bytes (unsigned integer I/O) ``` lambda x:int(f'{x:08b}'[::-1],2) ``` Input and output are `int` objects. This also reverses the bits in integers larger than 255, implicitly inferring their bit length from the number of bits needed to write them (even if that isn't a m... (more) |
— | about 1 year ago |