Decode a 7-segment display
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
You probably all know the 7-segment display which can display among other things all digits from $0dots 9$:
Challenge
We only consider the segments $textttAdotstextttG$, your task is to decode a single digit given which segments are turned on.
This can be encoded as an 8-bit integer, here's a table of each digit with their binary representation and the corresponding little-endian and big-endian values:
$$
beginarrayc
textDigit & texttt.ABCDEFG & textLittle-endian && textBig-endian & \ hline
0 & texttt01111110 & 126 & texttt0x7E & 126 & texttt0x7E \
1 & texttt00110000 & 48 & texttt0x30 & 12 & texttt0x0C \
2 & texttt01101101 & 109 & texttt0x6D & 182 & texttt0xB6 \
3 & texttt01111001 & 121 & texttt0x79 & 158 & texttt0x9E \
4 & texttt00110011 & 51 & texttt0x33 & 204 & texttt0xCC \
5 & texttt01011011 & 91 & texttt0x5B & 218 & texttt0xDA \
6 & texttt01011111 & 95 & texttt0x5F & 250 & texttt0xFA \
7 & texttt01110000 & 112 & texttt0x70 & 14 & texttt0x0E \
8 & texttt01111111 & 127 & texttt0x7F & 254 & texttt0xFE \
9 & texttt01111011 & 123 & texttt0x7B & 222 & texttt0xDE
endarray
$$
Rules & I/O
- Input will be one of
- single integer (like in the table above)
- a list/array/.. of bits
- a string consisting of characters
ABCDEFG
(you may assume it's sorted, as an exampleABC
encodes $7$), their case is your choice (not mixed-case)
- Output will be the digit it encodes
- You may assume no invalid inputs (invalid means that there is no corresponding digit)
Tests
Since this challenge allows multiple representations, please refer to the table.
code-golf kolmogorov-complexity decode
add a comment |Â
up vote
3
down vote
favorite
You probably all know the 7-segment display which can display among other things all digits from $0dots 9$:
Challenge
We only consider the segments $textttAdotstextttG$, your task is to decode a single digit given which segments are turned on.
This can be encoded as an 8-bit integer, here's a table of each digit with their binary representation and the corresponding little-endian and big-endian values:
$$
beginarrayc
textDigit & texttt.ABCDEFG & textLittle-endian && textBig-endian & \ hline
0 & texttt01111110 & 126 & texttt0x7E & 126 & texttt0x7E \
1 & texttt00110000 & 48 & texttt0x30 & 12 & texttt0x0C \
2 & texttt01101101 & 109 & texttt0x6D & 182 & texttt0xB6 \
3 & texttt01111001 & 121 & texttt0x79 & 158 & texttt0x9E \
4 & texttt00110011 & 51 & texttt0x33 & 204 & texttt0xCC \
5 & texttt01011011 & 91 & texttt0x5B & 218 & texttt0xDA \
6 & texttt01011111 & 95 & texttt0x5F & 250 & texttt0xFA \
7 & texttt01110000 & 112 & texttt0x70 & 14 & texttt0x0E \
8 & texttt01111111 & 127 & texttt0x7F & 254 & texttt0xFE \
9 & texttt01111011 & 123 & texttt0x7B & 222 & texttt0xDE
endarray
$$
Rules & I/O
- Input will be one of
- single integer (like in the table above)
- a list/array/.. of bits
- a string consisting of characters
ABCDEFG
(you may assume it's sorted, as an exampleABC
encodes $7$), their case is your choice (not mixed-case)
- Output will be the digit it encodes
- You may assume no invalid inputs (invalid means that there is no corresponding digit)
Tests
Since this challenge allows multiple representations, please refer to the table.
code-golf kolmogorov-complexity decode
Related.
– BMO
1 hour ago
Can we accept an integer (or array) in any specified bit-order or just the two shown?
– Jonathan Allan
50 mins ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
You probably all know the 7-segment display which can display among other things all digits from $0dots 9$:
Challenge
We only consider the segments $textttAdotstextttG$, your task is to decode a single digit given which segments are turned on.
This can be encoded as an 8-bit integer, here's a table of each digit with their binary representation and the corresponding little-endian and big-endian values:
$$
beginarrayc
textDigit & texttt.ABCDEFG & textLittle-endian && textBig-endian & \ hline
0 & texttt01111110 & 126 & texttt0x7E & 126 & texttt0x7E \
1 & texttt00110000 & 48 & texttt0x30 & 12 & texttt0x0C \
2 & texttt01101101 & 109 & texttt0x6D & 182 & texttt0xB6 \
3 & texttt01111001 & 121 & texttt0x79 & 158 & texttt0x9E \
4 & texttt00110011 & 51 & texttt0x33 & 204 & texttt0xCC \
5 & texttt01011011 & 91 & texttt0x5B & 218 & texttt0xDA \
6 & texttt01011111 & 95 & texttt0x5F & 250 & texttt0xFA \
7 & texttt01110000 & 112 & texttt0x70 & 14 & texttt0x0E \
8 & texttt01111111 & 127 & texttt0x7F & 254 & texttt0xFE \
9 & texttt01111011 & 123 & texttt0x7B & 222 & texttt0xDE
endarray
$$
Rules & I/O
- Input will be one of
- single integer (like in the table above)
- a list/array/.. of bits
- a string consisting of characters
ABCDEFG
(you may assume it's sorted, as an exampleABC
encodes $7$), their case is your choice (not mixed-case)
- Output will be the digit it encodes
- You may assume no invalid inputs (invalid means that there is no corresponding digit)
Tests
Since this challenge allows multiple representations, please refer to the table.
code-golf kolmogorov-complexity decode
You probably all know the 7-segment display which can display among other things all digits from $0dots 9$:
Challenge
We only consider the segments $textttAdotstextttG$, your task is to decode a single digit given which segments are turned on.
This can be encoded as an 8-bit integer, here's a table of each digit with their binary representation and the corresponding little-endian and big-endian values:
$$
beginarrayc
textDigit & texttt.ABCDEFG & textLittle-endian && textBig-endian & \ hline
0 & texttt01111110 & 126 & texttt0x7E & 126 & texttt0x7E \
1 & texttt00110000 & 48 & texttt0x30 & 12 & texttt0x0C \
2 & texttt01101101 & 109 & texttt0x6D & 182 & texttt0xB6 \
3 & texttt01111001 & 121 & texttt0x79 & 158 & texttt0x9E \
4 & texttt00110011 & 51 & texttt0x33 & 204 & texttt0xCC \
5 & texttt01011011 & 91 & texttt0x5B & 218 & texttt0xDA \
6 & texttt01011111 & 95 & texttt0x5F & 250 & texttt0xFA \
7 & texttt01110000 & 112 & texttt0x70 & 14 & texttt0x0E \
8 & texttt01111111 & 127 & texttt0x7F & 254 & texttt0xFE \
9 & texttt01111011 & 123 & texttt0x7B & 222 & texttt0xDE
endarray
$$
Rules & I/O
- Input will be one of
- single integer (like in the table above)
- a list/array/.. of bits
- a string consisting of characters
ABCDEFG
(you may assume it's sorted, as an exampleABC
encodes $7$), their case is your choice (not mixed-case)
- Output will be the digit it encodes
- You may assume no invalid inputs (invalid means that there is no corresponding digit)
Tests
Since this challenge allows multiple representations, please refer to the table.
code-golf kolmogorov-complexity decode
code-golf kolmogorov-complexity decode
asked 1 hour ago


