Skip to main content
added 7 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Mathematica, 123 119119 118 bytes

f=FromCharacterCode[s=SortBy;#&@@@s[Join@@(s[Tally@ToCharacterCode@#,-Last@#&]/.{x_,n_}:>({x,#/n}&/@Range@n&~Array~n)),{Last}]]&

Defines a named function f. Ungolfed:

f = FromCharacterCode[
   s = SortBy;
   # & @@@ s[
     Join @@ (
       s[
         Tally@ToCharacterCode@#,
         -Last@# &
         ] /. {x_, n_} :> ({x, #/n} & /@ Range@n&~Array~n)
       ),
     {Last}
     ]
   ] &

Using built-in rational types seemed like a good idea for this. Of course, this is nowhere near CJam. Basically, I'm representing the grid shown in the challenge as a list of pairs. The first thing in the pair is the character code, the second is it's position as a fraction less than or equal to 1 (the final column being 1). Having made sure that the individual characters are already in the right order, I just need to sort this stably by said fraction to get the desired result.

Mathematica, 123 119 bytes

f=FromCharacterCode[s=SortBy;#&@@@s[Join@@(s[Tally@ToCharacterCode@#,-Last@#&]/.{x_,n_}:>({x,#/n}&/@Range@n)),{Last}]]&

Defines a named function f. Ungolfed:

f = FromCharacterCode[
   s = SortBy;
   # & @@@ s[
     Join @@ (
       s[
         Tally@ToCharacterCode@#,
         -Last@# &
         ] /. {x_, n_} :> ({x, #/n} & /@ Range@n)
       ),
     {Last}
     ]
   ] &

Using built-in rational types seemed like a good idea for this. Of course, this is nowhere near CJam. Basically, I'm representing the grid shown in the challenge as a list of pairs. The first thing in the pair is the character code, the second is it's position as a fraction less than or equal to 1 (the final column being 1). Having made sure that the individual characters are already in the right order, I just need to sort this stably by said fraction to get the desired result.

Mathematica, 123 119 118 bytes

f=FromCharacterCode[s=SortBy;#&@@@s[Join@@(s[Tally@ToCharacterCode@#,-Last@#&]/.{x_,n_}:>({x,#/n}&~Array~n)),{Last}]]&

Defines a named function f. Ungolfed:

f = FromCharacterCode[
   s = SortBy;
   # & @@@ s[
     Join @@ (
       s[
         Tally@ToCharacterCode@#,
         -Last@# &
         ] /. {x_, n_} :> ({x, #/n} &~Array~n)
       ),
     {Last}
     ]
   ] &

Using built-in rational types seemed like a good idea for this. Of course, this is nowhere near CJam. Basically, I'm representing the grid shown in the challenge as a list of pairs. The first thing in the pair is the character code, the second is it's position as a fraction less than or equal to 1 (the final column being 1). Having made sure that the individual characters are already in the right order, I just need to sort this stably by said fraction to get the desired result.

added 11 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Mathematica, 123123 119 bytes

f=FromCharacterCode[#&@@#&/@SortBy[Join@@f=FromCharacterCode[s=SortBy;#&@@@s[Join@@(SortBy[Tally@ToCharacterCode@#s[Tally@ToCharacterCode@#,-Last@#&]/.{x_,n_}:>({x,#/n}&/@Range@n)),{Last}]]&

Defines a named function f. Ungolfed:

f = FromCharacterCode[
   #s &= @@SortBy;
   # & /@@@@ SortBy[s[
     Join @@ (
       SortBy[s[
         Tally@ToCharacterCode@#,
         -Last@# &
         ] /. {x_, n_} :> ({x, #/n} & /@ Range@n)
       ),
     {Last}
     ]
   ] &

Using built-in rational types seemed like a good idea for this. Of course, this is nowhere near CJam. Basically, I'm representing the grid shown in the challenge as a list of pairs. The first thing in the pair is the character code, the second is it's position as a fraction less than or equal to 1 (the final column being 1). Having made sure that the individual characters are already in the right order, I just need to sort this stably by said fraction to get the desired result.

Mathematica, 123 bytes

f=FromCharacterCode[#&@@#&/@SortBy[Join@@(SortBy[Tally@ToCharacterCode@#,-Last@#&]/.{x_,n_}:>({x,#/n}&/@Range@n)),{Last}]]&

Defines a named function f. Ungolfed:

f = FromCharacterCode[
   # & @@ # & /@ SortBy[
     Join @@ (
       SortBy[
         Tally@ToCharacterCode@#,
         -Last@# &
         ] /. {x_, n_} :> ({x, #/n} & /@ Range@n)
       ),
     {Last}
     ]
   ] &

Using built-in rational types seemed like a good idea for this. Of course, this is nowhere near CJam. Basically, I'm representing the grid shown in the challenge as a list of pairs. The first thing in the pair is the character code, the second is it's position as a fraction less than or equal to 1 (the final column being 1). Having made sure that the individual characters are already in the right order, I just need to sort this stably by said fraction to get the desired result.

Mathematica, 123 119 bytes

f=FromCharacterCode[s=SortBy;#&@@@s[Join@@(s[Tally@ToCharacterCode@#,-Last@#&]/.{x_,n_}:>({x,#/n}&/@Range@n)),{Last}]]&

Defines a named function f. Ungolfed:

f = FromCharacterCode[
   s = SortBy;
   # & @@@ s[
     Join @@ (
       s[
         Tally@ToCharacterCode@#,
         -Last@# &
         ] /. {x_, n_} :> ({x, #/n} & /@ Range@n)
       ),
     {Last}
     ]
   ] &

Using built-in rational types seemed like a good idea for this. Of course, this is nowhere near CJam. Basically, I'm representing the grid shown in the challenge as a list of pairs. The first thing in the pair is the character code, the second is it's position as a fraction less than or equal to 1 (the final column being 1). Having made sure that the individual characters are already in the right order, I just need to sort this stably by said fraction to get the desired result.

Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

Mathematica, 123 bytes

f=FromCharacterCode[#&@@#&/@SortBy[Join@@(SortBy[Tally@ToCharacterCode@#,-Last@#&]/.{x_,n_}:>({x,#/n}&/@Range@n)),{Last}]]&

Defines a named function f. Ungolfed:

f = FromCharacterCode[
   # & @@ # & /@ SortBy[
     Join @@ (
       SortBy[
         Tally@ToCharacterCode@#,
         -Last@# &
         ] /. {x_, n_} :> ({x, #/n} & /@ Range@n)
       ),
     {Last}
     ]
   ] &

Using built-in rational types seemed like a good idea for this. Of course, this is nowhere near CJam. Basically, I'm representing the grid shown in the challenge as a list of pairs. The first thing in the pair is the character code, the second is it's position as a fraction less than or equal to 1 (the final column being 1). Having made sure that the individual characters are already in the right order, I just need to sort this stably by said fraction to get the desired result.