# -*- mode: icon -*- # $Id: hash.icon,v 1.1 2000/12/18 03:10:54 doug Exp $ # http://www.bagley.org/~doug/shootout/ procedure hexstring(i) local s if i = 0 then s := "0" else { s := "" while i ~= 0 do { s := "0123456789abcdef"[iand(i,15) + 1] || s i := ishift(i,-4) } } return s end procedure main(argv) local n local X local c local i n := argv[1] | 1 X := table(0) c := 0 every i := 1 to n do { X[hexstring(i)] := i } every i := n to 1 by -1 do { if (member(X,string(i))) then { c +:= 1 } } write(c) end