Post History
C, 59 byte h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;} Old version, 60 byte: h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&...
Answer
#6: Post edited
- ## C, 59 byte
```- h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- ### Old version, 60 byte:
```- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
- A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'M'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`. This has the nice side effect that it works work lower and upper case letters, since it ignores all bits >3.
- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
- ## C, 59 byte
- ```c
- h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- ### Old version, 60 byte:
- ```c
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
- A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'M'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`. This has the nice side effect that it works work lower and upper case letters, since it ignores all bits >3.
- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
#5: Post edited
- ## C, 59 byte
- ```
- h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- ### Old version, 60 byte:
- ```
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'M'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`.- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
- ## C, 59 byte
- ```
- h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- ### Old version, 60 byte:
- ```
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
- A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'M'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`. This has the nice side effect that it works work lower and upper case letters, since it ignores all bits >3.
- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
#4: Post edited
- ## C, 59 byte
- ```
- h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- ### Old version, 60 byte:
- ```
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'N'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`.- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
- ## C, 59 byte
- ```
- h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- ### Old version, 60 byte:
- ```
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
- A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'M'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`.
- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
#3: Post edited
## C, 60 byte- ```
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
- A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'N'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`.
- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
- ## C, 59 byte
- ```
- h(n){return n&4?n&2?5:n&1?1e3:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- ### Old version, 60 byte:
- ```
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
- A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'N'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`.
- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
#2: Post edited
- ## C, 60 byte
- ```
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
Not very creative, there is probably a smaller version.- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'N'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`.
- ## C, 60 byte
- ```
- h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;}
- ```
- Not very creative, there is probably a smaller version. Takes a ASCII character as argument and returns the value.
- `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`.
- A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'N'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`.
- Tried a version for EBCDIC-Encoding but that is longer (because some characters only differ at bit 4, which requires a `n&16`, which is 1 byte longer).
#1: Initial revision
## C, 60 byte ``` h(n){return n&4?n&2?5:n&1?1000:n&8?50:500:n&2?100:n&1?1:10;} ``` Not very creative, there is probably a smaller version. `n&4` separates `'V'`/`5`, `'L'`/`50`, `'D'`/`500` and `'M'`/`1000`, which have bit 2 set and end up in this part: `n&2?5:n&1?1000:n&8?50:500`, and `'I'`/`1`, `'X'`/`10`, `'C'`/`100` , which have bit 2 cleared and end up in this part: `n&2?100:n&1?1:10`. A similar thing is done after that, of `'V', 'L', 'D', 'M'`, only `'V'` has bit 1 set, so if `n&2` is true, the value is 5. If not, we check bit 0 with `n&1` for `'N'` or 1000, bit 3 for `'L'` or `50` and if it is none of them it must be `'D'` or `500`. A similar thing is done for the numbers `100`, `1` and `10`.