16
Inspired by this question which was further inspired by this one, write a program which takes two integers and adds them in a unique way, by performing an OR operation on the segments used to display them in a 7-segment display. For reference, the digits are represented in the following way:
_ _ _ _ _ _ _ _
| | | _| _| |_| |_ |_ | |_| |_|
|_| | |_ _| | _| |_| | |_| _|
Note that the 1 uses the two segments on the right, not the left. There are two special characters that can be produced this way which are not numbers. See the addition table below:
| 0 1 2 3 4 5 6 7 8 9
--+--------------------
0 | 0 0 8 8 8 8 8 0 8 8
1 | 0 1 a 3 4 9 8 7 8 9
2 | 8 a 2 a 8 8 8 a 8 8
3 | 8 3 a 3 9 9 8 3 8 9
4 | 8 4 8 9 4 9 8 Q 8 9
5 | 8 9 8 9 9 5 6 9 8 9
6 | 8 8 8 8 8 6 6 8 8 8
7 | 0 7 a 3 Q 9 8 7 8 9
8 | 8 8 8 8 8 8 8 8 8 8
9 | 8 9 8 9 9 9 8 9 8 9
Useful observations:
- Any digit plus itself equals itself
- 8 plus any digit equals 8
- 2 plus 1, 3, or 7 equals the letter 'a' (must be lower-case)
- 4 plus 7 equals either 'q' or 'Q', your choice
- Numbers should be right-aligned, so the digits should be added from right to left. If one number has more digits than the other, the extra digits at the beginning should be unchanged. There are no leading 0's, unless the number is exactly 0.
- All numbers will be 0 or greater. You don't need to handle a '-' sign. (Mainly because there's no good fit for the sum of a '-' and a '1' or '7'.)
Your program should accept 2 integers in any format you choose, and output a string containing their "sum" when calculated in this manner. This is code-golf, so your program should be as small as possible.
Examples:
- Input: 12345, 123. Output: 12389
- Input: 88888, 42. Output: 88888
- Input: 0, 23. Output: 28
- Input: 120, 240. Output: a80
- Input: 270, 42. Output: 2Q8 (or 2q8)
- Input: 1234567890, 1234567890. Output: 1234567890
4Interesting challenge, but this could use some test cases so people can validate their answers. – AdmBorkBork – 2016-05-26T15:59:11.943
3Shouldn't the
Q
be lowercase? The actual shape looks like aq
rather than aQ
– Luis Mendo – 2016-05-26T16:01:36.467Will the input integers be single-digit, limited number of digits or unlimited? – Digital Trauma – 2016-05-26T16:27:43.650
@DigitalTrauma - Numbers can be any number of digits (within reason, depending on the limitations of your chosen language). For simplicity, the numbers should be right-aligned, just as in normal addition. (So unlike the linked puzzle where 22+4=82, in this challenge it would be 28.) – Darrel Hoffman – 2016-05-26T16:48:17.670
1@LuisMendo - I suppose it could go either way. I'll leave that up to your discretion. The
a
should definitely be lower case though, sinceA
looks completely different. – Darrel Hoffman – 2016-05-26T16:49:48.493-
plus1
equals⊣
and-
plus7
equalsᖷ
! – Adám – 2016-05-26T19:59:31.487@Zgarb - Done. Also added a test that adds a value to itself (which should simply return the same number unchanged). – Darrel Hoffman – 2016-05-26T21:07:34.927
2@Adám - Yeah, I thought about that, but figured not everybody has access to Unicode characters in their golfing languages of choice, so it'd be unfair to expect them to handle that. – Darrel Hoffman – 2016-05-26T21:09:01.120
Can input be an array of arrays of digits? Something like
{[1 2 3 4 5] [1 2 3]}
for the first test case – Luis Mendo – 2016-05-27T00:54:18.087@LuisMendo - I don't know - what's the usual practice on this sort of thing? I did say "any format you choose", but that might be stretching it a bit? I'll let the community decide whether that's fair or not. – Darrel Hoffman – 2016-05-27T13:22:54.090
@DarrelHoffman Yes, I agree it might be stretching – Luis Mendo – 2016-05-27T13:46:55.197