When translated to J, the Khan academy approach implemented using
floating point numbers seems about 60 times faster, and 17 times more
compact than using exact arithmetic.
365 (^ %~ [ %&!&x: -) 30
0.293684
365 (^ %~ [: */ -@] {. 1 + i.@[) 30
0.293684
ts '365 (^ %~ [ %&!&x: -) 30'
0.00117391 122944
ts '365 (^ %~ [: */ -@] {. 1 + i.@[) 30'
1.82348e_5 6848
And the difference between the results is comparable to the least
significant bit in a 64 bit floating point number of this magnitude
(probably a two bit difference).
365 ((^ %~ [ %&!&x: -) -^ %~ [: */ -@] {. 1 + i.@[) 30
_5.55112e_17
0.25 0.293684 0.5* 2^_53
2.77556e_17 3.26055e_17 5.55112e_17
FYI,
--
Raul
On Tue, Feb 14, 2012 at 2:54 PM, Skip Cave <[email protected]> wrote:
> Never mind, I figured it out...
>
> (365 ^ 30) %~ (!365x) % !365x - 30
> 0.293684
>
> Skip
>
>
> On Tue, Feb 14, 2012 at 1:35 PM, Skip Cave <[email protected]> wrote:
>
>> I find it interesting that the TI calculator used by the Khan Academy
>> teacher solved the birthday problem by directly calculating the factorials
>> of 365 and 365-30. In J I had to reduce the fraction first because 365
>> factorial shows as infinity in J , Can one solve Khan's birthday problem by
>> using extended arithmetic and not have to reduce the factorials?
>>
>> Skip
>>
>>
>> On Tue, Feb 14, 2012 at 1:03 PM, Skip Cave <[email protected]>wrote:
>>
>>> Here's a one-liner direct-execution answer for the Khan Academy birthday
>>> problem:
>>> (365 ^ 30) %~ */ _30 {. >: i. 365
>>> 0.293684
>>>
>>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm