Talk:NYCJUG/2023-06-13

From J Wiki
Jump to navigation Jump to search

It's perhaps worth noting that since qsort uses random pivots, running it multiple times is sufficient to show the "different paths to the same result" issue:

   qsort=: (($:@(<#[) ; (=#[) ,&< $:@(>#[)) ({~ ?@#)) ^: (1<#)
   V=: 10?10
   qsort V
┌─────────────────────────────────────┬─┬┐
│┌┬─┬────────────────────────────────┐│9││
│││0│┌───────────────────────────┬─┬┐││ ││
│││ ││┌──────────────────────┬─┬┐│8││││ ││
│││ │││┌────────────────┬─┬─┐│7│││ ││││ ││
│││ ││││┌┬─┬───────────┐│56││ │││ ││││ ││
│││ ││││││1│┌──────┬─┬┐││  ││ │││ ││││ ││
│││ ││││││ ││┌─┬─┬┐│4││││  ││ │││ ││││ ││
│││ ││││││ │││23│││ ││││  ││ │││ ││││ ││
│││ ││││││ ││└─┴─┴┘│ ││││  ││ │││ ││││ ││
│││ ││││││ │└──────┴─┴┘││  ││ │││ ││││ ││
│││ ││││└┴─┴───────────┘│  ││ │││ ││││ ││
│││ │││└────────────────┴─┴─┘│ │││ ││││ ││
│││ ││└──────────────────────┴─┴┘│ ││││ ││
│││ │└───────────────────────────┴─┴┘││ ││
│└┴─┴────────────────────────────────┘│ ││
└─────────────────────────────────────┴─┴┘
   qsort V
┌───────────┬─┬──────────────────┐
│┌──────┬─┬┐│3│┌─┬─┬────────────┐│
││┌┬─┬─┐│2│││ ││45│┌─┬─┬──────┐││
││││01││ │││ ││  ││67│┌─┬─┬┐│││
││└┴─┴─┘│ │││ ││  ││  ││89│││││
│└──────┴─┴┘│ ││  ││  │└─┴─┴┘│││
            ││  │└─┴─┴──────┘││
            │└─┴─┴────────────┘│
└───────────┴─┴──────────────────┘