Code Monkey home page Code Monkey logo

bad-sorting's Introduction

Bad-Sorting

Status GitHub Issues GitHub Pull Requests License


Table of Contents


About

Tired of your wimpy sorting algorithms getting the job done too darn fast? Or maybe you're fed up of reaching for that elusive O(1) algorithim. Well you should try Bad-Sorting! the npm package for those who like their sorts served with the heat death of the universe!

This glorious collection of terrible, horrible, no good, very bad sorting techniques (affectionately called "algorithms") is guaranteed to modify your data. For better or for worse

Why Bad-Sorting?

  • Because why not? Normality is so boring.
  • Need a good laugh? Watch your CPU cry as it wrestles with bogosort.
  • Busy day? Multi-Task as your computer sleep sorts!

Installing

For Installation With NPM

npm i @yoloftw/bad-sorting

Usage

Sure, you installed Bad-Sorting, but how do you use it? Don't worry, I've got you covered.


First things first you've got pick your poison and import it into your project.

const { BogoSort } = require('@yoloftw/bad-sorting');

The next step is to question your life choises that brought you to this moment in time.


Last but not least SORT

let arr = [7, 2, 20, 5, 15, 3];

let sorted = BogoSort(arr);

console.log(sorted);
//expected output: [2, 3, 5, 7, 15, 20]

Bogo Sort

Ah, Bogo Sort, the algorithm that embodies the spirit of "throw it at the wall and see if it sticks". Bogo Sort does away with the hard work of itterating over an array and offloads the sorting to the checking algorithim by randomising the array until it is sorted. Heres how to use it.

const { BogoSort } = require('@yoloftw/bad-sorting');

let arr = [5, 18, 3, 8, 14, 2, 13, 16];

let sorted = BogoSort(arr);

console.log(sorted);
//expected output: [2, 3, 5, 8, 13, 14, 16, 18]

Bogosort boasts a time complexity of O(n * n!), which basically means it could take longer than the life expectancy of the universe to sort a moderately sized list.


Communism Sort

In a communist array everyone is equal. Communism Sort redistributes the wealth to the less fortunate elements resulting in an array that is perfectly equal and therefore sorted.

const { CommunismSort } = require('@yoloftw/bad-sorting');

let arr = [1, 6, 4, 10, 13];

let sorted = CommunismSort(arr);

console.log(sorted);
//expected output: [ 6.8, 6.8, 6.8, 6.8, 6.8 ]

Communism Sort achieves a time complexity of O(n), a testament to the efficiency of collective action!


Intelligent Sort

Credit Goes to David Morgan-Mar's Esoteric Algorithims page

From the Intelligent Sort page

The probability of the original input list being in the exact order it's in is 1/(n!). There is such a small likelihood of this that it's clearly absurd to say that this happened by chance, so it must have been consciously put in that order by an intelligent Sorter. Therefore it's safe to assume that it's already optimally Sorted in some way that transcends our naïve mortal understanding of "ascending order". Any attempt to change that order to conform to our own preconceptions would actually make it less sorted.

const { IntelligentSort } = require('@yoloftw/bad-sorting');

let arr = [13, 16, 4, 8, 3, 14, 2];

let sorted = IntelligentSort(arr);

console.log(sorted);
//expected output: [13, 16, 4, 8, 3, 14, 2]

Intelligent Sort is one of those elusive constant time algorithims and therefore has the gift of O(1) time complexity.


Miracle Sort

Miracle Sort embraces the power of chance (and cosmic rays) to achieve the impossible. Miracle Sort waits for cosmic rays to flip enough bits in memory for the array to be sorted.

const { MiracleSort } = require('@yoloftw/bad-sorting');

let arr = [13, 16, 4, 8, 3, 14, 2];

let sorted = MiracleSort(arr);

console.log(sorted);
//expected output: [2, 3, 4, 8, 13, 14, 16]

Due to Miracle Sort waiting for, well, a miracle the time complexity is a staggering O(∞).


Quantum Bogo Sort

Quantum Bogo Sort assumes that Hugh Everett guy was correct that that there are infact infinite parrallel universes. Quantum Bogo Sort checks if the array is sorted and if not destroys the universe. The only remaining universe is where the array is sorted

const { QuantumBogoSort } = require('@yoloftw/bad-sorting');

let arr = [6, 19, 5, 1, 3, 8];

let sorted = QuantumBogoSort(arr);

console.log(sorted);
//expected output: [1, 3, 5, 6, 8, 19]

In the universe where the array was sorted, it was only checked once. Therefore we have another example of a coverted O(1) algorithim


Sleep Sort

Sleep Sort takes a laid-back approach to sorting. Instead of furiously comparing elements it takes a step back and waits for the problem to sort itself.

const { SleepSort } = require('@yoloftw/bad-sorting');

let arr = [7, 2, 20, 5, 15, 3];

let sorted = SleepSort(arr);

console.log(sorted);
//expected output: [2, 3, 5, 7, 15, 20]

Sleep Sorts time complexity is a tough one as unlike other algorithims that are dependent on array size, Sleep Sort is dependent on the biggest element. Due to this Sleep Sorts time complexity is O(max(input))


Disclaimer

These sorting systems utilize highly experimental and down right questionable "algorithms". Potential side effects include interdimensional tears, sentient toaster uprisings, and a mild case of the Mondays. Use at your own risk. We're not responsible for any existential crises caused by questioning the nature of sorting after using Bad-Sorting.


Authors

bad-sorting's People

Contributors

yoloftw avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

connorb175

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.