Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Genius sorting algorithm: Sleep sort

Name: Anonymous 2011-01-20 12:22

Man, am I a genius. Check out this sorting algorithm I just invented.


#!/bin/bash
function f() {
    sleep "$1"
    echo "$1"
}
while [ -n "$1" ]
do
    f "$1" &
    shift
done
wait


example usage:
./sleepsort.bash 5 3 6 3 6 3 1 4 7

Name: Anonymous 2011-03-30 16:47

THIS IS A MESSAGE FROM THE SUSSIX DEV TEAM (ME)

/*
 * Inspired by the valiant /prog/lodtyes
 * one of my personalities wrote an OMP
 * implementation.
 *
 * Since we are currently training SCC
 * (SCC Compiles C) we currently have to
 * use GCC to compile it.
 */

/*
 * @file sleepsort.c
 * @brief sorts numbers
 *
 * @compile gcc sleepsort.c -fopenmp -o sleepsort
 *
 * @author Gerald Jay Sussman (Massachvsetts Institvte of Technology)
 *
 * Copyright (C) 2011 Gerald Jay Sussman and the Massachvsetts
 * Institvte of Technology. All rights reserved.
 *
 * The new BSD License is applied to this software, see LICENSE.txt
 */

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

int main(int argc, char **argv) {
  int i;

  omp_set_num_threads(argc);

#pragma omp parallel for
  for (i = 0; i < argc - 1; i++) {
    long int this = atol(argv[i+1]);

    sleep(this);

    printf("%ld\n", this);
    fflush(stdout);
  }

  return 0;
}


THIS HAS BEEN A MESSAGE FROM THE SUSSIX DEV TEAM (ME)

Newer Posts