Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Here's the challenge:

Order an Array from the Lowest to the Highest digit from a number, which is conveniently represented in an array. The trick here is that you cannot use any array methods, nor other sorts of loopholes. You have to stick to the basics (Arrays, Mathematical Operators /not Math Class/, no recursion. You can use any variable type of your chosing (eg: String, int), and evidently repetitive cicles, you can't however use "advanced" expressions, such as ArrayList or ParseInt for Java)

For an user input of 2014, the output should be 0124 Yes, the 0 must be represented

Scoring Method

Simply a codegolf challenge, shortest code wins.

Origin of the challenge:

I've been reading quite a bit of codegolf for a while, and decided to create a challenge based on an issue that I had with java to order the digits of a number. I did manage to get a solution, but I wasn't quite pleased with it (it took a significant ammount of bytes which I wanted to avoid), I am interested in creative, short awnsers to counter my own =)

share|improve this question

closed as unclear what you're asking by durron597, Tony H., TheDoctor, Geobits, squeamish ossifrage May 10 at 19:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Just to clarify, the program must be valid for any integer, 2014 was an example. –  Oak May 10 at 17:17
    
And evidently, any downvote without a plight explanation is the same as flipping me the finger, which I find rude. –  Oak May 10 at 17:24
5  
Can't speak for anyone else, but in my opinion, as code-golf sorting challenges go this is really boring. And thinking that recursion is not "basic" suggests that you may be just beginning to program; believe me, it is on the same level of the basic tool box as looping. Moreover, the limitations and scoring modifiers make it look like you are trying to use CodeGolf SE as a mechanical turk willing to do your homework. And people can react badly to that impression no matter the truth or falsity of it. –  dmckee May 10 at 17:36
1  
Scoring item 1 and 2 are unnecessary. For 3 and 4, I highly doubt any golfed submission will reach over 500 bytes. 5 seems strange and put in there for no reason, and 6 makes very little sense at all - why does Java get priority over, say, C++? 7 just begs for someone to answer "foobarbaz in Perl, it doesn't work but I still get the first submission bonus" or something. Furthermore, typically challenges here do not have deadlines. –  Doorknob May 10 at 18:08
1  
A more ideal method would be plain code-golf: shortest code wins. You may also want to clarify what "the basics" are - that's extremely underspecified at the moment. –  Doorknob May 10 at 18:24
show 7 more comments

1 Answer

up vote 1 down vote accepted

In Racket, without explicit recursion :-P

(define Y (lambda (f) ((lambda (x) (x x)) (lambda (x) (lambda (y) ((f (x x)) y))))))
(define a (Y (lambda (f) (lambda (c) (cond ((null? c) c)
                                           ((null? (cdr c)) c)
                                           ((> (car c) (cadr c))
                                            (f (cons (cadr c) (cons (car c) (cddr c)))))
                                           (#t (cons (car c) (f (cdr c)))))))))
(define b (Y (lambda (f) (lambda (c) (let ((s (a c))) (if (equal? s c) c (f s)))))))

Call:

(b '(2 0 1 4))

where

  • Y is the Y-Combinator
  • a is one iteration of Bubble Sort
  • b is the bubble sort algorithm
share|improve this answer
    
Guess I can't really accept other awnsers –  Oak May 10 at 20:49
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.