| Bytes | Lang | Time | Link |
|---|---|---|---|
| 012 | Pip | 211213T171331Z | DLosc |
| 097 | AWK | 241107T172426Z | xrs |
| 013 | UiuaSBCS | 241022T073208Z | Europe20 |
| 071 | Julia 1.0 | 230224T194105Z | Ashlin H |
| 053 | Python | 230225T140741Z | The Thon |
| nan | 230225T140325Z | The Thon | |
| 010 | Pyt | 230225T134814Z | Kip the |
| nan | Fig | 220910T014821Z | Seggan |
| 612 | Nibbles | 220907T105810Z | Dominic |
| 007 | Vyxal | 211213T184817Z | emanresu |
| 040 | Prolog SWI | 220906T203346Z | naffetS |
| 063 | Excel | 211214T162414Z | Engineer |
| 008 | Raku | 211213T142957Z | ovs |
| 094 | Lua | 211219T065548Z | Visckmar |
| 027 | APOL | 211213T141117Z | Ginger |
| 050 | Python 3.8 prerelease | 211213T141238Z | rak1507 |
| 037 | Hexagony | 211215T042202Z | Joundill |
| 089 | Python 3 | 211213T135242Z | Fmbalbue |
| 060 | JavaScript | 211213T153712Z | Unmitiga |
| 013 | Factor | 211214T171425Z | chunes |
| 040 | Ruby | 211214T130724Z | G B |
| 051 | R | 211213T143016Z | Dominic |
| 099 | Turing Machine Code | 211214T103631Z | ouflak |
| 063 | Nim | 211214T102600Z | Adam |
| 015 | APL dzaima/APL | 211213T141735Z | Adá |
| 035 | PHP | 211214T094229Z | Kaddath |
| 063 | C gcc with funsignedchar | 211214T090759Z | ErikF |
| 009 | Husk | 211213T193824Z | Dominic |
| 008 | 05AB1E | 211213T154128Z | Kevin Cr |
| 043 | JavaScript ES6 | 211213T180322Z | Arnauld |
| 007 | Jelly | 211213T235814Z | lynn |
| 075 | Haskell | 211213T220746Z | Benji |
| 007 | Japt m | 211213T215400Z | Shaggy |
| 046 | C gcc | 211213T174035Z | Noodle9 |
| 067 | Java | 211213T172529Z | Unmitiga |
| 020 | JavaScript | 211213T164644Z | Shaggy |
| 019 | Retina 0.8.2 | 211213T144619Z | Neil |
| 002 | Charcoal | 211213T143906Z | Neil |
| 053 | Python 3 | 211213T140801Z | Alan Bag |
| 062 | Python 3 | 211213T135532Z | Ginger |
Pip, 9 12 bytes
+3 bytes to handle more stringent rules
+:A_%E#A_MJa
Explanation
After some trial and error, I found a really nice property of these numbers' codepoints:
- ¹, ², and ³ have codepoints 185, 178, and 179. Mod 8 (or 4), these become 1, 2, and 3.
- The other superscript numbers have codepoints equal to the corresponding digit plus 8304. Mod 16 (or 12, or many other options), these become their respective digits.
So all we need to do is take the codepoint of each digit mod 8 if it's 3 digits and mod 16 if it's 4 digits...
a First command-line argument
MJ Map this function to each character, joining the results together:
A_ Codepoint of the character
% Mod
E 2 to the power of
# Length of
A_ Codepoint of the character
+: Treat the resulting string as a number (removing leading 0s)
AWK, 97 bytes
{for(;i++<split("¹²³⁴⁵⁶⁷⁸⁹⁰",a);)b[a[i]]=i
for(;j++<NF;)s=s b[$j]%10;print s*1}
{for(;i++<split("¹²³⁴⁵⁶⁷⁸⁹⁰",a);)b[a[i]]=i # map
for(;j++<NF;)s=s b[$j]%10; # convert
print s*1} # implicit convert to int
# remove leading zeros
UiuaSBCS, 13 bytes
⋕+@0◿12◿92-@\0
Explanation
⋕+@0◿12◿92-@\0
-@\0 Unicode codepoints
◿92 modulo 92
◿12 modulo 12
+@0 convert numbers to digits
⋕ parse
Julia 1.0, 78 71 bytes
~x=parse(Int,join(Dict(["⁰¹²³"...;'⁴':'⁹'].=>0:9)[i] for i=x))
- -3 bytes thanks to MarcMush: use range directly, no need to vectorize with
[0:9;] - -4 bytes thanks to MarcMush: use array comprehension instead of an anonymous function, removing one occurrence of the splat operator
...
Python, 53 bytes
lambda s:int(''.join(str(x%12&x)for x in map(ord,s)))
Port of Lynn's Jelly answer. Not the best Python answer (by 3 bytes), but uses a different method to the others.
Thunno, \$ 11 \log_{256}(96) \approx \$ 9.05 bytes
OD12%z.A&ZD
Port of Lynn's Jelly answer.
Explanation
OD12%z.A&ZD # Implicit input
OD # Get ordinals and duplicate
12% # Mod 12 of each
z. # Zip and apply to each pair:
A& # Bitwise AND
ZD # Convert to integer
# Implicit output
Pyt, 10 bytes
ą2Ĩ4+1ᴇ%ǰƖ
ą implicit input; convert to ąrray of characters
2Ĩ due to oversight in implementing arbitrary-base integer
Ĩnterpretation, this returns the position for each character
in the list of potential base characters (which is a contiguous
stretch)
4+ add 4 to each
1ᴇ% modulo 10
ǰ ǰoin without delimiters
Ɩ cast to Ɩnteger; implicit print
Fig, \$9\log_{256}(96)\approx\$ 7.408 bytes
_O%12%92C
_O%12%92C
C # Convert to charcodes
%92 # Mod 92
%12 # Mod 12
O # Join the list of digits
_ # Cast to number to get rid of leading 0s
Nibbles, 6.5 6 bytes (12 nibbles)
`@~.$`&%$12
A port of Lynn's Jelly answer comes out half-a-byte a byte shorter in Nibbles.
. # Map over
$ # the input string:
`& # bitwise-and of
$ # each element
% # modulo
12 # twelve
# and itself
`@~ # Finally, convert from base-10 digits
Excel, 72 63 bytes
Saved 9 bytes thanks to JvdV
=--CONCAT(MOD(MOD(UNICODE(MID(A1,SEQUENCE(LEN(A1)),1)),92),12))
Not very exciting, really. It's the Excel version of Arnauld's answer.
MID(A1,SEQUENCE(LEN(A1)),1)pulls each character from the input one at a time.MOD(MOD(UNICODE(MID(~)),92),12))converts that character to unicode and then takes the mod 92 and mod 12.--CONCAT(MOD(~))combines all those code values into a string and then coerces that string into a number by making it negative twice (so back to positive again) which also will drop any leading zeros.
Raku, 14 10 11 8 bytes
+1 and +4 to remove leading 0's.
-3 bytes thanks to Moonchild!
+~*.NFKD
Raku -p, 15 19 bytes
-1 byte and -1 flag thanks to Jo King!
$_=+S:g{.}=$/.EVAL
Raku uses superscript digits as exponents, but single digits on their own evaluate to their numeric value.
Lua, 94 bytes
r=0 t={[185]=1,[178]=2,[179]=3}for _,c in utf8.codes(...)do r=r*10+(t[c]or c-8304)end print(r)
APOL, 46 27 bytes
I(j(ƒ(i %(%(↶(∋) 92) 12))))
Uses Arnauld's 92/12 solution.
Note: 3 bytes can be saved by removing the I instruction, however this version is not case 5-compliant.
Explanation
I( Cast to integer
j( Join string (default is no seperator)
ƒ( List-builder for loop (returns a list of every returned value of the passed instruction)
i Get input
%( Modulo 2 (12)
%( Modulo 1 (92)
↶( Get codepoint
∋ The current item in the for loop
)
92
)
12
)
)
)
)
Implicit print
Old code (uses lookup table instead):
v(0 []);f(i a(0 t(⌕("⁰¹²³⁴⁵⁶⁷⁸⁹" ∋))));I(j(⁰))
Python 3.8 (pre-release), 46 50 bytes
-1 thanks to ovs!
lambda x:int(x.translate('%7d 45678923'%10*999))
Helper program to generate this: helper
Hexagony, side length 4, 37 bytes
92},/%=\_@=..}{<.{\<.>".2//{%.1!}>'/_
Unwrapped code:
9 2 } ,
/ % = \ _
@ = . . } {
< . { \ < . >
" . 2 / / {
% . 1 ! }
> ' / _
This is my first post on Code Golf, and first time using Hexagony. It's as painful as the name implies, but so satisfying to get a result! I ended up with more mirrors than I expected, but I'm pretty proud of what I achieved.
Credit to the previous users who worked out the modulo trick. My hexagon would have been a lot bigger without %92%12!
Python 3, 89 bytes
lambda a:int(a.translate(dict(zip(map(ord,"⁰¹²³⁴⁵⁶⁷⁸⁹"),"0123456789"))))
-77 Bytes thanks to @grandBagel
-31 Bytes thanks to @ovs
JavaScript, 65 62 61 60 bytes
s=>s.replace(/./g,x=>-~'¹²³⁴⁵⁶⁷⁸⁹'.search(x))
Saved 3 bytes thanks to Neil.
Saved 1 byte thanks to Shaggy.
Saved 1 byte thanks to Arnauld.
R, 45 53 51 bytes
Edit +8 bytes to comply with the updated rules (0123 -> 123), but then -2 bytes thanks to pajonk
function(s)el(chartr("⁰¹²³⁴-⁹","0-9",s):1)
R, 53 51 57 bytes / 25 bytes with IO as character codes
Edit: -4 bytes thanks to pajonk, but then +6 bytes (again thanks to pajonk) to comply with the updated rules
function(s,x=utf8ToInt(s))el(intToUtf8(x%%64-8*!x-185):1)
Function without multi-byte character codes, but sadly the verbose utf8ToInt and intToUtf8 function names make it quite long if we want to accept input directly as a string...
The new rule that ⁰¹²³ should output 123 invalidates the second version with IO as character codes. It could be fixed for +17 bytes, but it's shorter to completely change approach (below), porting Arnauld's charcode-to-digit method.
R, 40 bytes with IO as character codes
function(c)c%%92%%12%*%10^rev(seq(!c)-1)
Turing Machine Code, 99 bytes
* ⁰ 0 r *
* ¹ 1 r *
* ² 2 r *
* ³ 3 r *
* ⁴ 4 r *
* ⁵ 5 r *
* ⁶ 6 r *
* ⁷ 7 r *
* ⁸ 8 r *
* ⁹ 9 r *
Nim, 63 bytes
import strutils,unidecode
stdin.readAll.unidecode.parseInt.echo
If removing leading zeros is not required:
Nim, 45 bytes
import unidecode
stdin.readAll.unidecode.echo
APL (dzaima/APL), 16 15 bytes
−1 byte thanks to rak1509
Anonymous tacit prefix function. Requires 0-based indexing.
10⊥'⁰¹²³⁴⁵⁶⁷⁸'⍳
10⊥ evaluate in base 10
'⁰¹²³⁴⁵⁶⁷⁸'⍳ the respective indices of the argument characters in this string (any character not in the string gets the first index beyond the end, i.e. 9)
C (gcc) with -funsigned-char, 63 bytes
This version takes a string of UTF-8 characters. If the leading byte is E2 then I mask the third byte with 15; otherwise I mask the second byte with 3. It's useful that B9 (the trailing byte of ¹) is odd!
i;f(char*s){for(i=0;*s;s++)i=(*s++-226?*s&3:*++s&15)+i*10;i=i;}
Husk, 10 9 bytes
dm(Sn%12c
Port of Arnauld's Javascript answer Lynn's Jelly answer.
The 'charcode-to-charcode' modulo-except-when-it's-185 approach is discouragingly long in Husk, but Lynn's 'charcode-to-digit' modulo-AND approach is very well-suited to Husk's d (digits to decimal number) function.
05AB1E, 11 8 bytes
Ç92%12%J
-3 bytes porting @Arnauld's JavaScript method (thanks @Neil for the heads up).
Add a trailing ï (+1 byte) if you want to remove leading 0s..
Try it online or verify all test cases.
Explanation:
Ç # Convert the (implicit) input to a list of its codepoint-integers
# e.g. "⁰¹²³⁴⁵⁶⁷⁸⁹" → [8304,185,178,179,8308,8309,8310,8311,8312,8313]
92% # Modulo-92
# → [24,1,86,87,28,29,30,31,32,33]
12% # Modulo-12
# → [0,1,2,3,4,5,6,7,8,9]
J # Join the list together
# → 0123456789
ï # (Optionally) Remove leading 0s by casting to an integer
# → 123456789
# (after which the result is output implicitly)
JavaScript (ES6), 43 bytes
Edit: +1 to support 0123 -> 123 ...
s=>+s.replace(/./g,c=>c.charCodeAt()%92%12)
Conversion table
char. | code | mod 92 | mod 12
-------+------+--------+--------
'⁰' | 8304 | 24 | 0
'¹' | 185 | 1 | 1
'²' | 178 | 86 | 2
'³' | 179 | 87 | 3
'⁴' | 8308 | 28 | 4
'⁵' | 8309 | 29 | 5
'⁶' | 8310 | 30 | 6
'⁷' | 8311 | 31 | 7
'⁸' | 8312 | 32 | 8
'⁹' | 8313 | 33 | 9
Jelly, 7 bytes
O%12&ƊḌ
O Get ordinal values
%12&Ɗ Apply x ↦ x%12&x
Ḍ Digits to number
I found the x%12&x formula by computer search. If I/O were super duper lenient, I guess %12& would be a valid 4-byte answer.
C (gcc), 83 \$\cdots\$ 60 46 bytes
n;f(int*s){for(n=0;*s;)n+=9*n+*s++%92%12;n=n;}
Inputs a pointer to a wchar_t string of superscript numbers.
Returns the normal number.
Discovered the n % 92 % 12 formula independently.
Retina 0.8.2, 19 bytes
T`⁰-⁹_¹²³`dd
Try it online! Link includes test cases. Explanation: d is a shorthand for 0123456789. As ⁰-⁹ expands to ⁰ⁱ⁴⁵⁶⁷⁸⁹, and assuming none of ⁱ will appear in the input, those supserscript digits will get mapped to ASCII digits, while the _¹²³ gets mapped to 0123 (the remaining digits in d get ignored). _ is actually a placeholder on the LHS and does nothing except to skip 0 on the RHS (on the RHS it causes the character on the LHS to be deleted).
Charcoal, 2 bytes
IV
Try it online! Explanation:
V Eval as a Charcoal integer literal
I Cast to string
Implicitly print
Python 3, 63 62 bytes
lambda n: int("".join([str("⁰¹²³⁴⁵⁶⁷⁸⁹".index(c))for c in n]))
Thanks @Fmbalbuena!

