Skip to main content
added 1013 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

CJam, 2121 19 bytes

'[,_qeuqeu:A|&65>A;'[,65>{A\-,}$

Try it online.

Example

$ cjam etaoin.cjam <<< "~XyxY YyxZ"
YXZABCDEFGHIJKLMNOPQRSTUVW

(no newline)

How it works

qeu:A; " Read from STDIN, convert to uppercase, save in the variable “A” and discard, ";
'[,    " Push an array of all ASCII characters before “[” (NUL to “Z”).               ";
65>    " Remove the first 64 characters (NUL to “@”).                                 ";
{      " Sort the array of characters by the following mapping:                       ";
  A\   " Swap the character with the string saved in variable “A”.                    ";
  -    " Remove all occurrences of the character from the string.                     ";
  ,    " Push the length of the string.                                               ";
}$     "                                                                              ";

More occurrences means more characters get removed, so the most frequent characters appear at the beginning of the array.

CJam, 21 bytes

'[,_qeu:A|&65>{A\-,}$

Try it online.

CJam, 21 19 bytes

qeu:A;'[,65>{A\-,}$

Try it online.

Example

$ cjam etaoin.cjam <<< "~XyxY YyxZ"
YXZABCDEFGHIJKLMNOPQRSTUVW

(no newline)

How it works

qeu:A; " Read from STDIN, convert to uppercase, save in the variable “A” and discard, ";
'[,    " Push an array of all ASCII characters before “[” (NUL to “Z”).               ";
65>    " Remove the first 64 characters (NUL to “@”).                                 ";
{      " Sort the array of characters by the following mapping:                       ";
  A\   " Swap the character with the string saved in variable “A”.                    ";
  -    " Remove all occurrences of the character from the string.                     ";
  ,    " Push the length of the string.                                               ";
}$     "                                                                              ";

More occurrences means more characters get removed, so the most frequent characters appear at the beginning of the array.

Post Undeleted by Dennis
deleted 1 character in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

CJam, 1921 bytes

'[,qeu_qeu:A|65>A|&65>{A\-,}$

Try it online.

CJam, 19 bytes

'[,qeu:A|65>{A\-,}$

Try it online.

CJam, 21 bytes

'[,_qeu:A|&65>{A\-,}$

Try it online.

Post Deleted by Dennis
deleted 1 character in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

CJam, 2019 bytes

'[,qeu:A|65>{A\/-,~}$

Try it online.

CJam, 20 bytes

'[,qeu:A|65>{A\/,~}$

Try it online.

CJam, 19 bytes

'[,qeu:A|65>{A\-,}$

Try it online.

Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading