Sign that word!

12

6

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

user42003

Posted 2015-08-19T07:22:18.930

Reputation:

3We 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? – Fatalize – 2015-08-19T07:24:41.467

Also are inputs consisting only of lowercase characters or can there be uppercase letters? – Fatalize – 2015-08-19T07:28:18.513

4What about duplicate letters? e.g. is the signature of broom bmoor or bmor? – samgak – 2015-08-19T07:39:51.110

@Fatalize Yes, there is no required interaction with the user. Just take the input and print the result. – None – 2015-08-19T07:50:25.833

@samgak bmoor. Duplicates are put in. – None – 2015-08-19T07:51:05.993

1I'm voting to close this as too broad/trivial. – isaacg – 2015-08-19T10:24:51.703

3@isaacg why are you? – Tim – 2015-08-19T10:52:26.987

This looks essentially like a duplicate of this question.

– Peter Taylor – 2015-08-19T10:56:10.227

3@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. – isaacg – 2015-08-19T11:00:54.107

Well, I'm a few hours late, and every competitive language I know has already been done. :/ – kirbyfan64sos – 2015-08-19T13:44:37.543

2I think this would have been a more interesting challenge if you couldn't use built-in sorting functions. – Glen O – 2015-08-20T04:34:16.260

1@GlenO, or duplicate letters and multicase need to be supported. – James Webster – 2015-08-20T11:50:08.853

@JamesWebster Duplicate letters do. – None – 2015-08-20T17:26:28.020

These suggestions will be addressed in Sign that word 2, being posted soon. That one will have a stricter set of rules. – None – 2015-08-20T19:25:58.437

1

Added second edition. http://codegolf.stackexchange.com/questions/55090/sign-that-word-2 Not a duplicate because the answers from this question are not transposable to that one.

– None – 2015-08-21T07:13:28.930

Answers

49

GolfScript, 1 byte

$

Yes, only 1 byte.

Try it here.

jimmy23013

Posted 2015-08-19T07:22:18.930

Reputation: 34 042

4Marked as correct because no-one can beat 1 byte. – None – 2015-08-19T07:55:24.977

9@Kslkgh In theory, maybe someone can find a language that can do it in 0 bytes? – jimmy23013 – 2015-08-19T07:57:41.363

OK then, fair enough, will mark as correct in 1 week! – None – 2015-08-19T07:58:59.517

SERIOUSLY?! _____ – Alec Teal – 2015-08-20T09:36:46.677

2I would say that this fails for "Hello" – James Webster – 2015-08-20T11:50:39.413

3Seems to break for anything with a capital, but guess it was never specified – Lain – 2015-08-20T13:37:52.023

1Capitals don't break the code. It first sorts capitals then lowercase. i.e. cbaCBAfed -> ABCabcdef – Mully – 2015-08-21T22:16:16.643

Congratulations to @jimmy23013, you win! – None – 2015-08-28T06:43:26.713

25

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.

Lynn

Posted 2015-08-19T07:22:18.930

Reputation: 55 648

This is not generic C language, as it targets a specific architecture. That should be specified in the heading – edc65 – 2015-08-21T19:57:44.220

20

Stuck, 4 bytes

sc$d

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

Lynn

Posted 2015-08-19T07:22:18.930

Reputation: 55 648

1Nicely done! :) – Kade – 2015-08-19T14:14:33.183

19

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!

Kade

Posted 2015-08-19T07:22:18.930

Reputation: 7 463

16

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

Fatalize

Posted 2015-08-19T07:22:18.930

Reputation: 32 976

13

gs2, 1 byte

/

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

Lynn

Posted 2015-08-19T07:22:18.930

Reputation: 55 648

10

Perl, 18 bytes

print sort<>=~/./g

Thanks to Dom Hastings for helping me save 3 bytes.

samgak

Posted 2015-08-19T07:22:18.930

Reputation: 1 577

you can save a few bytes using a /./g instead of split'',: print sort<>=~/./g! – Dom Hastings – 2015-08-19T09:02:25.667

With -nE, you can do say sort/./g. – Dennis – 2015-08-19T20:18:36.943

7

Haskell, 35 bytes

import Data.List;main=interact sort

Lynn

Posted 2015-08-19T07:22:18.930

Reputation: 55 648

6

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!

ProgramFOX

Posted 2015-08-19T07:22:18.930

Reputation: 8 017

1You can save 4 chars by using Write instead of WriteLine. ;) – Abbas – 2015-08-19T13:19:15.767

@Abbas Thanks! Totally missed that one ;p – ProgramFOX – 2015-08-19T13:24:30.357

6

Pyth, 2 bytes

Sw

DEMO HERE.

Details-

S - for sorting
w - Python 3's input()

