5 ts '([:*./ >:@i.)"0 y'[y=:[EMAIL PROTECTED] 1000x
0.28845623 188992
is not an optimal solution, see
5 ts '([:*./&.|. >:@i.)"0 y'
0.20137625 189504
(([:*./ >:@i.)"0 -: ([:*./&.|. >:@i.)"0) y
1
Nevertheless, the first ([:*./ >:@i.)"0 will serve as the benchmark.
(You may use any y (of natural numbers) you like.)
Solutions foo0, foo1, ... will be ranked according to
(\:,.]) 2 rsd ({.%"1 ]) 5 ts&'([:*./ >:@i.)"0 y';'foo0 y';'foo1 y';'....'
with
ts=: 6!:2 , 7!:[EMAIL PROTECTED]
and with
rsd=: 4 : 0 NB. round y to x significant digits
z0=. (<: x) + -@<.@(10&^.)y
z1=. 0.5<[EMAIL PROTECTED] y (*10&^) z0
(10^- z0)* z1
)
Of course one should have
(fooX -: ([:*./ >:@i.)"0) y
1
(Perhaps, under http://www.jsoftware.com/jwiki/Showcase there should be a
subpage Competitions.)
Here is my try:
y=:[EMAIL PROTECTED] 1000x
(\:,.]) 2 rsd ({.%"1 ]) 5 ts&'([:*./ >:@i.)"0 y';'([:*./&.|. >:@i.)"0
y';'lcm y' NB. wrap around!
2 1 1
1 1.3 1
0 90 0.45
(lcm -: ([:*./ >:@i.)"0) y
1
y=:[EMAIL PROTECTED] 10000x
(\:,.]) 2 rsd ({.%"1 ]) 5 ts&'([:*./ >:@i.)"0 y';'([:*./&.|. >:@i.)"0
y';'lcm y' NB. wrap around!
2 1 1
1 1.6 1
0 280 0.11
(lcm -: ([:*./ >:@i.)"0) y
1
lcm is defined by
lcm=: 3 : 0
z0=. i.&.(_1&p:)1x+m=: >./, y
NB. primes less than max y
z1=. |:/:~;(<@([,.~ (^ >:@i.@>:))"0 <.@:^.&m) z0
NB. prime powers with corresponding primes
z2=. ({.,: [:*/\.&.|. {:) z1
NB. prime powers with corresponding ([:*./ >:@i.)
y(((I.~- [EMAIL PROTECTED]){.){ {:@]) z2
NB. ([:*./ >:@i.)"0 y
)
R.E. Boss
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm