Simplification of numbersIs this n-speak?How strong are nonary numbers?Mixed Base Conversionxkcd-Style Page NumberingAddition in base -1+iWhat base is this number in?Pronounce numbersFind the longest run of consecutive digitsNumbers Increase While Letters DecreaseIntegers in Base PiPrint the Lost numbers
How can God warn people of the upcoming rapture without disrupting society?
Normalization constant of a planar wave
Boss wants me to ignore a software license
Generate Brainfuck for the numbers 1–255
These were just lying around
A torrent of foreign terms
A Non Math Puzzle. What is the middle number?
Super Duper Vdd stiffening required on 555 timer, what is the best way?
What should I call bands of armed men in the Middle Ages?
How can Radagast come across Gandalf and Thorin's company?
If a digital camera can be "hacked" in the ransomware sense, how best to protect it?
Annotating a table with arrows
Not going forward with internship interview process
Do beef farmed pastures net remove carbon emissions?
Is this n-speak?
Lengthened voiced stops and the airstream through the nose
Submitting a new paper just after another was accepted by the same journal
What gave Harry Potter the idea of writing in Tom Riddle's diary?
Loading military units into ships optimally, using backtracking
TEMPO: play a sound in animated GIF/PDF/SVG
Can a PC use the Levitate spell to avoid movement speed reduction from exhaustion?
Understanding the point of a kölsche Witz
What ability do tools use?
Why command hierarchy, if the chain of command is standing next to each other?
Simplification of numbers
Is this n-speak?How strong are nonary numbers?Mixed Base Conversionxkcd-Style Page NumberingAddition in base -1+iWhat base is this number in?Pronounce numbersFind the longest run of consecutive digitsNumbers Increase While Letters DecreaseIntegers in Base PiPrint the Lost numbers
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
How, you can’t remember the 6 or 7-digit phone number that appeared on the TV screen for a second?! Using the special technique described below, you will turn into a walking phonebook!
Obviously, the number 402
is easier to remember than the number 110010010
, and the number 337377
is easier to remember than the number 957472
.
This means that the memorized number, on the one hand, should contain as few digits as possible, and on the other hand, it is desirable that the number contains as many repeating numbers as possible.
As a criterion for the difficulty of remembering, we take the sum of the number of digits in number and the number of different digits in number. A memorized number can be written in another number system, perhaps then it will be easier to remember. For example, the number 65535
in the hexadecimal notation looks like FFFF
.
Task
You need to write a program for selecting the base of the number system to minimize the complexity criterion. The base of the number system must be selected in the range from 2 to 36, then the numbers 0-9
and the English letters A-Z
can be used to represent the number.
Input
The input contains a decimal integer from 1 to 999999999.
Output
The output must contain the base of the number system (from 2 to 36), minimizing the criterion of memorization complexity, and the number in the selected number system, separated by one space. If several bases give the same value for the criterion, then choose the smallest among them.
Notes
- The letters must be uppercase(
A-Z
).
Test Cases
Input Output
1
2 1
2
3 2
65535
16 FFFF
123
12 A3
code-golf number base-conversion
New contributor
$endgroup$
|
show 4 more comments
$begingroup$
How, you can’t remember the 6 or 7-digit phone number that appeared on the TV screen for a second?! Using the special technique described below, you will turn into a walking phonebook!
Obviously, the number 402
is easier to remember than the number 110010010
, and the number 337377
is easier to remember than the number 957472
.
This means that the memorized number, on the one hand, should contain as few digits as possible, and on the other hand, it is desirable that the number contains as many repeating numbers as possible.
As a criterion for the difficulty of remembering, we take the sum of the number of digits in number and the number of different digits in number. A memorized number can be written in another number system, perhaps then it will be easier to remember. For example, the number 65535
in the hexadecimal notation looks like FFFF
.
Task
You need to write a program for selecting the base of the number system to minimize the complexity criterion. The base of the number system must be selected in the range from 2 to 36, then the numbers 0-9
and the English letters A-Z
can be used to represent the number.
Input
The input contains a decimal integer from 1 to 999999999.
Output
The output must contain the base of the number system (from 2 to 36), minimizing the criterion of memorization complexity, and the number in the selected number system, separated by one space. If several bases give the same value for the criterion, then choose the smallest among them.
Notes
- The letters must be uppercase(
A-Z
).
Test Cases
Input Output
1
2 1
2
3 2
65535
16 FFFF
123
12 A3
code-golf number base-conversion
New contributor
$endgroup$
11
$begingroup$
Great challenge, but it needs more test cases.
$endgroup$
– Grimy
13 hours ago
6
$begingroup$
Also, the output format is a bit too strict, you might want to allow e.g. an array of two elements, the base and the string, or allowing them in reverse order or separated by another character. Also, I assume that you add the sum of the digits to the number of digits, but you may want to clarify that.
$endgroup$
– Erik the Outgolfer
13 hours ago
7
$begingroup$
Can I usea-z
instead ofA-Z
?
$endgroup$
– Neil
13 hours ago
3
$begingroup$
Can we just use the corresponding numbers instead ofA-Z
?
$endgroup$
– flawr
13 hours ago
5
$begingroup$
@VerNick Next time you write a similar challenge I would suggest allowing both these requests, as they are just an unnecessary complication which are discouraged: see e.g. here.
$endgroup$
– flawr
10 hours ago
|
show 4 more comments
$begingroup$
How, you can’t remember the 6 or 7-digit phone number that appeared on the TV screen for a second?! Using the special technique described below, you will turn into a walking phonebook!
Obviously, the number 402
is easier to remember than the number 110010010
, and the number 337377
is easier to remember than the number 957472
.
This means that the memorized number, on the one hand, should contain as few digits as possible, and on the other hand, it is desirable that the number contains as many repeating numbers as possible.
As a criterion for the difficulty of remembering, we take the sum of the number of digits in number and the number of different digits in number. A memorized number can be written in another number system, perhaps then it will be easier to remember. For example, the number 65535
in the hexadecimal notation looks like FFFF
.
Task
You need to write a program for selecting the base of the number system to minimize the complexity criterion. The base of the number system must be selected in the range from 2 to 36, then the numbers 0-9
and the English letters A-Z
can be used to represent the number.
Input
The input contains a decimal integer from 1 to 999999999.
Output
The output must contain the base of the number system (from 2 to 36), minimizing the criterion of memorization complexity, and the number in the selected number system, separated by one space. If several bases give the same value for the criterion, then choose the smallest among them.
Notes
- The letters must be uppercase(
A-Z
).
Test Cases
Input Output
1
2 1
2
3 2
65535
16 FFFF
123
12 A3
code-golf number base-conversion
New contributor
$endgroup$
How, you can’t remember the 6 or 7-digit phone number that appeared on the TV screen for a second?! Using the special technique described below, you will turn into a walking phonebook!
Obviously, the number 402
is easier to remember than the number 110010010
, and the number 337377
is easier to remember than the number 957472
.
This means that the memorized number, on the one hand, should contain as few digits as possible, and on the other hand, it is desirable that the number contains as many repeating numbers as possible.
As a criterion for the difficulty of remembering, we take the sum of the number of digits in number and the number of different digits in number. A memorized number can be written in another number system, perhaps then it will be easier to remember. For example, the number 65535
in the hexadecimal notation looks like FFFF
.
Task
You need to write a program for selecting the base of the number system to minimize the complexity criterion. The base of the number system must be selected in the range from 2 to 36, then the numbers 0-9
and the English letters A-Z
can be used to represent the number.
Input
The input contains a decimal integer from 1 to 999999999.
Output
The output must contain the base of the number system (from 2 to 36), minimizing the criterion of memorization complexity, and the number in the selected number system, separated by one space. If several bases give the same value for the criterion, then choose the smallest among them.
Notes
- The letters must be uppercase(
A-Z
).
Test Cases
Input Output
1
2 1
2
3 2
65535
16 FFFF
123
12 A3
code-golf number base-conversion
code-golf number base-conversion
New contributor
New contributor
edited 8 hours ago
Ver Nick
New contributor
asked 14 hours ago
Ver NickVer Nick
1725 bronze badges
1725 bronze badges
New contributor
New contributor
11
$begingroup$
Great challenge, but it needs more test cases.
$endgroup$
– Grimy
13 hours ago
6
$begingroup$
Also, the output format is a bit too strict, you might want to allow e.g. an array of two elements, the base and the string, or allowing them in reverse order or separated by another character. Also, I assume that you add the sum of the digits to the number of digits, but you may want to clarify that.
$endgroup$
– Erik the Outgolfer
13 hours ago
7
$begingroup$
Can I usea-z
instead ofA-Z
?
$endgroup$
– Neil
13 hours ago
3
$begingroup$
Can we just use the corresponding numbers instead ofA-Z
?
$endgroup$
– flawr
13 hours ago
5
$begingroup$
@VerNick Next time you write a similar challenge I would suggest allowing both these requests, as they are just an unnecessary complication which are discouraged: see e.g. here.
$endgroup$
– flawr
10 hours ago
|
show 4 more comments
11
$begingroup$
Great challenge, but it needs more test cases.
$endgroup$
– Grimy
13 hours ago
6
$begingroup$
Also, the output format is a bit too strict, you might want to allow e.g. an array of two elements, the base and the string, or allowing them in reverse order or separated by another character. Also, I assume that you add the sum of the digits to the number of digits, but you may want to clarify that.
$endgroup$
– Erik the Outgolfer
13 hours ago
7
$begingroup$
Can I usea-z
instead ofA-Z
?
$endgroup$
– Neil
13 hours ago
3
$begingroup$
Can we just use the corresponding numbers instead ofA-Z
?
$endgroup$
– flawr
13 hours ago
5
$begingroup$
@VerNick Next time you write a similar challenge I would suggest allowing both these requests, as they are just an unnecessary complication which are discouraged: see e.g. here.
$endgroup$
– flawr
10 hours ago
11
11
$begingroup$
Great challenge, but it needs more test cases.
$endgroup$
– Grimy
13 hours ago
$begingroup$
Great challenge, but it needs more test cases.
$endgroup$
– Grimy
13 hours ago
6
6
$begingroup$
Also, the output format is a bit too strict, you might want to allow e.g. an array of two elements, the base and the string, or allowing them in reverse order or separated by another character. Also, I assume that you add the sum of the digits to the number of digits, but you may want to clarify that.
$endgroup$
– Erik the Outgolfer
13 hours ago
$begingroup$
Also, the output format is a bit too strict, you might want to allow e.g. an array of two elements, the base and the string, or allowing them in reverse order or separated by another character. Also, I assume that you add the sum of the digits to the number of digits, but you may want to clarify that.
$endgroup$
– Erik the Outgolfer
13 hours ago
7
7
$begingroup$
Can I use
a-z
instead of A-Z
?$endgroup$
– Neil
13 hours ago
$begingroup$
Can I use
a-z
instead of A-Z
?$endgroup$
– Neil
13 hours ago
3
3
$begingroup$
Can we just use the corresponding numbers instead of
A-Z
?$endgroup$
– flawr
13 hours ago
$begingroup$
Can we just use the corresponding numbers instead of
A-Z
?$endgroup$
– flawr
13 hours ago
5
5
$begingroup$
@VerNick Next time you write a similar challenge I would suggest allowing both these requests, as they are just an unnecessary complication which are discouraged: see e.g. here.
$endgroup$
– flawr
10 hours ago
$begingroup$
@VerNick Next time you write a similar challenge I would suggest allowing both these requests, as they are just an unnecessary complication which are discouraged: see e.g. here.
$endgroup$
– flawr
10 hours ago
|
show 4 more comments
14 Answers
14
active
oldest
votes
$begingroup$
Python 2, 150 149 127 144 bytes
lambda n:min((len(c(n,b))+len(set(c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n/b,b,chr(n%b+48+7*(n%b>9))+s)or s or'0'
Try it online!
Python 3, 136 bytes
lambda n:min((len((*c(n,b),**c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
Python 3.8 (pre-release), 131 bytes
lambda n:min((len((*(x:=c(n,b)),**x)),b,x)for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
c
converts a base 10 number to any base (2-36), and the first (anonymous) function finds the smallest result.
$endgroup$
add a comment |
$begingroup$
05AB1E, 16 14 bytes
-1 byte thanks to Kevin Cruijssen
₆LBāøΣнDÙìg}1è
Try it online!
Or add R)» at the end to conform exactly to the specified output format, but most other answers didn't bother.
Explanation:
₆L # range 1..36
B # convert the input to each of those bases
āø # enumerate (pair each element with its 1-based index)
Σ } # sort by
g # length
н # of the first element
ì # concatenated to
DÙ # itself, uniquified
1è # take the second entry (first will always be base 1)
$endgroup$
1
$begingroup$
-1 byte by using₆L©B®ø
instead of₆LεBy‚}
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
@KevinCruijssen Thanks! Another -1 by usingā
, seems like you always forget about that one.
$endgroup$
– Grimy
12 hours ago
$begingroup$
Lol, I indeed do.. I remembered it with this challenge earlier today, not that it helped in any way, haha xD
$endgroup$
– Kevin Cruijssen
12 hours ago
2
$begingroup$
This doesn't seem to comply with the strict output requirements such as "separated by one space".
$endgroup$
– recursive
7 hours ago
add a comment |
$begingroup$
Japt v2.0a0 -gS
, 24 23 bytes
Not pretty, but it does the job. +2 bytes for the completely unnecessary requirement that output be uppercase.
37o2@sX u ¸iXÃñÈÌiXÌâ)l
Try it
37o2@sX u ¸iXÃñÈÌiXÌâ)l :Implicit input of integer
37o2 :Range [2,37)
@ :Map
sX : Convert the input to a base-X string
u : Uppercase
¸ : Split on spaces (there are none, so this returns a singleton array)
iX : Prepend X
à :End map
ñ :Sort by
È :Pass each X through the following function
Ì : Last element of X
i : Prepend
XÌâ : Last element of X, deduplicated
) : End prepend
l : Length
:Implicit output of the first sub-array, joined with spaces
$endgroup$
$begingroup$
Yes, it works nice, but the letters must be uppercase.
$endgroup$
– Ver Nick
8 hours ago
1
$begingroup$
@VerNick, why? That adds absolutely nothing to the challenge.
$endgroup$
– Shaggy
8 hours ago
$begingroup$
...I guess the next thing will be "separated by one space". Seems the output format has been made very strict on this challenge, and from the comments does not look like it will change.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
@JonathanAllan, luckily I can "fix" that one with a change of flag.
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 87 85 101 bytes
Edit: +16 useless bytes to comply with the strict output format
n=>(g=m=>--b>2?g(m<(v=new Set(s=n.toString(b)).size+s.length)?m:(o=b+' '+s.toUpperCase(),v)):o)(b=37)
Try it online!
$endgroup$
$begingroup$
Ah, I missed that part
$endgroup$
– TFeld
12 hours ago
add a comment |
$begingroup$
Charcoal, 38 bytes
Nθ≔EE³⁴↨θ⁺²ιL⁺ιΦι⁼λ⌕ικη≔⁺²⌕η⌊ηηIη ↥⍘θη
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the integer.
≔EE³⁴↨θ⁺²ι
Convert it from base 2 to base 36...
L⁺ιΦι⁼λ⌕ικη
... deduplicate, concatenate, and take the length.
≔⁺²⌕η⌊ηη
Take the index of the minimum complexity and add 2 to get the base.
Iη ↥⍘θη
Print the base and the integer converted to that base in upper case.
$endgroup$
add a comment |
$begingroup$
Stax, 19 bytes
Ç╛;ⁿY3█↕(╖S♪*ò▌?½╦l
Run and debug it
No fancy algorithm, just straightforward brute force. About a third of the program is format-wrangling for the precise output rules.
Bonus program: Output for [1..1000]
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
bⱮ36µQL+LN)Mḟ1Ḣ,ị‘ịØBʋ¥⁸K
Try it online!
A monadic link taking an integer as its argument and returning a Jelly string of the desired format. If a two-item list was acceptable output (as per most challenges), could save 2 bytes. If base 1 were acceptable for the edge case of 1 as input, could save a further 2 bytes.
$endgroup$
add a comment |
$begingroup$
Japt v2.0a0, 32 bytes
T=2o37 ñ@sX Ê+UsX â ÊÃÎT+S+UsT u
Can save two bytes if I can reverse the order, and can save 2 more if uppercase wasn't required.
Try it
$endgroup$
add a comment |
$begingroup$
Perl 5, 161 bytes
sub f$X=99;for$b(2..36)$_=c($_[0],$b);$x=uniq(/./g)+y///c;($X,$B,$C)=($x,$b,$_)if$x<$X$B,$C
sub cmy($n,$b)=@_;$n?c(int$n/$b,$b).chr(48+$n%$b+7*($n%$b>9)):''
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 109 bytes
Print[a=OrderingBy[#~IntegerDigits~Range@36,Tr[1^#]+Tr[1^Union@#]&][[1]]," ",ToUpperCase[#~IntegerString~a]]&
OrderingBy
was introduced in Mathematica 12.0, which TIO does not seem to have updated to yet.
$endgroup$
$begingroup$
"If several bases give the same value for the criterion, then choose the smallest among them.":OrderingBy
doesn't conform to this requirement.
$endgroup$
– Roman
6 hours ago
$begingroup$
Maybe something withMinimalBy
, like this?
$endgroup$
– Roman
6 hours ago
add a comment |
$begingroup$
PHP, 124 119 bytes
for($i=36;$b=strtoupper(base_convert($argn,10,--$i));$o[strlen($b.count_chars($b,3))]="$i $b");krsort($o);echo end($o);
Try it online!
A shame about the +12 bytes in PHP to uppercase the output... but... anyway.
$endgroup$
add a comment |
$begingroup$
Perl 6, 55 bytes
~map($^b,.base($b),2..36).min:.[*]+.Seto*[1].comb
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 140 135 bytes
lambda n:min([(b,g(n,b))for b in range(2,36)],key=lambda(b,s):len(s)+len(set(s)))
g=lambda n,b:n and g(n/b,b)+chr(n%b+48+7*(n%b>9))or''
Try it online!
$endgroup$
add a comment |
$begingroup$
Brachylog, 44 bytes
∧Y≜∧36≥Xℕ₂≜&ḃ↙X Zd,Zl≡Y∧XwṢwZ-₁₀;Ạụᵗ∋₍ᵐwᵐ
Try it online!
This hurt a bit to write.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Ver Nick is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f189786%2fsimplification-of-numbers%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
14 Answers
14
active
oldest
votes
14 Answers
14
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 2, 150 149 127 144 bytes
lambda n:min((len(c(n,b))+len(set(c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n/b,b,chr(n%b+48+7*(n%b>9))+s)or s or'0'
Try it online!
Python 3, 136 bytes
lambda n:min((len((*c(n,b),**c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
Python 3.8 (pre-release), 131 bytes
lambda n:min((len((*(x:=c(n,b)),**x)),b,x)for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
c
converts a base 10 number to any base (2-36), and the first (anonymous) function finds the smallest result.
$endgroup$
add a comment |
$begingroup$
Python 2, 150 149 127 144 bytes
lambda n:min((len(c(n,b))+len(set(c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n/b,b,chr(n%b+48+7*(n%b>9))+s)or s or'0'
Try it online!
Python 3, 136 bytes
lambda n:min((len((*c(n,b),**c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
Python 3.8 (pre-release), 131 bytes
lambda n:min((len((*(x:=c(n,b)),**x)),b,x)for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
c
converts a base 10 number to any base (2-36), and the first (anonymous) function finds the smallest result.
$endgroup$
add a comment |
$begingroup$
Python 2, 150 149 127 144 bytes
lambda n:min((len(c(n,b))+len(set(c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n/b,b,chr(n%b+48+7*(n%b>9))+s)or s or'0'
Try it online!
Python 3, 136 bytes
lambda n:min((len((*c(n,b),**c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
Python 3.8 (pre-release), 131 bytes
lambda n:min((len((*(x:=c(n,b)),**x)),b,x)for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
c
converts a base 10 number to any base (2-36), and the first (anonymous) function finds the smallest result.
$endgroup$
Python 2, 150 149 127 144 bytes
lambda n:min((len(c(n,b))+len(set(c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n/b,b,chr(n%b+48+7*(n%b>9))+s)or s or'0'
Try it online!
Python 3, 136 bytes
lambda n:min((len((*c(n,b),**c(n,b))),b,c(n,b))for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
Python 3.8 (pre-release), 131 bytes
lambda n:min((len((*(x:=c(n,b)),**x)),b,x)for b in range(2,37))[1:]
c=lambda n,b,s='':n and c(n//b,b,chr(n%b+48+7*(n%b>9))+s)or s
Try it online!
c
converts a base 10 number to any base (2-36), and the first (anonymous) function finds the smallest result.
edited 12 hours ago
answered 13 hours ago
TFeldTFeld
18.1k3 gold badges14 silver badges57 bronze badges
18.1k3 gold badges14 silver badges57 bronze badges
add a comment |
add a comment |
$begingroup$
05AB1E, 16 14 bytes
-1 byte thanks to Kevin Cruijssen
₆LBāøΣнDÙìg}1è
Try it online!
Or add R)» at the end to conform exactly to the specified output format, but most other answers didn't bother.
Explanation:
₆L # range 1..36
B # convert the input to each of those bases
āø # enumerate (pair each element with its 1-based index)
Σ } # sort by
g # length
н # of the first element
ì # concatenated to
DÙ # itself, uniquified
1è # take the second entry (first will always be base 1)
$endgroup$
1
$begingroup$
-1 byte by using₆L©B®ø
instead of₆LεBy‚}
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
@KevinCruijssen Thanks! Another -1 by usingā
, seems like you always forget about that one.
$endgroup$
– Grimy
12 hours ago
$begingroup$
Lol, I indeed do.. I remembered it with this challenge earlier today, not that it helped in any way, haha xD
$endgroup$
– Kevin Cruijssen
12 hours ago
2
$begingroup$
This doesn't seem to comply with the strict output requirements such as "separated by one space".
$endgroup$
– recursive
7 hours ago
add a comment |
$begingroup$
05AB1E, 16 14 bytes
-1 byte thanks to Kevin Cruijssen
₆LBāøΣнDÙìg}1è
Try it online!
Or add R)» at the end to conform exactly to the specified output format, but most other answers didn't bother.
Explanation:
₆L # range 1..36
B # convert the input to each of those bases
āø # enumerate (pair each element with its 1-based index)
Σ } # sort by
g # length
н # of the first element
ì # concatenated to
DÙ # itself, uniquified
1è # take the second entry (first will always be base 1)
$endgroup$
1
$begingroup$
-1 byte by using₆L©B®ø
instead of₆LεBy‚}
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
@KevinCruijssen Thanks! Another -1 by usingā
, seems like you always forget about that one.
$endgroup$
– Grimy
12 hours ago
$begingroup$
Lol, I indeed do.. I remembered it with this challenge earlier today, not that it helped in any way, haha xD
$endgroup$
– Kevin Cruijssen
12 hours ago
2
$begingroup$
This doesn't seem to comply with the strict output requirements such as "separated by one space".
$endgroup$
– recursive
7 hours ago
add a comment |
$begingroup$
05AB1E, 16 14 bytes
-1 byte thanks to Kevin Cruijssen
₆LBāøΣнDÙìg}1è
Try it online!
Or add R)» at the end to conform exactly to the specified output format, but most other answers didn't bother.
Explanation:
₆L # range 1..36
B # convert the input to each of those bases
āø # enumerate (pair each element with its 1-based index)
Σ } # sort by
g # length
н # of the first element
ì # concatenated to
DÙ # itself, uniquified
1è # take the second entry (first will always be base 1)
$endgroup$
05AB1E, 16 14 bytes
-1 byte thanks to Kevin Cruijssen
₆LBāøΣнDÙìg}1è
Try it online!
Or add R)» at the end to conform exactly to the specified output format, but most other answers didn't bother.
Explanation:
₆L # range 1..36
B # convert the input to each of those bases
āø # enumerate (pair each element with its 1-based index)
Σ } # sort by
g # length
н # of the first element
ì # concatenated to
DÙ # itself, uniquified
1è # take the second entry (first will always be base 1)
edited 8 hours ago
answered 13 hours ago
GrimyGrimy
5,28915 silver badges28 bronze badges
5,28915 silver badges28 bronze badges
1
$begingroup$
-1 byte by using₆L©B®ø
instead of₆LεBy‚}
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
@KevinCruijssen Thanks! Another -1 by usingā
, seems like you always forget about that one.
$endgroup$
– Grimy
12 hours ago
$begingroup$
Lol, I indeed do.. I remembered it with this challenge earlier today, not that it helped in any way, haha xD
$endgroup$
– Kevin Cruijssen
12 hours ago
2
$begingroup$
This doesn't seem to comply with the strict output requirements such as "separated by one space".
$endgroup$
– recursive
7 hours ago
add a comment |
1
$begingroup$
-1 byte by using₆L©B®ø
instead of₆LεBy‚}
$endgroup$
– Kevin Cruijssen
12 hours ago
1
$begingroup$
@KevinCruijssen Thanks! Another -1 by usingā
, seems like you always forget about that one.
$endgroup$
– Grimy
12 hours ago
$begingroup$
Lol, I indeed do.. I remembered it with this challenge earlier today, not that it helped in any way, haha xD
$endgroup$
– Kevin Cruijssen
12 hours ago
2
$begingroup$
This doesn't seem to comply with the strict output requirements such as "separated by one space".
$endgroup$
– recursive
7 hours ago
1
1
$begingroup$
-1 byte by using
₆L©B®ø
instead of ₆LεBy‚}
$endgroup$
– Kevin Cruijssen
12 hours ago
$begingroup$
-1 byte by using
₆L©B®ø
instead of ₆LεBy‚}
$endgroup$
– Kevin Cruijssen
12 hours ago
1
1
$begingroup$
@KevinCruijssen Thanks! Another -1 by using
ā
, seems like you always forget about that one.$endgroup$
– Grimy
12 hours ago
$begingroup$
@KevinCruijssen Thanks! Another -1 by using
ā
, seems like you always forget about that one.$endgroup$
– Grimy
12 hours ago
$begingroup$
Lol, I indeed do.. I remembered it with this challenge earlier today, not that it helped in any way, haha xD
$endgroup$
– Kevin Cruijssen
12 hours ago
$begingroup$
Lol, I indeed do.. I remembered it with this challenge earlier today, not that it helped in any way, haha xD
$endgroup$
– Kevin Cruijssen
12 hours ago
2
2
$begingroup$
This doesn't seem to comply with the strict output requirements such as "separated by one space".
$endgroup$
– recursive
7 hours ago
$begingroup$
This doesn't seem to comply with the strict output requirements such as "separated by one space".
$endgroup$
– recursive
7 hours ago
add a comment |
$begingroup$
Japt v2.0a0 -gS
, 24 23 bytes
Not pretty, but it does the job. +2 bytes for the completely unnecessary requirement that output be uppercase.
37o2@sX u ¸iXÃñÈÌiXÌâ)l
Try it
37o2@sX u ¸iXÃñÈÌiXÌâ)l :Implicit input of integer
37o2 :Range [2,37)
@ :Map
sX : Convert the input to a base-X string
u : Uppercase
¸ : Split on spaces (there are none, so this returns a singleton array)
iX : Prepend X
à :End map
ñ :Sort by
È :Pass each X through the following function
Ì : Last element of X
i : Prepend
XÌâ : Last element of X, deduplicated
) : End prepend
l : Length
:Implicit output of the first sub-array, joined with spaces
$endgroup$
$begingroup$
Yes, it works nice, but the letters must be uppercase.
$endgroup$
– Ver Nick
8 hours ago
1
$begingroup$
@VerNick, why? That adds absolutely nothing to the challenge.
$endgroup$
– Shaggy
8 hours ago
$begingroup$
...I guess the next thing will be "separated by one space". Seems the output format has been made very strict on this challenge, and from the comments does not look like it will change.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
@JonathanAllan, luckily I can "fix" that one with a change of flag.
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
Japt v2.0a0 -gS
, 24 23 bytes
Not pretty, but it does the job. +2 bytes for the completely unnecessary requirement that output be uppercase.
37o2@sX u ¸iXÃñÈÌiXÌâ)l
Try it
37o2@sX u ¸iXÃñÈÌiXÌâ)l :Implicit input of integer
37o2 :Range [2,37)
@ :Map
sX : Convert the input to a base-X string
u : Uppercase
¸ : Split on spaces (there are none, so this returns a singleton array)
iX : Prepend X
à :End map
ñ :Sort by
È :Pass each X through the following function
Ì : Last element of X
i : Prepend
XÌâ : Last element of X, deduplicated
) : End prepend
l : Length
:Implicit output of the first sub-array, joined with spaces
$endgroup$
$begingroup$
Yes, it works nice, but the letters must be uppercase.
$endgroup$
– Ver Nick
8 hours ago
1
$begingroup$
@VerNick, why? That adds absolutely nothing to the challenge.
$endgroup$
– Shaggy
8 hours ago
$begingroup$
...I guess the next thing will be "separated by one space". Seems the output format has been made very strict on this challenge, and from the comments does not look like it will change.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
@JonathanAllan, luckily I can "fix" that one with a change of flag.
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
Japt v2.0a0 -gS
, 24 23 bytes
Not pretty, but it does the job. +2 bytes for the completely unnecessary requirement that output be uppercase.
37o2@sX u ¸iXÃñÈÌiXÌâ)l
Try it
37o2@sX u ¸iXÃñÈÌiXÌâ)l :Implicit input of integer
37o2 :Range [2,37)
@ :Map
sX : Convert the input to a base-X string
u : Uppercase
¸ : Split on spaces (there are none, so this returns a singleton array)
iX : Prepend X
à :End map
ñ :Sort by
È :Pass each X through the following function
Ì : Last element of X
i : Prepend
XÌâ : Last element of X, deduplicated
) : End prepend
l : Length
:Implicit output of the first sub-array, joined with spaces
$endgroup$
Japt v2.0a0 -gS
, 24 23 bytes
Not pretty, but it does the job. +2 bytes for the completely unnecessary requirement that output be uppercase.
37o2@sX u ¸iXÃñÈÌiXÌâ)l
Try it
37o2@sX u ¸iXÃñÈÌiXÌâ)l :Implicit input of integer
37o2 :Range [2,37)
@ :Map
sX : Convert the input to a base-X string
u : Uppercase
¸ : Split on spaces (there are none, so this returns a singleton array)
iX : Prepend X
à :End map
ñ :Sort by
È :Pass each X through the following function
Ì : Last element of X
i : Prepend
XÌâ : Last element of X, deduplicated
) : End prepend
l : Length
:Implicit output of the first sub-array, joined with spaces
edited 7 hours ago
answered 10 hours ago
ShaggyShaggy
20.9k3 gold badges20 silver badges70 bronze badges
20.9k3 gold badges20 silver badges70 bronze badges
$begingroup$
Yes, it works nice, but the letters must be uppercase.
$endgroup$
– Ver Nick
8 hours ago
1
$begingroup$
@VerNick, why? That adds absolutely nothing to the challenge.
$endgroup$
– Shaggy
8 hours ago
$begingroup$
...I guess the next thing will be "separated by one space". Seems the output format has been made very strict on this challenge, and from the comments does not look like it will change.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
@JonathanAllan, luckily I can "fix" that one with a change of flag.
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
Yes, it works nice, but the letters must be uppercase.
$endgroup$
– Ver Nick
8 hours ago
1
$begingroup$
@VerNick, why? That adds absolutely nothing to the challenge.
$endgroup$
– Shaggy
8 hours ago
$begingroup$
...I guess the next thing will be "separated by one space". Seems the output format has been made very strict on this challenge, and from the comments does not look like it will change.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
@JonathanAllan, luckily I can "fix" that one with a change of flag.
$endgroup$
– Shaggy
7 hours ago
$begingroup$
Yes, it works nice, but the letters must be uppercase.
$endgroup$
– Ver Nick
8 hours ago
$begingroup$
Yes, it works nice, but the letters must be uppercase.
$endgroup$
– Ver Nick
8 hours ago
1
1
$begingroup$
@VerNick, why? That adds absolutely nothing to the challenge.
$endgroup$
– Shaggy
8 hours ago
$begingroup$
@VerNick, why? That adds absolutely nothing to the challenge.
$endgroup$
– Shaggy
8 hours ago
$begingroup$
...I guess the next thing will be "separated by one space". Seems the output format has been made very strict on this challenge, and from the comments does not look like it will change.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
...I guess the next thing will be "separated by one space". Seems the output format has been made very strict on this challenge, and from the comments does not look like it will change.
$endgroup$
– Jonathan Allan
7 hours ago
$begingroup$
@JonathanAllan, luckily I can "fix" that one with a change of flag.
$endgroup$
– Shaggy
7 hours ago
$begingroup$
@JonathanAllan, luckily I can "fix" that one with a change of flag.
$endgroup$
– Shaggy
7 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 87 85 101 bytes
Edit: +16 useless bytes to comply with the strict output format
n=>(g=m=>--b>2?g(m<(v=new Set(s=n.toString(b)).size+s.length)?m:(o=b+' '+s.toUpperCase(),v)):o)(b=37)
Try it online!
$endgroup$
$begingroup$
Ah, I missed that part
$endgroup$
– TFeld
12 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 87 85 101 bytes
Edit: +16 useless bytes to comply with the strict output format
n=>(g=m=>--b>2?g(m<(v=new Set(s=n.toString(b)).size+s.length)?m:(o=b+' '+s.toUpperCase(),v)):o)(b=37)
Try it online!
$endgroup$
$begingroup$
Ah, I missed that part
$endgroup$
– TFeld
12 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 87 85 101 bytes
Edit: +16 useless bytes to comply with the strict output format
n=>(g=m=>--b>2?g(m<(v=new Set(s=n.toString(b)).size+s.length)?m:(o=b+' '+s.toUpperCase(),v)):o)(b=37)
Try it online!
$endgroup$
JavaScript (ES6), 87 85 101 bytes
Edit: +16 useless bytes to comply with the strict output format
n=>(g=m=>--b>2?g(m<(v=new Set(s=n.toString(b)).size+s.length)?m:(o=b+' '+s.toUpperCase(),v)):o)(b=37)
Try it online!
edited 10 hours ago
answered 13 hours ago
ArnauldArnauld
89.7k7 gold badges104 silver badges366 bronze badges
89.7k7 gold badges104 silver badges366 bronze badges
$begingroup$
Ah, I missed that part
$endgroup$
– TFeld
12 hours ago
add a comment |
$begingroup$
Ah, I missed that part
$endgroup$
– TFeld
12 hours ago
$begingroup$
Ah, I missed that part
$endgroup$
– TFeld
12 hours ago
$begingroup$
Ah, I missed that part
$endgroup$
– TFeld
12 hours ago
add a comment |
$begingroup$
Charcoal, 38 bytes
Nθ≔EE³⁴↨θ⁺²ιL⁺ιΦι⁼λ⌕ικη≔⁺²⌕η⌊ηηIη ↥⍘θη
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the integer.
≔EE³⁴↨θ⁺²ι
Convert it from base 2 to base 36...
L⁺ιΦι⁼λ⌕ικη
... deduplicate, concatenate, and take the length.
≔⁺²⌕η⌊ηη
Take the index of the minimum complexity and add 2 to get the base.
Iη ↥⍘θη
Print the base and the integer converted to that base in upper case.
$endgroup$
add a comment |
$begingroup$
Charcoal, 38 bytes
Nθ≔EE³⁴↨θ⁺²ιL⁺ιΦι⁼λ⌕ικη≔⁺²⌕η⌊ηηIη ↥⍘θη
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the integer.
≔EE³⁴↨θ⁺²ι
Convert it from base 2 to base 36...
L⁺ιΦι⁼λ⌕ικη
... deduplicate, concatenate, and take the length.
≔⁺²⌕η⌊ηη
Take the index of the minimum complexity and add 2 to get the base.
Iη ↥⍘θη
Print the base and the integer converted to that base in upper case.
$endgroup$
add a comment |
$begingroup$
Charcoal, 38 bytes
Nθ≔EE³⁴↨θ⁺²ιL⁺ιΦι⁼λ⌕ικη≔⁺²⌕η⌊ηηIη ↥⍘θη
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the integer.
≔EE³⁴↨θ⁺²ι
Convert it from base 2 to base 36...
L⁺ιΦι⁼λ⌕ικη
... deduplicate, concatenate, and take the length.
≔⁺²⌕η⌊ηη
Take the index of the minimum complexity and add 2 to get the base.
Iη ↥⍘θη
Print the base and the integer converted to that base in upper case.
$endgroup$
Charcoal, 38 bytes
Nθ≔EE³⁴↨θ⁺²ιL⁺ιΦι⁼λ⌕ικη≔⁺²⌕η⌊ηηIη ↥⍘θη
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input the integer.
≔EE³⁴↨θ⁺²ι
Convert it from base 2 to base 36...
L⁺ιΦι⁼λ⌕ικη
... deduplicate, concatenate, and take the length.
≔⁺²⌕η⌊ηη
Take the index of the minimum complexity and add 2 to get the base.
Iη ↥⍘θη
Print the base and the integer converted to that base in upper case.
edited 10 hours ago
answered 13 hours ago
NeilNeil
87.1k8 gold badges46 silver badges183 bronze badges
87.1k8 gold badges46 silver badges183 bronze badges
add a comment |
add a comment |
$begingroup$
Stax, 19 bytes
Ç╛;ⁿY3█↕(╖S♪*ò▌?½╦l
Run and debug it
No fancy algorithm, just straightforward brute force. About a third of the program is format-wrangling for the precise output rules.
Bonus program: Output for [1..1000]
$endgroup$
add a comment |
$begingroup$
Stax, 19 bytes
Ç╛;ⁿY3█↕(╖S♪*ò▌?½╦l
Run and debug it
No fancy algorithm, just straightforward brute force. About a third of the program is format-wrangling for the precise output rules.
Bonus program: Output for [1..1000]
$endgroup$
add a comment |
$begingroup$
Stax, 19 bytes
Ç╛;ⁿY3█↕(╖S♪*ò▌?½╦l
Run and debug it
No fancy algorithm, just straightforward brute force. About a third of the program is format-wrangling for the precise output rules.
Bonus program: Output for [1..1000]
$endgroup$
Stax, 19 bytes
Ç╛;ⁿY3█↕(╖S♪*ò▌?½╦l
Run and debug it
No fancy algorithm, just straightforward brute force. About a third of the program is format-wrangling for the precise output rules.
Bonus program: Output for [1..1000]
edited 7 hours ago
answered 7 hours ago
recursiverecursive
7,74115 silver badges30 bronze badges
7,74115 silver badges30 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 25 bytes
bⱮ36µQL+LN)Mḟ1Ḣ,ị‘ịØBʋ¥⁸K
Try it online!
A monadic link taking an integer as its argument and returning a Jelly string of the desired format. If a two-item list was acceptable output (as per most challenges), could save 2 bytes. If base 1 were acceptable for the edge case of 1 as input, could save a further 2 bytes.
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
bⱮ36µQL+LN)Mḟ1Ḣ,ị‘ịØBʋ¥⁸K
Try it online!
A monadic link taking an integer as its argument and returning a Jelly string of the desired format. If a two-item list was acceptable output (as per most challenges), could save 2 bytes. If base 1 were acceptable for the edge case of 1 as input, could save a further 2 bytes.
$endgroup$
add a comment |
$begingroup$
Jelly, 25 bytes
bⱮ36µQL+LN)Mḟ1Ḣ,ị‘ịØBʋ¥⁸K
Try it online!
A monadic link taking an integer as its argument and returning a Jelly string of the desired format. If a two-item list was acceptable output (as per most challenges), could save 2 bytes. If base 1 were acceptable for the edge case of 1 as input, could save a further 2 bytes.
$endgroup$
Jelly, 25 bytes
bⱮ36µQL+LN)Mḟ1Ḣ,ị‘ịØBʋ¥⁸K
Try it online!
A monadic link taking an integer as its argument and returning a Jelly string of the desired format. If a two-item list was acceptable output (as per most challenges), could save 2 bytes. If base 1 were acceptable for the edge case of 1 as input, could save a further 2 bytes.
answered 5 hours ago
Nick KennedyNick Kennedy
5,7781 gold badge9 silver badges15 bronze badges
5,7781 gold badge9 silver badges15 bronze badges
add a comment |
add a comment |
$begingroup$
Japt v2.0a0, 32 bytes
T=2o37 ñ@sX Ê+UsX â ÊÃÎT+S+UsT u
Can save two bytes if I can reverse the order, and can save 2 more if uppercase wasn't required.
Try it
$endgroup$
add a comment |
$begingroup$
Japt v2.0a0, 32 bytes
T=2o37 ñ@sX Ê+UsX â ÊÃÎT+S+UsT u
Can save two bytes if I can reverse the order, and can save 2 more if uppercase wasn't required.
Try it
$endgroup$
add a comment |
$begingroup$
Japt v2.0a0, 32 bytes
T=2o37 ñ@sX Ê+UsX â ÊÃÎT+S+UsT u
Can save two bytes if I can reverse the order, and can save 2 more if uppercase wasn't required.
Try it
$endgroup$
Japt v2.0a0, 32 bytes
T=2o37 ñ@sX Ê+UsX â ÊÃÎT+S+UsT u
Can save two bytes if I can reverse the order, and can save 2 more if uppercase wasn't required.
Try it
answered 11 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
4,8461 silver badge29 bronze badges
4,8461 silver badge29 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 5, 161 bytes
sub f$X=99;for$b(2..36)$_=c($_[0],$b);$x=uniq(/./g)+y///c;($X,$B,$C)=($x,$b,$_)if$x<$X$B,$C
sub cmy($n,$b)=@_;$n?c(int$n/$b,$b).chr(48+$n%$b+7*($n%$b>9)):''
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5, 161 bytes
sub f$X=99;for$b(2..36)$_=c($_[0],$b);$x=uniq(/./g)+y///c;($X,$B,$C)=($x,$b,$_)if$x<$X$B,$C
sub cmy($n,$b)=@_;$n?c(int$n/$b,$b).chr(48+$n%$b+7*($n%$b>9)):''
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5, 161 bytes
sub f$X=99;for$b(2..36)$_=c($_[0],$b);$x=uniq(/./g)+y///c;($X,$B,$C)=($x,$b,$_)if$x<$X$B,$C
sub cmy($n,$b)=@_;$n?c(int$n/$b,$b).chr(48+$n%$b+7*($n%$b>9)):''
Try it online!
$endgroup$
Perl 5, 161 bytes
sub f$X=99;for$b(2..36)$_=c($_[0],$b);$x=uniq(/./g)+y///c;($X,$B,$C)=($x,$b,$_)if$x<$X$B,$C
sub cmy($n,$b)=@_;$n?c(int$n/$b,$b).chr(48+$n%$b+7*($n%$b>9)):''
Try it online!
answered 7 hours ago
Kjetil S.Kjetil S.
6972 silver badges5 bronze badges
6972 silver badges5 bronze badges
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 109 bytes
Print[a=OrderingBy[#~IntegerDigits~Range@36,Tr[1^#]+Tr[1^Union@#]&][[1]]," ",ToUpperCase[#~IntegerString~a]]&
OrderingBy
was introduced in Mathematica 12.0, which TIO does not seem to have updated to yet.
$endgroup$
$begingroup$
"If several bases give the same value for the criterion, then choose the smallest among them.":OrderingBy
doesn't conform to this requirement.
$endgroup$
– Roman
6 hours ago
$begingroup$
Maybe something withMinimalBy
, like this?
$endgroup$
– Roman
6 hours ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 109 bytes
Print[a=OrderingBy[#~IntegerDigits~Range@36,Tr[1^#]+Tr[1^Union@#]&][[1]]," ",ToUpperCase[#~IntegerString~a]]&
OrderingBy
was introduced in Mathematica 12.0, which TIO does not seem to have updated to yet.
$endgroup$
$begingroup$
"If several bases give the same value for the criterion, then choose the smallest among them.":OrderingBy
doesn't conform to this requirement.
$endgroup$
– Roman
6 hours ago
$begingroup$
Maybe something withMinimalBy
, like this?
$endgroup$
– Roman
6 hours ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 109 bytes
Print[a=OrderingBy[#~IntegerDigits~Range@36,Tr[1^#]+Tr[1^Union@#]&][[1]]," ",ToUpperCase[#~IntegerString~a]]&
OrderingBy
was introduced in Mathematica 12.0, which TIO does not seem to have updated to yet.
$endgroup$
Wolfram Language (Mathematica), 109 bytes
Print[a=OrderingBy[#~IntegerDigits~Range@36,Tr[1^#]+Tr[1^Union@#]&][[1]]," ",ToUpperCase[#~IntegerString~a]]&
OrderingBy
was introduced in Mathematica 12.0, which TIO does not seem to have updated to yet.
answered 7 hours ago
attinatattinat
1,8672 silver badges9 bronze badges
1,8672 silver badges9 bronze badges
$begingroup$
"If several bases give the same value for the criterion, then choose the smallest among them.":OrderingBy
doesn't conform to this requirement.
$endgroup$
– Roman
6 hours ago
$begingroup$
Maybe something withMinimalBy
, like this?
$endgroup$
– Roman
6 hours ago
add a comment |
$begingroup$
"If several bases give the same value for the criterion, then choose the smallest among them.":OrderingBy
doesn't conform to this requirement.
$endgroup$
– Roman
6 hours ago
$begingroup$
Maybe something withMinimalBy
, like this?
$endgroup$
– Roman
6 hours ago
$begingroup$
"If several bases give the same value for the criterion, then choose the smallest among them.":
OrderingBy
doesn't conform to this requirement.$endgroup$
– Roman
6 hours ago
$begingroup$
"If several bases give the same value for the criterion, then choose the smallest among them.":
OrderingBy
doesn't conform to this requirement.$endgroup$
– Roman
6 hours ago
$begingroup$
Maybe something with
MinimalBy
, like this?$endgroup$
– Roman
6 hours ago
$begingroup$
Maybe something with
MinimalBy
, like this?$endgroup$
– Roman
6 hours ago
add a comment |
$begingroup$
PHP, 124 119 bytes
for($i=36;$b=strtoupper(base_convert($argn,10,--$i));$o[strlen($b.count_chars($b,3))]="$i $b");krsort($o);echo end($o);
Try it online!
A shame about the +12 bytes in PHP to uppercase the output... but... anyway.
$endgroup$
add a comment |
$begingroup$
PHP, 124 119 bytes
for($i=36;$b=strtoupper(base_convert($argn,10,--$i));$o[strlen($b.count_chars($b,3))]="$i $b");krsort($o);echo end($o);
Try it online!
A shame about the +12 bytes in PHP to uppercase the output... but... anyway.
$endgroup$
add a comment |
$begingroup$
PHP, 124 119 bytes
for($i=36;$b=strtoupper(base_convert($argn,10,--$i));$o[strlen($b.count_chars($b,3))]="$i $b");krsort($o);echo end($o);
Try it online!
A shame about the +12 bytes in PHP to uppercase the output... but... anyway.
$endgroup$
PHP, 124 119 bytes
for($i=36;$b=strtoupper(base_convert($argn,10,--$i));$o[strlen($b.count_chars($b,3))]="$i $b");krsort($o);echo end($o);
Try it online!
A shame about the +12 bytes in PHP to uppercase the output... but... anyway.
edited 5 mins ago
answered 3 hours ago
640KB640KB
4,1061 gold badge9 silver badges29 bronze badges
4,1061 gold badge9 silver badges29 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 6, 55 bytes
~map($^b,.base($b),2..36).min:.[*]+.Seto*[1].comb
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 6, 55 bytes
~map($^b,.base($b),2..36).min:.[*]+.Seto*[1].comb
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 6, 55 bytes
~map($^b,.base($b),2..36).min:.[*]+.Seto*[1].comb
Try it online!
$endgroup$
Perl 6, 55 bytes
~map($^b,.base($b),2..36).min:.[*]+.Seto*[1].comb
Try it online!
answered 4 hours ago
nwellnhofnwellnhof
7,9701 gold badge12 silver badges29 bronze badges
7,9701 gold badge12 silver badges29 bronze badges
add a comment |
add a comment |
$begingroup$
Python 2, 140 135 bytes
lambda n:min([(b,g(n,b))for b in range(2,36)],key=lambda(b,s):len(s)+len(set(s)))
g=lambda n,b:n and g(n/b,b)+chr(n%b+48+7*(n%b>9))or''
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 140 135 bytes
lambda n:min([(b,g(n,b))for b in range(2,36)],key=lambda(b,s):len(s)+len(set(s)))
g=lambda n,b:n and g(n/b,b)+chr(n%b+48+7*(n%b>9))or''
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 140 135 bytes
lambda n:min([(b,g(n,b))for b in range(2,36)],key=lambda(b,s):len(s)+len(set(s)))
g=lambda n,b:n and g(n/b,b)+chr(n%b+48+7*(n%b>9))or''
Try it online!
$endgroup$
Python 2, 140 135 bytes
lambda n:min([(b,g(n,b))for b in range(2,36)],key=lambda(b,s):len(s)+len(set(s)))
g=lambda n,b:n and g(n/b,b)+chr(n%b+48+7*(n%b>9))or''
Try it online!
answered 4 hours ago
Chas BrownChas Brown
6,0191 gold badge6 silver badges23 bronze badges
6,0191 gold badge6 silver badges23 bronze badges
add a comment |
add a comment |
$begingroup$
Brachylog, 44 bytes
∧Y≜∧36≥Xℕ₂≜&ḃ↙X Zd,Zl≡Y∧XwṢwZ-₁₀;Ạụᵗ∋₍ᵐwᵐ
Try it online!
This hurt a bit to write.
$endgroup$
add a comment |
$begingroup$
Brachylog, 44 bytes
∧Y≜∧36≥Xℕ₂≜&ḃ↙X Zd,Zl≡Y∧XwṢwZ-₁₀;Ạụᵗ∋₍ᵐwᵐ
Try it online!
This hurt a bit to write.
$endgroup$
add a comment |
$begingroup$
Brachylog, 44 bytes
∧Y≜∧36≥Xℕ₂≜&ḃ↙X Zd,Zl≡Y∧XwṢwZ-₁₀;Ạụᵗ∋₍ᵐwᵐ
Try it online!
This hurt a bit to write.
$endgroup$
Brachylog, 44 bytes
∧Y≜∧36≥Xℕ₂≜&ḃ↙X Zd,Zl≡Y∧XwṢwZ-₁₀;Ạụᵗ∋₍ᵐwᵐ
Try it online!
This hurt a bit to write.
answered 3 hours ago
Unrelated StringUnrelated String
3,2752 gold badges3 silver badges17 bronze badges
3,2752 gold badges3 silver badges17 bronze badges
add a comment |
add a comment |
Ver Nick is a new contributor. Be nice, and check out our Code of Conduct.
Ver Nick is a new contributor. Be nice, and check out our Code of Conduct.
Ver Nick is a new contributor. Be nice, and check out our Code of Conduct.
Ver Nick is a new contributor. Be nice, and check out our Code of Conduct.
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f189786%2fsimplification-of-numbers%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
11
$begingroup$
Great challenge, but it needs more test cases.
$endgroup$
– Grimy
13 hours ago
6
$begingroup$
Also, the output format is a bit too strict, you might want to allow e.g. an array of two elements, the base and the string, or allowing them in reverse order or separated by another character. Also, I assume that you add the sum of the digits to the number of digits, but you may want to clarify that.
$endgroup$
– Erik the Outgolfer
13 hours ago
7
$begingroup$
Can I use
a-z
instead ofA-Z
?$endgroup$
– Neil
13 hours ago
3
$begingroup$
Can we just use the corresponding numbers instead of
A-Z
?$endgroup$
– flawr
13 hours ago
5
$begingroup$
@VerNick Next time you write a similar challenge I would suggest allowing both these requests, as they are just an unnecessary complication which are discouraged: see e.g. here.
$endgroup$
– flawr
10 hours ago