Same number letters
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Letters of the words want fairness
they decided to appear same number of times in a sentence equally
Example
Priorities
will become
Ppprrioooritttieeesss
each letter show 3 times as letter mostly used was i and it showed 3 times
it does not matter where you put the repeated letters as log as they next to a similar letter
means
Pppriooorritttieeesss
is ok (the r letter)
Ppprioororitttieeesss
is no ok (the r letter)
another example
invoice
will become
innvvooiccee
another example
Remittance Advice
will become
Rrremmmiitttaannncce Adddvvvice
Space, comma, question mark, quotation, etc. are not letters letters are from (a-z both cap and small) , just once space is enough, and the order of the letters should remain the same
the form of the letter does not matter, either cap or small will count as the same letter, Pip
has 2 Ps and 1 I so it will become Piip
It is case insensitive letters can be in any form, Piip=piip=piiP=PiiP
This is code-golf
code-golf word-puzzle
 |Â
show 6 more comments
up vote
2
down vote
favorite
Letters of the words want fairness
they decided to appear same number of times in a sentence equally
Example
Priorities
will become
Ppprrioooritttieeesss
each letter show 3 times as letter mostly used was i and it showed 3 times
it does not matter where you put the repeated letters as log as they next to a similar letter
means
Pppriooorritttieeesss
is ok (the r letter)
Ppprioororitttieeesss
is no ok (the r letter)
another example
invoice
will become
innvvooiccee
another example
Remittance Advice
will become
Rrremmmiitttaannncce Adddvvvice
Space, comma, question mark, quotation, etc. are not letters letters are from (a-z both cap and small) , just once space is enough, and the order of the letters should remain the same
the form of the letter does not matter, either cap or small will count as the same letter, Pip
has 2 Ps and 1 I so it will become Piip
It is case insensitive letters can be in any form, Piip=piip=piiP=PiiP
This is code-golf
code-golf word-puzzle
1
How do we deal with capital letters?
â xnor
4 hours ago
Caps and small no difference, you can use either
â asmgx
4 hours ago
1
Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
â Shieru Asakoto
4 hours ago
1
@JonathanAllan will fix this now
â asmgx
11 mins ago
2
can we change the case of capitalised letters? e.g. CanPip
result inpiip
?
â Jo King
7 mins ago
 |Â
show 6 more comments
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Letters of the words want fairness
they decided to appear same number of times in a sentence equally
Example
Priorities
will become
Ppprrioooritttieeesss
each letter show 3 times as letter mostly used was i and it showed 3 times
it does not matter where you put the repeated letters as log as they next to a similar letter
means
Pppriooorritttieeesss
is ok (the r letter)
Ppprioororitttieeesss
is no ok (the r letter)
another example
invoice
will become
innvvooiccee
another example
Remittance Advice
will become
Rrremmmiitttaannncce Adddvvvice
Space, comma, question mark, quotation, etc. are not letters letters are from (a-z both cap and small) , just once space is enough, and the order of the letters should remain the same
the form of the letter does not matter, either cap or small will count as the same letter, Pip
has 2 Ps and 1 I so it will become Piip
It is case insensitive letters can be in any form, Piip=piip=piiP=PiiP
This is code-golf
code-golf word-puzzle
Letters of the words want fairness
they decided to appear same number of times in a sentence equally
Example
Priorities
will become
Ppprrioooritttieeesss
each letter show 3 times as letter mostly used was i and it showed 3 times
it does not matter where you put the repeated letters as log as they next to a similar letter
means
Pppriooorritttieeesss
is ok (the r letter)
Ppprioororitttieeesss
is no ok (the r letter)
another example
invoice
will become
innvvooiccee
another example
Remittance Advice
will become
Rrremmmiitttaannncce Adddvvvice
Space, comma, question mark, quotation, etc. are not letters letters are from (a-z both cap and small) , just once space is enough, and the order of the letters should remain the same
the form of the letter does not matter, either cap or small will count as the same letter, Pip
has 2 Ps and 1 I so it will become Piip
It is case insensitive letters can be in any form, Piip=piip=piiP=PiiP
This is code-golf
code-golf word-puzzle
code-golf word-puzzle
edited 2 mins ago
asked 5 hours ago
asmgx
1156
1156
1
How do we deal with capital letters?
â xnor
4 hours ago
Caps and small no difference, you can use either
â asmgx
4 hours ago
1
Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
â Shieru Asakoto
4 hours ago
1
@JonathanAllan will fix this now
â asmgx
11 mins ago
2
can we change the case of capitalised letters? e.g. CanPip
result inpiip
?
â Jo King
7 mins ago
 |Â