Kamehameha

Posted 2015-08-19T07:22:18.930

Reputation: 553

6

J, 3 bytes

/:~

For example: /:~'this'

Fatalize

Posted 2015-08-19T07:22:18.930

Reputation: 32 976

6

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.

Dennis

Posted 2015-08-19T07:22:18.930

Reputation: 196 637

5

CJam, 2 bytes

l$

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

Lynn

Posted 2015-08-19T07:22:18.930

Reputation: 55 648

4

Coreutils, 24 23

fold -w1|sort|tr -d \\n

Thor

Posted 2015-08-19T07:22:18.930

Reputation: 2 526

4

Python 3, 31 Bytes

print("".join(sorted(input())))

Kamehameha

Posted 2015-08-19T07:22:18.930

Reputation: 553

That looks like 29 bytes to me – Blue – 2015-08-19T09:30:03.543

@muddyfish it's 31 chars, when I counted :) – Kamehameha – 2015-08-19T09:40:23.437

4

Ruby, 17 bytes

$><<$<.chars.sort

Lynn

Posted 2015-08-19T07:22:18.930

Reputation: 55 648

4

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.

TheMadHaberdasher

Posted 2015-08-19T07:22:18.930

Reputation: 191

You can save one char by removing the space between String[] and s. – ProgramFOX – 2015-08-19T14:06:23.260

Oh, I forgot about that. Now my byte count is a nice square number. Thanks! – TheMadHaberdasher – 2015-08-19T14:18:57.417

I think you can use System.out.print instead of println – rink.attendant.6 – 2015-08-19T14:59:18.553

Thank you! This is my first attempt at code golf, so I still have to learn stuff like that. – TheMadHaberdasher – 2015-08-19T15:38:45.567

You could save 12 characters with public static void main(String[]s){s[0].chars().sorted().forEach(i->System.out.print((char)i));} – assylias – 2015-08-21T11:34:02.863

4

Ostrich, 2 bytes

G$

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

Alex A.

Posted 2015-08-19T07:22:18.930

Reputation: 23 761

3

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>

rink.attendant.6

Posted 2015-08-19T07:22:18.930

Reputation: 2 776

2

SWI-Prolog, 34 bytes

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

Called as such:a(`this`).

Fatalize

Posted 2015-08-19T07:22:18.930

Reputation: 32 976

2

Scala, 21 bytes

print(args(0).sorted)

run from command line example:

$ scala -e "print(args(0).sorted)" this
hist

gilad hoch

Posted 2015-08-19T07:22:18.930

Reputation: 717

2

Powershell, 44 37 Bytes

-join((Read-Host).ToCharArray()|sort)

Stephan Schinkel

Posted 2015-08-19T07:22:18.930

Reputation: 596

also +1 for powershell use, but i beatcha :) – Nacht - Reinstate Monica – 2015-08-20T08:53:24.970

2

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(''))

NinjaBearMonkey

Posted 2015-08-19T07:22:18.930

Reputation: 9 925

Should specify EcmaScript 6 as it's using ... and template strings – edc65 – 2015-08-21T19:59:14.283

@edc65 You're right, I forgot. Done. – NinjaBearMonkey – 2015-08-21T20:56:03.047

2

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

Glen O

Posted 2015-08-19T07:22:18.930

Reputation: 2 548

1

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.

Blue

Posted 2015-08-19T07:22:18.930

Reputation: 26 661

1You 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) – Kamehameha – 2015-08-19T09:53:53.063

1

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.

Lynn

Posted 2015-08-19T07:22:18.930

Reputation: 55 648

1Works on Dyalog (desktop version, not TryAPL). – Alex A. – 2015-08-19T19:08:03.060

1

JavaScript, 54 bytes

call js file with node

console.log(process.argv[2].split('').sort().join(''))

Marcel

Posted 2015-08-19T07:22:18.930

Reputation: 21

1

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)

Sp3000

Posted 2015-08-19T07:22:18.930

Reputation: 58 729

let s=stdin.readAll;for i in 1..'~':(for j in s:(if i==j:echo j)) is 65 bytes. – Lynn – 2015-08-19T20:18:20.470

@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? – Sp3000 – 2015-08-20T00:08:27.260

Oh, oops, of course. stdout.write j seems to work, and is slightly shorter than your &= loop. – Lynn – 2015-08-20T01:45:00.253

@Mauris Indeed, it seems to work - thanks :) – Sp3000 – 2015-08-20T02:13:48.870

1

Matlab, 13 5 bytes

The code simply defines a function handle to the sort function:

@sort

To call it, use ans('this'), where 'this' represents the input string (thanks to Alex A. and Stewie Griffin):

>> @sort
ans = 
    @sort
