-4
Sorting a list would make a pretty fun code-golf challenge, but all the builtins make it boring! Its no fun when you spend all of your time golfing a function and then you see that someone else has a shorter answer just using a builtin!
The best way to solve this problem is to ban builtins, but no challenge has gone quite far enough! Most challenges only ban one or two builtins. We are going to ban them all!
Ok lets stop being sardonic for a moment.
Your task will be to write a function that takes a list of integers and returns a sorted version of the same list. You are to do this without the use of builtins
What are builtins?
To keep ourselves from having to navigate edge case hell we are going to limit answers to Haskell (sorry if Haskell is not your favorite language). We are going to define a builtin as any named function that is not defined in your code. We are going to say that symbolic operators, (+)
, (:)
, etc. are not builtin functions. This applies both to prelude and any libraries that are imported.
What does it mean to use?
Before anyone tries to get smart with me, using a function is using a function. Whether or not the function is named in your source code is irrelevant (this is not restricted-source), if you make calls to the function without naming it that is also considered cheating. That being said calls to a function are not the only form of use, you shouldn't name a builtin function in your code even if you don't call it (I don't know why you would want to do that but I'm not taking any risks).
Scoring
This is code-golf so you should aim to do this in as few bytes as possible. However since different algorithms are not going to be competitive, (merge sort answers are probably going to be longer than insertion sort answers) I would like this to be considered a competition among individual algorithms, just as normal code golf is a competition among individual languages. For that reason I would like you to name your algorithm used in your header instead of the language. If you don't know the name feel free to put Unknown.
1Related (sort list without sort builtin) – Okx – 2017-07-08T14:35:22.557
Well that did not go well so I gave a pity upvote – Christopher – 2017-07-08T14:46:29.950
1I would have upvoted this if the challenge was not limited to a specific language. – user41805 – 2017-07-08T15:14:14.400
@KritixiLithos I would have like to made it open to all languages, however the definition of builtin would have needed to be extremely complex. I figured it was best to constrain it to one language rather than have a broken challenge. Maybe I should have not asked the question. But I think its pretty fun if you give it a try. – Post Rock Garf Hunter – 2017-07-08T15:16:00.873
as we are talking about Haskell only, what about builtin values? – nimi – 2017-07-08T15:19:42.610
@WheatWizard Idea: allow other languages to join in but they are marked as NC – Christopher – 2017-07-08T15:19:48.187
@nimi I think builtin values are fine. – Post Rock Garf Hunter – 2017-07-08T15:21:24.377
@Christopher The problem with other languages is that the challenge gets very out of control and the definition becomes untenable, not that I don't like them. I don't think allowing NC answers would improve the challenge. – Post Rock Garf Hunter – 2017-07-08T15:22:24.917
Good point imagine jelly without builtins – Christopher – 2017-07-08T15:22:47.463
1What does the list contain? Arbitrary
Ord
types?Positive integers? Arbitrary types and we get an ordering function? – Laikoni – 2017-07-08T15:24:20.193@Laikoni Oh duh I forgot to add that. It will just be integers. Either
Int
orInteger
type. – Post Rock Garf Hunter – 2017-07-08T15:25:37.713@WheatWizard I think that if you allow functional programming languages that aren't designed for golfing (e.g. Python, Java, C etc.) where the definition of a builtin matches your current one, then the challenge would be better. If you do this, however, I would recommend having a list of languages which people can suggest changes to. – caird coinheringaahing – 2017-07-08T16:22:29.743
@cairdcoinheringaahing Believe it or not this was originally a python challenge, but I found it too difficult to get a good definition of builtin with member functions. I would also like to point out that none of the three languages you mentioned are functional :P, but I suppose that doesn't matter. – Post Rock Garf Hunter – 2017-07-08T16:29:03.413
Sorry, Wheat but I've downvoted this for the language restriction. The shame about it is that it would be an interesting challenge otherwise. – Shaggy – 2017-07-09T22:30:43.207
@Shaggy If you or anyone would like to post a version that is open to all languages they are free to do so. However it is my belief that such a challenge would turn out rather poorly and I am very satisfied with the current answers so I will not be opening this challenge to additional languages. I've already expressed why I believe this in previous comments so I won't go into further detail. – Post Rock Garf Hunter – 2017-07-10T01:36:15.300