Everything2
Near Matches
Ignore Exact
Full Text
Everything2

grade up

created by x3n0n

(thing) by x3n0n (10.9 mon) (print)   ?   (I like it!) Fri Oct 03 2003 at 4:07:53

In the k programming language, grade up is the monadic case of <.

<x returns all of the indices of elements in x so that the index of the smallest element is first and the index of the largest element is last. (The mnemonic device here is that the small elements are on the left and the large elements are on the right, just as the point of the symbol is on the left and the wide open part is on the right.)

Grade up (and its reverse, grade down) are frequently used to sort an array; x@ (x at grade up x) returns the elements of x in sorted order.

However, the grade operators are more versatile than a by-element sort because the indices can be applied elsewhere. For example, assume that x and y are parallel arrays, where x contains keys and y contains parallel values. You would like them to be sorted the same so that a binary search for the key in x leads to a value in y; however, if you sort x, you lose the connection between x and y. But if you obtain the grade up of x and apply it to both arrays, x will be in sorted order and y's elements will have been permuted to match x. Illustrated at the k command prompt (user input indented 2 spaces, results flush left):

  x:3 5 0 2 1
  y:`three`five`zero`two`one
  x
3 5 0 2 1
  y
`three `five `zero `two `one
  x@<x
0 1 2 3 5
  y@<y
`five `one `three `two `zero
  y@<x
`zero `one `two `three `five

printable version
chaos

word up K k programming reference code
Homsar
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
What you are reading:
Ad resistance training
Chuck D's 18 Reasons why 2Pac is alive
These dead open their bodies to the living like a door
London Underground
How to hide your hard disk porn stash
John W. Campbell
Peanuts
FINALLY, a New Orleans gathering: music, mayhem, beer snobs, and Bourbon Street
Strange things homeless people have said to me
Union of Soviet Socialist Republics
Termination dust
Mumia Abu-Jamal
Alfred Hitchcock
New Writeups
Heitah
Posthumous Oscar(thing)
ignis_glaciesque
University of South Florida(place)
ignis_glaciesque
Flogstaskriket(idea)
liveforever
Caesar's last breath(idea)
dagnyswaggart
she wants to believe(personal)
antigravpussy
he doesn't know, but her eyes widen too far(thing)
dagnyswaggart
Wild tides guard her secrets(poetry)
Lord Brawl
Caesar's last breath(poetry)
locke baron
Forgotten things in space(fiction)
sitaraika
Colours(idea)
etouffee
Wild tides guard her secrets(poetry)
Lord Brawl
Dr. Horrible's Sing-Along Blog(review)
a8ksh4
regret(idea)
Heisenberg
Editor Log: July 2008(log)
sam512
halfway homes, catacombs, twilight zones(fiction)
E2 is a by-product of the existence of The Everything Development Company