How to resolve the algorithm Sorting algorithms/Patience sort step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sorting algorithms/Patience sort step by step in the Quackery programming language

Table of Contents

Problem Statement

Sort an array of numbers (of any convenient size) into ascending order using   Patience sorting.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sorting algorithms/Patience sort step by step in the Quackery programming language

Source code in the quackery programming language

  [ dip [ 0 over size rot ]
    nested bsearchwith
      [ -1 peek
        dip [ -1 peek ] > ]
    drop ]                       is searchpiles ( [ n --> n )

  [ dup size dup 1 = iff
    [ drop 0 peek ] done
    2 / split
    recurse swap recurse
    merge ]                      is k-merge     (   [ --> [ )

  [ 1 split dip nested
    witheach
      [ 2dup dip dup
        searchpiles
        over size over = iff
          [ 2drop
            nested nested join ]
        else
          [ dup dip
              [ peek swap join
                swap ]
            poke ] ]
    k-merge ]                    is patience-sort ( [ --> [ )


  ' [ 0 1 2 3 4 5 6 7 8 9 ]
  shuffle dup echo cr 
  patience-sort echo

  

You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Literals/String step by step in the Python programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the MIPS Assembly programming language
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the Racket programming language
You may also check:How to resolve the algorithm Evaluate binomial coefficients step by step in the МК-61/52 programming language