14
\$\begingroup\$

What is a Word Signature?

The signature of a word are all of it's letters put in order - the signatures of this, hist and hits are all hist.

The Challenge

Write a program program should ask for an input, then print out the signature of that word. So an example program run might look like this:

Give me a string: this
The signature signature of 'this' is hist.

There is no required interaction, as long as it takes an input and prints the signature, it is OK.

Scoring

The program with the smallest byte count wins!

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

var QUESTION_ID=54945;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),e.has_more?getAnswers():process()}})}function shouldHaveHeading(e){var a=!1,r=e.body_markdown.split("\n");try{a|=/^#/.test(e.body_markdown),a|=["-","="].indexOf(r[1][0])>-1,a&=LANGUAGE_REG.test(e.body_markdown)}catch(n){}return a}function shouldHaveScore(e){var a=!1;try{a|=SIZE_REG.test(e.body_markdown.split("\n")[0])}catch(r){}return a}function getAuthorName(e){return e.owner.display_name}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading),answers.sort(function(e,a){var r=+(e.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0],n=+(a.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0];return r-n});var e={},a=1,r=null,n=1;answers.forEach(function(s){var t=s.body_markdown.split("\n")[0],o=jQuery("#answer-template").html(),l=(t.match(NUMBER_REG)[0],(t.match(SIZE_REG)||[0])[0]),c=t.match(LANGUAGE_REG)[1],i=getAuthorName(s);l!=r&&(n=a),r=l,++a,o=o.replace("{{PLACE}}",n+".").replace("{{NAME}}",i).replace("{{LANGUAGE}}",c).replace("{{SIZE}}",l).replace("{{LINK}}",s.share_link),o=jQuery(o),jQuery("#answers").append(o),e[c]=e[c]||{lang:c,user:i,size:l,link:s.share_link}});var s=[];for(var t in e)e.hasOwnProperty(t)&&s.push(e[t]);s.sort(function(e,a){return e.lang>a.lang?1:e.lang<a.lang?-1:0});for(var o=0;o<s.length;++o){var l=jQuery("#language-template").html(),t=s[o];l=l.replace("{{LANGUAGE}}",t.lang).replace("{{NAME}}",t.user).replace("{{SIZE}}",t.size).replace("{{LINK}}",t.link),l=jQuery(l),jQuery("#languages").append(l)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:&lt;(?:s&gt;[^&]*&lt;\/s&gt;|[^&]+&gt;)[^\d&]*)*$)/,NUMBER_REG=/\d+/,LANGUAGE_REG=/^#*\s*([^,]+)/;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table></div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table></div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table><table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody></table>

Challenged Finished!

WINNER: jimmy23013

\$\endgroup\$
15
  • 4
    \$\begingroup\$ We don't have to print the sentences Give me a string: and The signature signature of 'this' is right? We can just take the input directly and print the result? \$\endgroup\$
    – Fatalize
    Commented Aug 19, 2015 at 7:24
  • 5
    \$\begingroup\$ What about duplicate letters? e.g. is the signature of broom bmoor or bmor? \$\endgroup\$
    – samgak
    Commented Aug 19, 2015 at 7:39
  • 4
    \$\begingroup\$ @isaacg why are you? \$\endgroup\$
    – Tim
    Commented Aug 19, 2015 at 10:52
  • 3
    \$\begingroup\$ @Tim I don't think we should have challenges that are this straightforward. I'll ask about it on meta - it's not really about this question in particular. \$\endgroup\$
    – isaacg
    Commented Aug 19, 2015 at 11:00
  • 2
    \$\begingroup\$ I think this would have been a more interesting challenge if you couldn't use built-in sorting functions. \$\endgroup\$
    – Glen O
    Commented Aug 20, 2015 at 4:34

46 Answers 46

50
\$\begingroup\$

GolfScript, 1 byte

$

Yes, only 1 byte.

Try it here.

\$\endgroup\$
8
  • 4
    \$\begingroup\$ Marked as correct because no-one can beat 1 byte. \$\endgroup\$
    – user42003
    Commented Aug 19, 2015 at 7:55
  • 10
    \$\begingroup\$ @Kslkgh In theory, maybe someone can find a language that can do it in 0 bytes? \$\endgroup\$
    – jimmy23013
    Commented Aug 19, 2015 at 7:57
  • 2
    \$\begingroup\$ I would say that this fails for "Hello" \$\endgroup\$ Commented Aug 20, 2015 at 11:50
  • 3
    \$\begingroup\$ Seems to break for anything with a capital, but guess it was never specified \$\endgroup\$
    – Lain
    Commented Aug 20, 2015 at 13:37
  • 1
    \$\begingroup\$ Capitals don't break the code. It first sorts capitals then lowercase. i.e. cbaCBAfed -> ABCabcdef \$\endgroup\$
    – Mully
    Commented Aug 21, 2015 at 22:16
26
\$\begingroup\$

C (with x86), 61 bytes

s[];main(){qsort(s,read(0,s,99),1,"YXZQQQ\x8a\x00*\x02\x0f\xbe\xc0\xc3");puts(s);}

That string contains raw bytes, not actual \x.. codes, and it's a raw machine code callback passed to qsort. Works on x86 only:

59         pop   ecx
58         pop   eax
5a         pop   edx
51         push  ecx
51         push  ecx
51         push  ecx
8a 00      mov   al,  BYTE PTR [eax]
2a 02      sub   al,  BYTE PTR [edx]
0f be c0   movsx eax, al
c3         ret

Which is essentially:

int func(char *a, char *b) { return *a - *b; }

See p6-7 of this pamphlet in Japanese by shinh.

\$\endgroup\$
1
  • \$\begingroup\$ This is not generic C language, as it targets a specific architecture. That should be specified in the heading \$\endgroup\$
    – edc65
    Commented Aug 21, 2015 at 19:57
20
\$\begingroup\$

Stuck, 4 bytes

sc$d

This language was documented on the wiki just yesterday! Mmm, fresh esolangs.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nicely done! :) \$\endgroup\$
    – Kade
    Commented Aug 19, 2015 at 14:14
19
\$\begingroup\$

Stuck, 5 Bytes

I finally get to use my language, Stuck! :D

s$""j

This takes an input via stdin, sorts, joins, and implicitly prints. This did give me some ideas for changes though.

Edit: Oh wow, someone already posted and beat me in my own language!

\$\endgroup\$
16
\$\begingroup\$

GOTO++, 432 430 bytes

GOTO++ project site.

niveaugourou 0
s=ENTRETONTEXTE()
§2 a=LeCaracNumero()&s *(1)
n=*(1)
costaud i=*(2)/&i infeg NombreDeLettres(&s)/i=+*(1)
b=LeCaracNumero()&s &i
GOTONULPOURLESNULS %1 }&b inf &a{
a=&b
n=&i
§1 faiblard
GOTOPRINTDUTEXTE()&a
t=PrendsUnMorceau()&s *(0) &n
u=PrendsUnMorceau()&s }&n+*(1){ *(0)
e=BOITEAPINGOUINS()&t &u
s=Marijuana()&e «»
GOTONONNULPOURLESNULS %3 }NombreDeLettres(&s) eg *(1){
GOTOPASMALIN %2
§3 GOTOPRINTDUTEXTE()&s

Not sure why I inflicted this to myself, but I did

\$\endgroup\$
13
\$\begingroup\$

gs2, 1 byte

/

Same as the GolfScript answer, but gs2 uses a different operator for sorting.

\$\endgroup\$
10
\$\begingroup\$

Perl, 18 bytes

print sort<>=~/./g

Thanks to Dom Hastings for helping me save 3 bytes.

\$\endgroup\$
2
  • \$\begingroup\$ you can save a few bytes using a /./g instead of split'',: print sort<>=~/./g! \$\endgroup\$ Commented Aug 19, 2015 at 9:02
  • \$\begingroup\$ With -nE, you can do say sort/./g. \$\endgroup\$
    – Dennis
    Commented Aug 19, 2015 at 20:18
7
\$\begingroup\$

Haskell, 35 bytes

import Data.List;main=interact sort
\$\endgroup\$
0
6
\$\begingroup\$

J, 3 bytes

/:~

For example: /:~'this'

\$\endgroup\$
6
\$\begingroup\$

Pyth, 2 bytes

Sw

DEMO HERE.

Details-

S - for sorting
w - Python 3's input()
\$\endgroup\$
6
\$\begingroup\$

C#, 114 110 characters

Takes input from a command line argument. Not a very short program, but well... it's C#. :P

namespace System.Linq{class P{static void Main(string[]a){Console.Write(string.Concat(a[0].OrderBy(x=>x)));}}}

Thanks to Abbas for saving 4 bytes!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ You can save 4 chars by using Write instead of WriteLine. ;) \$\endgroup\$
    – Abbas
    Commented Aug 19, 2015 at 13:19
  • \$\begingroup\$ @Abbas Thanks! Totally missed that one ;p \$\endgroup\$
    – ProgramFOX
    Commented Aug 19, 2015 at 13:24
