There is programming puzzle on Programming Praxis for which I volunteered a 
simple J solution, as part of my New Year's resolution to renew interest in and 
help evangelize J.

http://programmingpraxis.com/2010/12/07/ullmans-puzzle/

> This puzzle is due to Jeffrey Ullman:
> 
> Given a list of n real numbers, a real number t, and an integer k, determine 
> if there exists a k-element subset of the original list of n real numbers 
> that is less than t.
> 
> For instance, given the list of 25 real numbers 18.1, 55.1, 91.2, 74.6, 73.0, 
> 85.9, 73.9, 81.4, 87.1, 49.3, 88.8, 5.7, 26.3, 7.1, 58.2, 31.7, 5.8, 76.9, 
> 16.5, 8.1, 48.3, 6.8, 92.4, 83.0, 19.6, t = 98.2 and k = 3, the 3-element 
> subset 31.7, 16.5 and 19.6 sums to 67.8, which is less than 98.2, so the 
> result is true.
> 
> This is a puzzle, so you’re not allowed to look at the suggested solution 
> until you have your own solution.
> 
> Your task is to write a function that makes that determination. 


My contribution is at 
http://programmingpraxis.com/2010/12/07/ullmans-puzzle/#comment-2267

> up =: dyad def 0
> NB. LIMIT K up DATA
> ({.x)>+/({:x){.(/:{])y
> )

The tacit expression is not very pretty, and so I didn't even go there for this 
audience.

-- 
Alan

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to