>> ans('this')
ans =
hist

Luis Mendo

Posted 2015-08-19T07:22:18.930

Reputation: 87 464

Gotta love f('this'). I don't think you need to count the name of the function in your byte count though, since unnamed functions are generally acceptable. – Alex A. – 2015-08-19T20:16:43.520

@AlexA Thanks! But if I define the function without the function handle f , i.e. just @(x)sort(x), then the call can't (obviously) be f('this'). It needs to be the uglier and cumbersome feval(@(x)sort(x),'this'). Do you think that would be acceptable? – Luis Mendo – 2015-08-20T00:22:51.200

Yep, that's very common. Often folks just say, "to call the function give it a name." – Alex A. – 2015-08-20T02:58:45.480

I don't like this at all, but you can actually do: @(x)sort(x), and then ans('this'). I guess you don't need to count the bytes for ans..? Obviously this only works one time, but nothing in the rules prevent this. Also, I would claim sort('this') should suffice, seeing that everyone else just uses the built in sort functions without giving it a different name first. – Stewie Griffin – 2015-08-20T12:36:18.507

@AlexA. Thanks! – Luis Mendo – 2015-08-20T15:12:08.580

@StewieGriffin Hey, good idea to use ans! I agree it's ugly, but the very purpose of code golf is to abuse language. As for your second proposal, I wouldn't know how many bytes to count then :-) – Luis Mendo – 2015-08-20T15:13:31.463

1

Processing, 40 bytes

print(join(sort(args[0].split("")),""));

Kevin Workman

Posted 2015-08-19T07:22:18.930

Reputation: 308

1

jq, 20 bytes

explode|sort|implode

try it here

gilad hoch

Posted 2015-08-19T07:22:18.930

Reputation: 717

1

PowerShell, 27 bytes

%{([char[]]$_|sort)-join''}

Nacht - Reinstate Monica

Posted 2015-08-19T07:22:18.930

Reputation: 481

Nicely done with taking pipeline input. – AdmBorkBork – 2015-08-20T12:40:46.450

1

PHP, 47 bytes

$a=str_split($argv[1]);asort($a);echo join($a);

GeorgeQ

Posted 2015-08-19T07:22:18.930

Reputation: 111

1

C++, 135 bytes

#include <iostream>
#include <string>
#include <algorithm>
main(){std::string s;std::cin>>s;std::sort(s.begin(),s.end());std::cout<<s;}

http://coliru.stacked-crooked.com/a/7c9d5c37c2783a23

I payed for what I used :P

user43222

Posted 2015-08-19T07:22:18.930

Reputation: 21

The downvote wasn't mine, but it may have something to do with this not being valid C++ because main() must have an int return

– Tas – 2015-08-24T03:37:09.443

@Tas The question doesn't specify that it must be strictly valid code. If it works, it works. – developerbmw – 2015-09-09T03:33:23.943

1payed paid... – developerbmw – 2015-09-09T03:36:32.417

1

pb (INVALID), 179 bytes

^w[B!0]{w[B!0]{>}<t[B]^b[T]vb[0]<[X]<vb[B+1]^>}^w[B!0]{w[B!0]{>}<t[B]b[0]<[X]v[T+2]w[B!0]{>}b[T]<[X]^[Y+2]}vv<w[B!0]{>vw[B=0]{v}w[B!0]{>}<t[B]b[0]^[Y]<[X]w[B!0]{>}b[T]<[X]<b[B-1]}

Answers on this site are only considered valid if the language they're written in was available (e.g. there was an interpreter) at the time the question was posted. I didn't finish pb's interpreter until the day after, so this answer is just for fun and is ineligible to win (not that it was going to). That's also why I formatted the header of this answer incorrectly; I don't want to show up in the leaderboard snippet :)

Here's the code with comments, though I'm not sure they'll be helpful to anyone trying to decipher this. I just wrote them to keep my thoughts straight while writing the program, so they're kind of redundant and all over the place.

^w[B!0]{                     # while there's something at (0, -1)
    w[B!0]{>}<t[B]^b[T]vb[0] # move last byte of input up by 1
    <[X]<v                   # go to (-1, 0)
    b[B+1]                   # increase by 1
    ^>}                      # restart loop
^w[B!0]{                     # while there's something at (0, -2)
    w[B!0]{>}<t[B]b[0]       # save last byte of input and erase it
    <[X]                     # go to (0, -2)
    v[T+2]                   # go down T+2
    w[B!0]{>}b[T]            # go right until there's nothing there. write T
    <[X]^[Y+2]}              # restart loop