show 6 more comments
1
How do we deal with capital letters?
â xnor
4 hours ago
Caps and small no difference, you can use either
â asmgx
4 hours ago
1
Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
â Shieru Asakoto
4 hours ago
1
@JonathanAllan will fix this now
â asmgx
11 mins ago
2
can we change the case of capitalised letters? e.g. CanPip
result inpiip
?
â Jo King
7 mins ago
1
1
How do we deal with capital letters?
â xnor
4 hours ago
How do we deal with capital letters?
â xnor
4 hours ago
Caps and small no difference, you can use either
â asmgx
4 hours ago
Caps and small no difference, you can use either
â asmgx
4 hours ago
1
1
Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
â Shieru Asakoto
4 hours ago
Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
â Shieru Asakoto
4 hours ago
1
1
@JonathanAllan will fix this now
â asmgx
11 mins ago
@JonathanAllan will fix this now
â asmgx
11 mins ago
2
2
can we change the case of capitalised letters? e.g. Can
Pip
result in piip
?â Jo King
7 mins ago
can we change the case of capitalised letters? e.g. Can
Pip
result in piip
?â Jo King
7 mins ago
 |Â
show 6 more comments
4 Answers
4
active
oldest
votes
up vote
3
down vote
05AB1E, 18 13 bytes
Case sensitive.
áÃÂSÃÂùsâZñ>ÃÂ.;
Try it online!
Explanation
á # keep only letters of input
ÃÂ # remove duplicates
S # split to list of chars
ÃÂ # triplicate
ùsâ # count the occurrence of each unique letter in input
Zñ # take abs with the max occurrence
> # increment
ÃÂ # repeat each unique letter that many times
.; # replace the first occurrence of the letter in the input with this
The input is meant to be able to contain mixed case, then be treated case insensitively e.g.Pip
->Ppii
; so this does not currently fit spec. However as Jo king just asked we do not know ifppii
orPPII
would be acceptable...
â Jonathan Allan
5 mins ago
@JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
â Emigna
1 min ago
add a comment |Â
up vote
2
down vote
JavaScript (Node.js), 126 bytes
f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x
Try it online!
all lower or ALL UPPER only.
Explanation
f = x => // The function. `f=` is needed because we will
// use the function object as temporary storage
[...x].map(c => ( // - Iterate among each character...
f[c] = -~f[c], // - Add one to the character counter
f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
c // - Return back the character for the use in
// the next map function
), w = 0) // - The max counter
.map(c => // - Iterate again...
x = x.replace( // - Repeat the first appearance of
c, // - Each character
c.repeat( // - Needed number times
parseInt(c, 36) > 9 // - Additional constraint
? w - f[c] + 1 // - If this is letter, repeat
: 1 // - If not, stay as is
), // - That should've been clearly stated
f[c] = w // - And set the counter so that no further
// replacements are done on this character
) // - (w - f[c] + 1 = 1 in further iterations)
) && x // - Return the result
add a comment |Â
up vote
2
down vote
J, 44 bytes
#~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.
Try it online!
add a comment |Â
up vote
1
down vote
Perl 6, 79 bytes
->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'
Try it online!
Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.
Explanation:
->a # Anonymous code block that takes a mutable string
for 'a'..'z' # For each letter
a.=subst( ) # Substitute
$_, #The first occurrence of the letter with
$_ x #The letter repeated
a.comb(/<:Ll>/) The lowercase letters of the string
.Bag.values.max # The count of the most common letter
+1 # Plus 1
-a.comb($_) # Minus the count of that letter already in the string
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
05AB1E, 18 13 bytes
Case sensitive.
áÃÂSÃÂùsâZñ>ÃÂ.;
Try it online!
Explanation
á # keep only letters of input
ÃÂ # remove duplicates
S # split to list of chars
ÃÂ # triplicate
ùsâ # count the occurrence of each unique letter in input
Zñ # take abs with the max occurrence
> # increment
ÃÂ # repeat each unique letter that many times
.; # replace the first occurrence of the letter in the input with this
The input is meant to be able to contain mixed case, then be treated case insensitively e.g.Pip
->Ppii
; so this does not currently fit spec. However as Jo king just asked we do not know ifppii
orPPII
would be acceptable...
â Jonathan Allan
5 mins ago
@JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
â Emigna
1 min ago
add a comment |Â
up vote
3
down vote
05AB1E, 18 13 bytes
Case sensitive.
áÃÂSÃÂùsâZñ>ÃÂ.;
Try it online!
Explanation
á # keep only letters of input
ÃÂ # remove duplicates
S # split to list of chars
ÃÂ # triplicate
ùsâ # count the occurrence of each unique letter in input
Zñ # take abs with the max occurrence
> # increment
ÃÂ # repeat each unique letter that many times
.; # replace the first occurrence of the letter in the input with this
The input is meant to be able to contain mixed case, then be treated case insensitively e.g.Pip
->Ppii
; so this does not currently fit spec. However as Jo king just asked we do not know ifppii
orPPII
would be acceptable...
â Jonathan Allan
5 mins ago
@JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
â Emigna
1 min ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
05AB1E, 18 13 bytes
Case sensitive.
áÃÂSÃÂùsâZñ>ÃÂ.;
Try it online!
Explanation
á # keep only letters of input
ÃÂ # remove duplicates
S # split to list of chars
ÃÂ # triplicate
ùsâ # count the occurrence of each unique letter in input
Zñ # take abs with the max occurrence
> # increment
ÃÂ # repeat each unique letter that many times
.; # replace the first occurrence of the letter in the input with this
05AB1E, 18 13 bytes
Case sensitive.
áÃÂSÃÂùsâZñ>ÃÂ.;
Try it online!
Explanation
á # keep only letters of input
ÃÂ # remove duplicates
S # split to list of chars
ÃÂ # triplicate
ùsâ # count the occurrence of each unique letter in input
Zñ # take abs with the max occurrence
> # increment
ÃÂ # repeat each unique letter that many times
.; # replace the first occurrence of the letter in the input with this
edited 17 mins ago
answered 29 mins ago
Emigna
43.5k431131
43.5k431131
The input is meant to be able to contain mixed case, then be treated case insensitively e.g.Pip
->Ppii
; so this does not currently fit spec. However as Jo king just asked we do not know ifppii
orPPII
would be acceptable...
â Jonathan Allan
5 mins ago
@JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
â Emigna
1 min ago
add a comment |Â
The input is meant to be able to contain mixed case, then be treated case insensitively e.g.Pip
->Ppii
; so this does not currently fit spec. However as Jo king just asked we do not know ifppii
orPPII
would be acceptable...
â Jonathan Allan
5 mins ago
@JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
â Emigna
1 min ago
The input is meant to be able to contain mixed case, then be treated case insensitively e.g.
Pip
-> Ppii
; so this does not currently fit spec. However as Jo king just asked we do not know if ppii
or PPII
would be acceptable...â Jonathan Allan
5 mins ago
The input is meant to be able to contain mixed case, then be treated case insensitively e.g.
Pip
-> Ppii
; so this does not currently fit spec. However as Jo king just asked we do not know if ppii
or PPII
would be acceptable...â Jonathan Allan
5 mins ago
@JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
â Emigna
1 min ago
@JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
â Emigna
1 min ago
add a comment |Â
up vote
2
down vote
JavaScript (Node.js), 126 bytes
f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x
Try it online!
all lower or ALL UPPER only.
Explanation
f = x => // The function. `f=` is needed because we will
// use the function object as temporary storage
[...x].map(c => ( // - Iterate among each character...
f[c] = -~f[c], // - Add one to the character counter
f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
c // - Return back the character for the use in
// the next map function
), w = 0) // - The max counter
.map(c => // - Iterate again...
x = x.replace( // - Repeat the first appearance of
c, // - Each character
c.repeat( // - Needed number times
parseInt(c, 36) > 9 // - Additional constraint
? w - f[c] + 1 // - If this is letter, repeat
: 1 // - If not, stay as is
), // - That should've been clearly stated
f[c] = w // - And set the counter so that no further
// replacements are done on this character
) // - (w - f[c] + 1 = 1 in further iterations)
) && x // - Return the result
add a comment |Â
up vote
2
down vote
JavaScript (Node.js), 126 bytes
f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x
Try it online!
all lower or ALL UPPER only.
Explanation
f = x => // The function. `f=` is needed because we will
// use the function object as temporary storage
[...x].map(c => ( // - Iterate among each character...
f[c] = -~f[c], // - Add one to the character counter
f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
c // - Return back the character for the use in
// the next map function
), w = 0) // - The max counter
.map(c => // - Iterate again...
x = x.replace( // - Repeat the first appearance of
c, // - Each character
c.repeat( // - Needed number times
parseInt(c, 36) > 9 // - Additional constraint
? w - f[c] + 1 // - If this is letter, repeat
: 1 // - If not, stay as is
), // - That should've been clearly stated
f[c] = w // - And set the counter so that no further
// replacements are done on this character
) // - (w - f[c] + 1 = 1 in further iterations)
) && x // - Return the result
add a comment |Â
up vote
2
down vote
up vote
2
down vote
JavaScript (Node.js), 126 bytes
f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x
Try it online!
all lower or ALL UPPER only.
Explanation
f = x => // The function. `f=` is needed because we will
// use the function object as temporary storage
[...x].map(c => ( // - Iterate among each character...
f[c] = -~f[c], // - Add one to the character counter
f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
c // - Return back the character for the use in
// the next map function
), w = 0) // - The max counter
.map(c => // - Iterate again...
x = x.replace( // - Repeat the first appearance of
c, // - Each character
c.repeat( // - Needed number times
parseInt(c, 36) > 9 // - Additional constraint
? w - f[c] + 1 // - If this is letter, repeat
: 1 // - If not, stay as is
), // - That should've been clearly stated
f[c] = w // - And set the counter so that no further
// replacements are done on this character
) // - (w - f[c] + 1 = 1 in further iterations)
) && x // - Return the result
JavaScript (Node.js), 126 bytes
f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x
Try it online!
all lower or ALL UPPER only.
Explanation
f = x => // The function. `f=` is needed because we will
// use the function object as temporary storage
[...x].map(c => ( // - Iterate among each character...
f[c] = -~f[c], // - Add one to the character counter
f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
c // - Return back the character for the use in
// the next map function
), w = 0) // - The max counter
.map(c => // - Iterate again...
x = x.replace( // - Repeat the first appearance of
c, // - Each character
c.repeat( // - Needed number times
parseInt(c, 36) > 9 // - Additional constraint
? w - f[c] + 1 // - If this is letter, repeat
: 1 // - If not, stay as is
), // - That should've been clearly stated
f[c] = w // - And set the counter so that no further
// replacements are done on this character
) // - (w - f[c] + 1 = 1 in further iterations)
) && x // - Return the result
edited 45 mins ago
answered 4 hours ago
Shieru Asakoto
1,690311
1,690311
add a comment |Â
add a comment |Â
up vote
2
down vote
J, 44 bytes
#~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.
Try it online!
add a comment |Â
up vote
2
down vote
J, 44 bytes
#~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
J, 44 bytes
#~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.
Try it online!
J, 44 bytes
#~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.
Try it online!
edited 15 mins ago
answered 3 hours ago
FrownyFrog
2,1671518
2,1671518
add a comment |Â
add a comment |Â
up vote
1
down vote
Perl 6, 79 bytes
->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'
Try it online!
Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.
Explanation:
->a # Anonymous code block that takes a mutable string
for 'a'..'z' # For each letter
a.=subst( ) # Substitute
$_, #The first occurrence of the letter with
$_ x #The letter repeated
a.comb(/<:Ll>/) The lowercase letters of the string
.Bag.values.max # The count of the most common letter
+1 # Plus 1
-a.comb($_) # Minus the count of that letter already in the string
add a comment |Â
up vote
1
down vote
Perl 6, 79 bytes
->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'
Try it online!
Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.
Explanation:
->a # Anonymous code block that takes a mutable string
for 'a'..'z' # For each letter
a.=subst( ) # Substitute
$_, #The first occurrence of the letter with
$_ x #The letter repeated
a.comb(/<:Ll>/) The lowercase letters of the string
.Bag.values.max # The count of the most common letter
+1 # Plus 1
-a.comb($_) # Minus the count of that letter already in the string
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Perl 6, 79 bytes
->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'
Try it online!
Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.
Explanation:
->a # Anonymous code block that takes a mutable string
for 'a'..'z' # For each letter
a.=subst( ) # Substitute
$_, #The first occurrence of the letter with
$_ x #The letter repeated
a.comb(/<:Ll>/) The lowercase letters of the string
.Bag.values.max # The count of the most common letter
+1 # Plus 1
-a.comb($_) # Minus the count of that letter already in the string
Perl 6, 79 bytes
->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'
Try it online!
Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.
Explanation:
->a # Anonymous code block that takes a mutable string
for 'a'..'z' # For each letter
a.=subst( ) # Substitute
$_, #The first occurrence of the letter with
$_ x #The letter repeated
a.comb(/<:Ll>/) The lowercase letters of the string
.Bag.values.max # The count of the most common letter
+1 # Plus 1
-a.comb($_) # Minus the count of that letter already in the string
edited 19 mins ago
answered 4 hours ago
Jo King
16.8k24193
16.8k24193
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%2f173323%2fsame-number-letters%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
1
How do we deal with capital letters?
â xnor
4 hours ago
Caps and small no difference, you can use either
â asmgx
4 hours ago
1
Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
â Shieru Asakoto
4 hours ago
1
@JonathanAllan will fix this now
â asmgx
11 mins ago
2
can we change the case of capitalised letters? e.g. Can
Pip
result inpiip
?â Jo King
7 mins ago