6
\$\begingroup\$

Brainfuck, 40 bytes

,[>>+>>,]<<[[<<]>>[-[<]>>[.<<->]>+>>]<<]

This uses the counting sort algorithm, which makes this an O(n) solution.

The code requires a left-infinite or wrapping tape of 8 bit cells. Try it online!

How it works

,          Read a char from STDIN.
[          While the byte under the pointer (last read char) is non-zero:
  >>+        Move the pointer two steps to the right and increment.
  >>,        Move the pointer two steps to the right and read a char.
]
<<         Move the pointer two steps to the left.

           If the input was "sort", the tape now contains the following:
           0 0 115 0 1 0 111 0 1 0 114 0 1 0 116 0 1 0 0
                                                   ^

[          While the byte under the pointer is non-zero:
  [<<]       Advance two steps to the left until a null byte is encountered.
  >>         Advance two steps to the right.

             This will place the pointer on the first input character.

  [          While the byte under the pointer is non-zero:
    -          Decrement.
    [<]        Move the pointer to the left until a null byte is encountered.
    >>         Move the pointer two steps to the right.

               If the decremented character is non-zero, [<] will move to the
               null byte before it, so >> brings the pointer to the null byte
               after it. If the decremented character is zero, [<] is a no-op, so
               >> advances two steps to the right, to a non-zero byte.

    [          While the byte under the pointer is non-zero:
      .          Print the char under the pointer.
      <<-        Move the pointer two steps to the left and decrement.
      >          Move the pointer to the right.
    ]

               If the decremented character gave zero, this will print the value
               of the accumulator after it, and decrement the character once more
               to make it non-zero, then place the pointer to the right of the
               character, thus exiting the loop.

    >+         Move the pointer to the right and increment.

               This increments the accumulator each time an input character is
               decremented.

    >>         Move the pointer two steps to the right.

               This moves the pointer to the next character.
  ]
  <<         Move the pointer two steps to the left.

             This moves the pointer to the accumulator of the last character.
]

             After 255, th accumulator wraps around to 0, and the loop ends.
