Skip to content

Instantly share code, notes, and snippets.

@jrandom
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save jrandom/b4dd0d0f8200217c44d1 to your computer and use it in GitHub Desktop.

Select an option

Save jrandom/b4dd0d0f8200217c44d1 to your computer and use it in GitHub Desktop.

Revisions

  1. jrandom revised this gist Dec 25, 2014. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions gistfile1.cpp
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,14 @@ template < typename container_t >

    void BogoSort( container_t & data )
    {
    using std::begin;
    using std::end;

    std::random_device rd;
    std::mt19937 ung( rd() );

    while( !std::is_sorted(std::begin(data), std::end(data)) )
    while( !std::is_sorted(begin(data), end(data)) )
    {
    std::shuffle(std::begin(data), std::end(data), ung);
    std::shuffle(begin(data), end(data), ung);
    }
    }
  2. jrandom revised this gist Dec 24, 2014. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions gistfile1.cpp
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,12 @@
    template < typename value_t >
    template < typename container_t >

    void BogoSort( std::vector< value_t > & data )
    void BogoSort( container_t & data )
    {
    while( !std::is_sorted(data.cbegin(), data.cend()) )
    std::random_device rd;
    std::mt19937 ung( rd() );

    while( !std::is_sorted(std::begin(data), std::end(data)) )
    {
    std::random_shuffle(data.begin(), data.end());
    std::shuffle(std::begin(data), std::end(data), ung);
    }
    }
  3. jrandom created this gist Dec 23, 2014.
    9 changes: 9 additions & 0 deletions gistfile1.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    template < typename value_t >

    void BogoSort( std::vector< value_t > & data )
    {
    while( !std::is_sorted(data.cbegin(), data.cend()) )
    {
    std::random_shuffle(data.begin(), data.end());
    }
    }