vv<w[B!0]{                   # while there's something at (-1, 0)
    >vw[B=0]{v}              # go down the X=0 column until you find something
    w[B!0]{>}<t[B]b[0]       # save the rightmost thing and erase it
    ^[Y]<[X]w[B!0]{>}b[T]    # add the thing you got to Y=0, to be outputted
    <[X]<b[B-1]}             # decrease (-1, 0) by 1 and repeat loop

undergroundmonorail

Posted 2015-08-19T07:22:18.930

Reputation: 5 897

1

Ruby, 23 bytes

puts gets.chars.sort*''

Splits string by empty regexp, sorts array, joins array. Thanks to @MartinBüttner for 6 bytes :D

clap

Posted 2015-08-19T07:22:18.930

Reputation: 834

1

Brainfuck, 140 bytes

Probably not the winning post, but still it was fun :)

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

Explanation:

Program loads whole line and performs bubble sort. After each sort iteration prints and removes last character. It's always the smallest one, because bubble sort guarantees, that after every iteration the lowest value is in the end. Stops after removal of all characters.

#read line
----------[++++++++++>>,----------]<<

#MEMORY MODEL OF WHOLE PROGRAM:
# 0|0|?|0|?|0|?|0|?|0|0
#     C   C   C   C
# C-character from input

#iterate if there are characters
[
    #go to first letter
    [<<]>>

    #MEMORY MODEL OF TWO SORTED CHARACTERS:
    # 0|?|0|?|0|?|0|?
    # S L M R F   G
    # S - swap of left during left 0 check
    # L - left character
    # M - middle, difference between left and right
    # R - right character
    # F - flag, set if left was not 0
    # G - next flag, set if left was 0

    #sort two characters if there are at least two
    >>[        
        #while right is not 0
        [
            #if left is not 0
            <<[[-<+>]
                #set flag
                >>>+<<<
            #clean up after left's 0 check
            ]<[->+<]>

            #if flag is set, so left is not 0
            >>>[-
                #move 1 from left and right to the middle
                <-<+<->>>
                #set next flag
                >>+<<
            ]

            #if next flag is not set, so left was 0 
            >>-[+
                #transfer right to left
                <<<[-<<+>>]>>>
            ]

        #while right is not 0
        <<<]

        #distribute middle to left and right
        <[-<+>>+<]>

    #end if it was the last character
    >>]
    #write and clear last character
    <<.[-]
#end if no more characters
<<]

CoffeeCloud

Posted 2015-08-19T07:22:18.930

Reputation: 31

1

C++, 101 Bytes

#include<bits/stdc++.h>
using namespace std;main(){string s;cin>>s;sort(s.begin(),s.end());cout<<s;}

Sahil Arora

Posted 2015-08-19T07:22:18.930

Reputation: 341

0

Idris, 46 bytes

main:IO();main=putStr$pack$sort$unpack!getLine

Lynn

Posted 2015-08-19T07:22:18.930

Reputation: 55 648

0

Lua, 79 bytes

t=table for c in({...})[1]:gmatch"."do t:insert(c)end t:sort()print(t:concat())

Obviously, I could save a few bytes if the string was already in a variable (say, s):

t=table for c in s:gmatch"."do t:insert(c)end t:sort()print(t:concat())

Henrik Ilgen

Posted 2015-08-19T07:22:18.930

Reputation: 121

4

64 bytes: s=io.read()t={s:byte(1,-1)}table.sort(t)print(s.char(unpack(t)))

– Egor Skriptunoff – 2015-08-19T18:11:42.553

64 is probably the minimum, too.

– Lynn – 2015-08-19T20:26:18.467

0

Bash + coreutils (49 bytes)

Bash was not yet submitted, here is a script (needs to be in a file, as it recurses):

[ $1 ]&&(echo ${1::1};$0 ${1:1})|sort|tr -d '\n'

I just recursively output head, call the script with the tail of the word in order to split the input word ($1) to single chars and then use sort util.

However I believe a shorter solution using bash+coreutils exists... Any ideas?

pawel.boczarski

Posted 2015-08-19T07:22:18.930

Reputation: 1 243

0

Lua, 91 bytes

a=table t={}for c in arg[1]:gmatch(".") do t[#t+1]=c end a.sort(t)print(a.concat(t))

Lua has no string sort function or split/explode function, so it was a struggle

Trebuchette

Posted 2015-08-19T07:22:18.930

Reputation: 1 692

0

Clojure, 35 Bytes

(print(apply str(sort(read-line))))

This will prompt the user for input, sort the characters, rejoin them back into a string and print it.

However, we can make it 3 bytes smaller if we allow the result to include quotations:

(pr(apply str(sort(read-line))))

pr is a debugging tool that prints the object it's given rather than its contents, so instead of showing hist in the console, it will show "hist".

KChaloux

Posted 2015-08-19T07:22:18.930

Reputation: 579