\$\endgroup\$
5
\$\begingroup\$

CJam, 2 bytes

l$

Reads a line of input (l) and sorts it ($).

\$\endgroup\$
4
\$\begingroup\$

Python 3, 31 Bytes

print("".join(sorted(input())))
\$\endgroup\$
2
  • \$\begingroup\$ That looks like 29 bytes to me \$\endgroup\$
    – Blue
    Commented Aug 19, 2015 at 9:30
  • \$\begingroup\$ @muddyfish it's 31 chars, when I counted :) \$\endgroup\$
    – Kamehameha
    Commented Aug 19, 2015 at 9:40
4
\$\begingroup\$

Coreutils, 24 23

fold -w1|sort|tr -d \\n
\$\endgroup\$
4
\$\begingroup\$

Ruby, 17 bytes

$><<$<.chars.sort
\$\endgroup\$
4
\$\begingroup\$

Java 8, 119 bytes

This is basically only competitive with the C# answer, because, well, Java.

(At least this beats GOTO++. Not really an accomplishment...)

class C{public static void main(String[]s){s=s[0].split("");java.util.Arrays.sort(s);System.out.print("".join("",s));}}

Thanks to ProgramFOX for saving 1 byte, rink.attendant for saving 2 bytes.

\$\endgroup\$
5
  • \$\begingroup\$ You can save one char by removing the space between String[] and s. \$\endgroup\$
    – ProgramFOX
    Commented Aug 19, 2015 at 14:06
  • \$\begingroup\$ Oh, I forgot about that. Now my byte count is a nice square number. Thanks! \$\endgroup\$ Commented Aug 19, 2015 at 14:18
  • \$\begingroup\$ I think you can use System.out.print instead of println \$\endgroup\$ Commented Aug 19, 2015 at 14:59
  • \$\begingroup\$ Thank you! This is my first attempt at code golf, so I still have to learn stuff like that. \$\endgroup\$ Commented Aug 19, 2015 at 15:38
  • \$\begingroup\$ You could save 12 characters with public static void main(String[]s){s[0].chars().sorted().forEach(i->System.out.print((char)i));} \$\endgroup\$
    – assylias
    Commented Aug 21, 2015 at 11:34
4
\$\begingroup\$

Ostrich, 2 bytes

G$

In Ostrich G reads a line of input from STDIN and $ sorts it.

\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6), 32 bytes

Demo only works in Firefox and Edge at time of writing, as Chrome/Opera does not support ES6 by default:

Edit: I didn't look at the answers prior to posting but now I realize it's pretty much the exact same as the one by NinjaBearMonkey.

