See it; Say it; Sort of sorted-ish

Fan-Shaped Display of Intricate Playing Cards
36
0
  • Squishy Plushie's avatar Artist
    Squishy Pl...
  • Prompt
    Read prompt
  • DDG Model
    DaVinci2
  • Access
    Public
  • Created
    18h ago
  • Try

More about See it; Say it; Sort of sorted-ish

{* #input : input >[.gn. input]> output *}
This algorithm, written in ::SHE+ILA::, will (very inefficiently) sort the table "input" giving the table "output". Its behaviour is worse than order n^2, but hey if you only want to sort 20 or less items it doesn't matter.
Operation: .gn. is the "find minimum" operator ("grade minimum" -- there is a similar op .gx. "grade maximum"), which returns the index of the smallest item in a list, and then the FBI operator ">[n]>" (extract from)" extracts that item from the input list, appending it onto "output". The loop construct "{* condition : action *}" repeatedly does "action" while "condition" is true, and "#input" is the number of elements in "input", which is nonzero (true) while there are stlll items to be processed. (FBI = Fundamental Buffer Interface, the "glue" between SHE and ILA)
In summary, "Repeatedly move the smallest item in "input" and put it into "output", until there aren't any more". The inefficiency comes from repeatedly finding the minimum item, which requires scanning through "input" repeatedly. Hint : it would be better to scan through "input" only once, and produce a table of offsets in ascending order, and then apply this table of offsets to give "output". Something like "output <:: input[.gu. input]" actually (where .gu. is the "grade up" operator, which produces a table of indices, which then selects á la APL the appropriate elements from "input", giving "output". But hey, then there wouldn't be as much fun :)

Comments


Loading Dream Comments...

Discover more dreams from this artist