BMO
10.2k21775
10.2k21775
Related.
– BMO
1 hour ago
Can we accept an integer (or array) in any specified bit-order or just the two shown?
– Jonathan Allan
50 mins ago
add a comment |Â
Related.
– BMO
1 hour ago
Can we accept an integer (or array) in any specified bit-order or just the two shown?
– Jonathan Allan
50 mins ago
Related.
– BMO
1 hour ago
Related.
– BMO
1 hour ago
Can we accept an integer (or array) in any specified bit-order or just the two shown?
– Jonathan Allan
50 mins ago
Can we accept an integer (or array) in any specified bit-order or just the two shown?
– Jonathan Allan
50 mins ago
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
1
down vote
Wolfram Language (Mathematica), 41 bytes
9[,6,0,8,2,3,1,7,5,4][[#~Mod~41~Mod~11]]&
Try it online!
Uses the little-endian column of integers as input. Ignore the syntax warning.
add a comment |Â
up vote
1
down vote
Java (JDK), 69 bytes
java.util.Arrays.asList(126,48,109,121,51,91,95,112,127,123)::indexOf
Try it online!
add a comment |Â
up vote
1
down vote
Jelly, 12 bytes
“0my3[_p¶{‘i
Accepts a little-endian integer.
Try it online!
This is the naive implementation, there might be a way to get a terser code.
add a comment |Â
up vote
0
down vote
05AB1E, 17 16 bytes
•βpm1Gî±ØÃ•žyòsk
Try it online or verify all test cases.
16-bytes alternative:
•otP¸HÄÞƒ•žyòsk>
Try it online or verify all test cases.
Will try to golf it down from here.
-1 byte thanks to @ErikTheOutgolfer.
Explanation:
•βpm1Gî±ØÃ•žyò # Compressed list [126,48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (and output implicitly)
•otP¸HÄÞƒ•žyò # Compressed list [48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (-1 if not found)
> # Increase it by 1 (and output implicitly)
See this 05AB1E tip of mine (section How to compress integer lists?) to understand why •βpm1Gî±ØÃ•128ò
is [126,48,109,121,51,91,95,112,127,123]
and •otP¸HÄÞƒ•128ò
is [48,109,121,51,91,95,112,127,123]
.
1
16 bytes.
– Erik the Outgolfer
26 mins ago
@EriktheOutgolfer Ah, of course.. Coincidentally it's128ò
. Forgot there is a builtin for128
being halve256
. Thanks!
– Kevin Cruijssen
23 mins ago
add a comment |Â
up vote
0
down vote
Japt, 16 bytes
Takes the big-endian value as input.
"~¶ÌÚúþÞ"b¥Ud
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=In4Mtp7M2voO/t4iYqVVZA==&input=MjU0(
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Wolfram Language (Mathematica), 41 bytes
9[,6,0,8,2,3,1,7,5,4][[#~Mod~41~Mod~11]]&
Try it online!
Uses the little-endian column of integers as input. Ignore the syntax warning.
add a comment |Â
up vote
1
down vote
Wolfram Language (Mathematica), 41 bytes
9[,6,0,8,2,3,1,7,5,4][[#~Mod~41~Mod~11]]&
Try it online!
Uses the little-endian column of integers as input. Ignore the syntax warning.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Wolfram Language (Mathematica), 41 bytes
9[,6,0,8,2,3,1,7,5,4][[#~Mod~41~Mod~11]]&
Try it online!
Uses the little-endian column of integers as input. Ignore the syntax warning.
Wolfram Language (Mathematica), 41 bytes
9[,6,0,8,2,3,1,7,5,4][[#~Mod~41~Mod~11]]&
Try it online!
Uses the little-endian column of integers as input. Ignore the syntax warning.
answered 41 mins ago
Misha Lavrov
3,437320
3,437320
add a comment |Â
add a comment |Â
up vote
1
down vote
Java (JDK), 69 bytes
java.util.Arrays.asList(126,48,109,121,51,91,95,112,127,123)::indexOf
Try it online!
add a comment |Â
up vote
1
down vote
Java (JDK), 69 bytes
java.util.Arrays.asList(126,48,109,121,51,91,95,112,127,123)::indexOf
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Java (JDK), 69 bytes
java.util.Arrays.asList(126,48,109,121,51,91,95,112,127,123)::indexOf
Try it online!
Java (JDK), 69 bytes
java.util.Arrays.asList(126,48,109,121,51,91,95,112,127,123)::indexOf
Try it online!
answered 23 mins ago


Olivier Grégoire
7,97111841
7,97111841
add a comment |Â
add a comment |Â
up vote
1
down vote
Jelly, 12 bytes
“0my3[_p¶{‘i
Accepts a little-endian integer.
Try it online!
This is the naive implementation, there might be a way to get a terser code.
add a comment |Â
up vote
1
down vote
Jelly, 12 bytes
“0my3[_p¶{‘i
Accepts a little-endian integer.
Try it online!
This is the naive implementation, there might be a way to get a terser code.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Jelly, 12 bytes
“0my3[_p¶{‘i
Accepts a little-endian integer.
Try it online!
This is the naive implementation, there might be a way to get a terser code.
Jelly, 12 bytes
“0my3[_p¶{‘i
Accepts a little-endian integer.
Try it online!
This is the naive implementation, there might be a way to get a terser code.
edited 21 mins ago
answered 48 mins ago


Jonathan Allan
49.2k534161
49.2k534161
add a comment |Â
add a comment |Â
up vote
0
down vote
05AB1E, 17 16 bytes
•βpm1Gî±ØÃ•žyòsk
Try it online or verify all test cases.
16-bytes alternative:
•otP¸HÄÞƒ•žyòsk>
Try it online or verify all test cases.
Will try to golf it down from here.
-1 byte thanks to @ErikTheOutgolfer.
Explanation:
•βpm1Gî±ØÃ•žyò # Compressed list [126,48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (and output implicitly)
•otP¸HÄÞƒ•žyò # Compressed list [48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (-1 if not found)
> # Increase it by 1 (and output implicitly)
See this 05AB1E tip of mine (section How to compress integer lists?) to understand why •βpm1Gî±ØÃ•128ò
is [126,48,109,121,51,91,95,112,127,123]
and •otP¸HÄÞƒ•128ò
is [48,109,121,51,91,95,112,127,123]
.
1
16 bytes.
– Erik the Outgolfer
26 mins ago
@EriktheOutgolfer Ah, of course.. Coincidentally it's128ò
. Forgot there is a builtin for128
being halve256
. Thanks!
– Kevin Cruijssen
23 mins ago
add a comment |Â
up vote
0
down vote
05AB1E, 17 16 bytes
•βpm1Gî±ØÃ•žyòsk
Try it online or verify all test cases.
16-bytes alternative:
•otP¸HÄÞƒ•žyòsk>
Try it online or verify all test cases.
Will try to golf it down from here.
-1 byte thanks to @ErikTheOutgolfer.
Explanation:
•βpm1Gî±ØÃ•žyò # Compressed list [126,48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (and output implicitly)
•otP¸HÄÞƒ•žyò # Compressed list [48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (-1 if not found)
> # Increase it by 1 (and output implicitly)
See this 05AB1E tip of mine (section How to compress integer lists?) to understand why •βpm1Gî±ØÃ•128ò
is [126,48,109,121,51,91,95,112,127,123]
and •otP¸HÄÞƒ•128ò
is [48,109,121,51,91,95,112,127,123]
.
1
16 bytes.
– Erik the Outgolfer
26 mins ago
@EriktheOutgolfer Ah, of course.. Coincidentally it's128ò
. Forgot there is a builtin for128
being halve256
. Thanks!
– Kevin Cruijssen
23 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
05AB1E, 17 16 bytes
•βpm1Gî±ØÃ•žyòsk
Try it online or verify all test cases.
16-bytes alternative:
•otP¸HÄÞƒ•žyòsk>
Try it online or verify all test cases.
Will try to golf it down from here.
-1 byte thanks to @ErikTheOutgolfer.
Explanation:
•βpm1Gî±ØÃ•žyò # Compressed list [126,48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (and output implicitly)
•otP¸HÄÞƒ•žyò # Compressed list [48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (-1 if not found)
> # Increase it by 1 (and output implicitly)
See this 05AB1E tip of mine (section How to compress integer lists?) to understand why •βpm1Gî±ØÃ•128ò
is [126,48,109,121,51,91,95,112,127,123]
and •otP¸HÄÞƒ•128ò
is [48,109,121,51,91,95,112,127,123]
.
05AB1E, 17 16 bytes
•βpm1Gî±ØÃ•žyòsk
Try it online or verify all test cases.
16-bytes alternative:
•otP¸HÄÞƒ•žyòsk>
Try it online or verify all test cases.
Will try to golf it down from here.
-1 byte thanks to @ErikTheOutgolfer.
Explanation:
•βpm1Gî±ØÃ•žyò # Compressed list [126,48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (and output implicitly)
•otP¸HÄÞƒ•žyò # Compressed list [48,109,121,51,91,95,112,127,123]
sk # Get the index of the input in this list (-1 if not found)
> # Increase it by 1 (and output implicitly)
See this 05AB1E tip of mine (section How to compress integer lists?) to understand why •βpm1Gî±ØÃ•128ò
is [126,48,109,121,51,91,95,112,127,123]
and •otP¸HÄÞƒ•128ò
is [48,109,121,51,91,95,112,127,123]
.
edited 17 mins ago
answered 27 mins ago


Kevin Cruijssen
32k554173
32k554173
1
16 bytes.
– Erik the Outgolfer
26 mins ago
@EriktheOutgolfer Ah, of course.. Coincidentally it's128ò
. Forgot there is a builtin for128
being halve256
. Thanks!
– Kevin Cruijssen
23 mins ago
add a comment |Â
1
16 bytes.
– Erik the Outgolfer
26 mins ago
@EriktheOutgolfer Ah, of course.. Coincidentally it's128ò
. Forgot there is a builtin for128
being halve256
. Thanks!
– Kevin Cruijssen
23 mins ago
1
1
16 bytes.
– Erik the Outgolfer
26 mins ago
16 bytes.
– Erik the Outgolfer
26 mins ago
@EriktheOutgolfer Ah, of course.. Coincidentally it's
128ò
. Forgot there is a builtin for 128
being halve 256
. Thanks!– Kevin Cruijssen
23 mins ago
@EriktheOutgolfer Ah, of course.. Coincidentally it's
128ò
. Forgot there is a builtin for 128
being halve 256
. Thanks!– Kevin Cruijssen
23 mins ago
add a comment |Â
up vote
0
down vote
Japt, 16 bytes
Takes the big-endian value as input.
"~¶ÌÚúþÞ"b¥Ud
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=In4Mtp7M2voO/t4iYqVVZA==&input=MjU0(
add a comment |Â
up vote
0
down vote
Japt, 16 bytes
Takes the big-endian value as input.
"~¶ÌÚúþÞ"b¥Ud
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=In4Mtp7M2voO/t4iYqVVZA==&input=MjU0(
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Japt, 16 bytes
Takes the big-endian value as input.
"~¶ÌÚúþÞ"b¥Ud
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=In4Mtp7M2voO/t4iYqVVZA==&input=MjU0(
Japt, 16 bytes
Takes the big-endian value as input.
"~¶ÌÚúþÞ"b¥Ud
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=In4Mtp7M2voO/t4iYqVVZA==&input=MjU0(
answered 13 mins ago


Shaggy
17.3k21662
17.3k21662
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174416%2fdecode-a-7-segment-display%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Related.
– BMO
1 hour ago
Can we accept an integer (or array) in any specified bit-order or just the two shown?
– Jonathan Allan
50 mins ago