f=x=>alert([...x].sort().join``)
<form action=# onsubmit='f(document.getElementById("I").value);return false;'>
  <input type=text pattern=\w+ id=I>
  <button type=submit>Sort letters</button>
</form>

\$\endgroup\$
3
\$\begingroup\$

Julia, 21 bytes

s->join(sort([s...]))

And for fun, here's how you might do it without using an inbuilt sorting function, for 53 bytes:

f=s->s>""?(k=indmax(s);f(s[k+1:end]s[1:k-1])s[k:k]):s
\$\endgroup\$
2
\$\begingroup\$

SWI-Prolog, 34 bytes

a(X):-msort(X,Y),writef("%s",[Y]).

Called as such:a(`this`).

\$\endgroup\$
2
\$\begingroup\$

Scala, 21 bytes

print(args(0).sorted)

run from command line example:

$ scala -e "print(args(0).sorted)" this
hist
\$\endgroup\$
2
\$\begingroup\$

Powershell, 44 37 Bytes

-join((Read-Host).ToCharArray()|sort)
\$\endgroup\$
1
  • \$\begingroup\$ also +1 for powershell use, but i beatcha :) \$\endgroup\$
    – Nacht
    Commented Aug 20, 2015 at 8:53
2
\$\begingroup\$

JavaScript, 34 bytes

alert([...prompt()].sort().join``)

The reason this is so long is that JavaScript can only sort arrays, so the string must be split into an array, sorted, and then joined back into a string. This is ECMAScript 6; the equivalent in ES5 is:

alert(prompt().split('').sort().join(''))
\$\endgroup\$
2
  • \$\begingroup\$ Should specify EcmaScript 6 as it's using ... and template strings \$\endgroup\$
    – edc65
    Commented Aug 21, 2015 at 19:59
  • \$\begingroup\$ @edc65 You're right, I forgot. Done. \$\endgroup\$ Commented Aug 21, 2015 at 20:56
1
\$\begingroup\$

Python 2, 33 32 bytes

print`sorted(raw_input())`[2::5]

Heavily inspired by @Kamehameha's answer. Converted to python 2. Can't golf much more.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can use repr to bring it down another byte (Now you know why I chose Python 3 version of the solution :P) - print`sorted(raw_input())`[2::5] (Those are backticks, not single quotes) \$\endgroup\$
    – Kamehameha
    Commented Aug 19, 2015 at 9:53
1
\$\begingroup\$

APL, 7 characters

Doesn't work on ngn-apl for me, but should work in theory:

X[⍋X←⍞]

reads a line from standard input, which is assigned to X. ⍋X is the indices of X which yield an ascending order, and X[...] actually sorts X by these indices.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Works on Dyalog (desktop version, not TryAPL). \$\endgroup\$
    – Alex A.
    Commented Aug 19, 2015 at 19:08
1
\$\begingroup\$

JavaScript, 54 bytes

call js file with node

console.log(process.argv[2].split('').sort().join(''))
\$\endgroup\$
1
\$\begingroup\$

Processing, 40 bytes

print(join(sort(args[0].split("")),""));
\$\endgroup\$
1
\$\begingroup\$

Nim, 102 101 79 73 bytes

let s=stdin.readAll
for i in 1..'~':
 for j in s:(if i==j:stdout.write j)

Still learning Nim and working out golf tricks. Apparently it's better not to use the builtin sort, which would require a lot of imports (thanks @Mauris)

\$\endgroup\$
4
  • \$\begingroup\$ let s=stdin.readAll;for i in 1..'~':(for j in s:(if i==j:echo j)) is 65 bytes. \$\endgroup\$
    – lynn
    Commented Aug 19, 2015 at 20:18
  • \$\begingroup\$ @Mauris Wow, I didn't think that not using the builtin sort would be shorter! Only problem though - is there a way to echo without the trailing newline? \$\endgroup\$
    – Sp3000
    Commented Aug 20, 2015 at 0:08
  • \$\begingroup\$ Oh, oops, of course. stdout.write j seems to work, and is slightly shorter than your &= loop. \$\endgroup\$
    – lynn
    Commented Aug 20, 2015 at 1:45
  • \$\begingroup\$ @Mauris Indeed, it seems to work - thanks :) \$\endgroup\$
    – Sp3000
    Commented Aug 20, 2015 at 2:13
1
\$\begingroup\$

PowerShell, 27 bytes

%{([char[]]$_|sort)-join''}
\$\endgroup\$
1
  • \$\begingroup\$ Nicely done with taking pipeline input. \$\endgroup\$ Commented Aug 20, 2015 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.