( scratchpad - auto ) \ largest-value see USING: kernel math math.combinatorics sequences ; IN: math.combinatorics.private : largest-value ( a b x -- v ) [ [ nCk ] dip <= ] 2curry find-last nip ; ( scratchpad - auto ) 10 5 0 largest-value --- Data stack: 4 ( scratchpad - auto ) Command: refresh-all Loading resource:basis/math/combinatorics/combinatorics.factor --- Data stack: 4 ( scratchpad - auto ) \ largest-value see USING: binary-search kernel math.combinatorics math.order ; IN: math.combinatorics.private : largest-value ( a b x -- v ) [ [ nCk ] dip >=< ] 2curry search nip ; --- Data stack: 4 ( scratchpad - auto ) 10 5 0 largest-value --- Data stack: 4 2 ( scratchpad - auto ) 10 5 0 '[ _ nCk _ >=< ] search nip --- Data stack: 4 2 f ! I've defined largest-value as: ! : largest-value ( a b x -- v ) ! '[ _ nCk _ <= ] find-last nip ; ! ...this gives the desired result of 4. I was hoping to make it into a binary ! search to make things faster, but it has to find the largest value 'v' that ! is less than 'a', and so that Choose(v,b) is less than or equal to x ! The binary search is almost working as planned written as: ! : largest-value ( a b x -- v ) ! '[ _ nCk _ >=< ] search nip ; ! ...but for some reason when the function is compiled, it returns 2, and when ! run in the listener, it returns f. Not sure why there's an inconsistency