Post History
Python 3, 60 59 bytes D=input();m=int(max(D),16);print(m and int(D,m+1)or len(D)) Quite straight forward implementation. Input string is assigned to D. m is the the max() letter in D conver...
Answer
#3: Post edited
# Python 3, 59 bytes- ```python
- D=input();m=int(max(D),16);print(m and int(D,m+1)or len(D))
- ```
- Quite straight forward implementation.
- * Input string is assigned to `D`.
- * `m` is the the `max()` letter in `D` converted to `int()` with base 16. `max()` works because Python strings/characters are compared as Unicode codepoints and the letters "A"-"F" or "a"-"f" have a higher value than the characters for the decimal digits "0"-"9".
- * Depending on `m` being…
- * …not zero/”truthy”: print the input parsed as integer with base `m+1`.
- * …zero/”falsy”: print the length of the input.
- The last part uses the fact that `and` and `or` evaluate to the first or the second operand instead of boolean values in Python. There's one pitfall with this trick: it doesn't work if the second argument to `and` can be ”falsy” if the first is ”truthy”, but this can't happen here because there is no possible input that is a) not unary and b) zero at the same time, because to be non-unary under the given assignment there must be at least one non-zero digit in it, and then it can't have the value 0 any more.
- # Python 3, ~~60~~ 59 bytes
- ```python
- D=input();m=int(max(D),16);print(m and int(D,m+1)or len(D))
- ```
- Quite straight forward implementation.
- * Input string is assigned to `D`.
- * `m` is the the `max()` letter in `D` converted to `int()` with base 16. `max()` works because Python strings/characters are compared as Unicode codepoints and the letters "A"-"F" or "a"-"f" have a higher value than the characters for the decimal digits "0"-"9".
- * Depending on `m` being…
- * …not zero/”truthy”: print the input parsed as integer with base `m+1`.
- * …zero/”falsy”: print the length of the input.
- The last part uses the fact that `and` and `or` evaluate to the first or the second operand instead of boolean values in Python. There's one pitfall with this trick: it doesn't work if the second argument to `and` can be ”falsy” if the first is ”truthy”, but this can't happen here because there is no possible input that is a) not unary and b) zero at the same time, because to be non-unary under the given assignment there must be at least one non-zero digit in it, and then it can't have the value 0 any more.
#2: Post edited
# Python 3, 60 bytes- ```python
D=input();m=int(max(D),16);print(int(D,m+1)if m else len(D))- ```
- Quite straight forward implementation.
- * Input string is assigned to `D`.
- * `m` is the the `max()` letter in `D` converted to `int()` with base 16. `max()` works because Python strings/characters are compared as Unicode codepoints and the letters "A"-"F" or "a"-"f" have a higher value than the characters for the decimal digits "0"-"9".
- * Depending on `m` being…
* …not zero: print the input parsed as integer with base `m+1`.* …zero: print the length of the input.
- # Python 3, 59 bytes
- ```python
- D=input();m=int(max(D),16);print(m and int(D,m+1)or len(D))
- ```
- Quite straight forward implementation.
- * Input string is assigned to `D`.
- * `m` is the the `max()` letter in `D` converted to `int()` with base 16. `max()` works because Python strings/characters are compared as Unicode codepoints and the letters "A"-"F" or "a"-"f" have a higher value than the characters for the decimal digits "0"-"9".
- * Depending on `m` being…
- * …not zero/”truthy”: print the input parsed as integer with base `m+1`.
- * …zero/”falsy”: print the length of the input.
- The last part uses the fact that `and` and `or` evaluate to the first or the second operand instead of boolean values in Python. There's one pitfall with this trick: it doesn't work if the second argument to `and` can be ”falsy” if the first is ”truthy”, but this can't happen here because there is no possible input that is a) not unary and b) zero at the same time, because to be non-unary under the given assignment there must be at least one non-zero digit in it, and then it can't have the value 0 any more.
#1: Initial revision
# Python 3, 60 bytes ```python D=input();m=int(max(D),16);print(int(D,m+1)if m else len(D)) ``` Quite straight forward implementation. * Input string is assigned to `D`. * `m` is the the `max()` letter in `D` converted to `int()` with base 16. `max()` works because Python strings/characters are compared as Unicode codepoints and the letters "A"-"F" or "a"-"f" have a higher value than the characters for the decimal digits "0"-"9". * Depending on `m` being… * …not zero: print the input parsed as integer with base `m+1`. * …zero: print the length of the input.