无心人
发表于 2010-6-13 09:52:48
楼上,为什么不是3个5位16进制呢?
无心人
发表于 2010-6-13 10:26:29
如果是3个5位16进制数字,程序如下
import List
import Numeric (showHex)
main = do
print \$ zip [(x, y, z)|a<-, b<-\\, c<-\\, d<-\\, e<-\\,
let x1 = (16^4) * a + (16^3) * b + (16^2) * c + 16 * d + e,
let x = showHex x1 "",
f<-\\, g<-\\, h<-\\,
i<-\\, j<-\\,
let y1 = (16^4) * f + (16^3) * g + (16^2) * h + 16 * i + j,
let y = showHex y1 "",
let z1 = x1 + y1, z1 < 16^5,
let z = showHex z1 "",
(==16) \$ length \$ nub \$ z ++ x ++ y ++ "0"
]
无心人
发表于 2010-6-13 10:37:18
:dizzy:
几万个答案,被我终止了,中午没事再运行吧
〇〇
发表于 2010-6-13 11:28:24
5位太大,4位已经足够测试算法速度
〇〇
发表于 2010-6-13 11:31:48
P(12,4)=11880
P(15,5)=360360
差30倍
如果算上第一个和第二个数组合
1000倍
1秒变成15分钟
〇〇
发表于 2010-6-13 13:02:04
SQL> insert into t select x,to_number(x,'fm0xxx')n from(SELECT REPLACE(SYS_CONNECT_BY_PATH(rn,','),',') x
2 FROM (SELECT to_char(ROWNUM,'fmx') rn FROM DUAL CONNECT BY ROWNUM<=12)
3 WHERE LEVEL=4
4 CONNECT BY NOCYCLE rn<> PRIOR rn AND LEVEL<=4
5 );
已创建11880行。
已用时间:00: 00: 00.18
SQL> commit;
提交完成。
已用时间:00: 00: 00.00
SQL> exec DBMS_STATS.GATHER_TABLE_STATS('LT','T');
PL/SQL 过程已成功完成。
已用时间:00: 00: 00.11
SQL> set autot on
SQL> select count(*) from(
2select a.x||'+'||b.x||'='||to_char(a.n+b.n,'fm0xxx')s
3from t a,t b --,t c
4where a.n<to_number('6000','fm0xxx')
5 and a.n<b.n
6 AND a.n+b.n <=to_number('cba9','fm0xxx')
7 and translate('123456789abc','\$'||a.x||b.x||to_char(a.n+b.n,'fm0xxx'),'\$')is null
8 );
COUNT(*)
----------
3408
已用时间:00: 01: 45.01
〇〇
发表于 2010-6-13 15:35:50
我的代码怎么变成了数学公式?
gxqcn
发表于 2010-6-14 07:42:07
我的代码怎么变成了数学公式?
〇〇 发表于 2010-6-13 15:35 http://bbs.emath.ac.cn/images/common/back.gif
在美元符前加“\”即可屏蔽被误识别成TeX数学公式(我已经帮你修改好了)。
wayne
发表于 2010-6-14 13:12:06
22# 无心人
你知道J语言吗
一种特别精简,同时可读性特别差的语言。
感觉Haskell的可读性也不是很好(针对外行来说的),:(
〇〇
发表于 2010-6-14 14:08:26
过程式语言的写法,和SQL时间差不多
create or replace procedure pc5
as
time_before BINARY_INTEGER;
time_after BINARY_INTEGER;
TYPE t_num IS TABLE OF PLS_INTEGER INDEX BYPLS_INTEGER ;
x t_num;
a t_num;
b t_num;
c PLS_INTEGER;
c1 PLS_INTEGER;
r PLS_INTEGER;
l varchar(4);
begin
c:=0;
time_before := DBMS_UTILITY.GET_TIME;
for i in to_number('1234','fm0xxx')..to_number('cba9','fm0xxx') loop
l:=to_char(i,'fm0xxx');
if substr(l,1,1)<>substr(l,2,1)and
substr(l,2,1)<>substr(l,3,1)and
substr(l,3,1)<>substr(l,4,1)and
substr(l,1,1)<>substr(l,3,1)and
substr(l,2,1)<>substr(l,4,1)and
substr(l,1,1)<>substr(l,4,1)and
instr(l,0)=0 and instr(l,'d')=0 and instr(l,'e')=0 and instr(l,'f')=0 then
c:=c+1;
if i<to_number('cba9','fm0xxx')/2 then
a(c):=i;
c1:=c;
end if;
b(c):=i;
x(i):=c;
else
x(i):=c;
end if;
end loop;
r:=0;
dbms_output.put_line('c='||c||'c1='||c1||a(1)||b(1));
FOR I IN 1 .. c1 LOOP
FOR J IN x(a(i))+1 .. x(to_number('cba9','fm0xxx')-a(i)) LOOP
--if translate('123456789abc','\$'||to_char(a(i),'fm0xxx')||to_char(b(j),'fm0xxx')||to_char(a(i)+b(j),'fm0xxx'),'\$')is null then
--dbms_output.put_line(to_char(a(i),'fm0xxx')||to_char(b(j),'fm0xxx')||to_char(a(i)+b(j),'fm0xxx'));
--NULL;
l:=to_char(a(i)+b(j),'fm0xxx');
if substr(l,1,1)<>substr(l,2,1)and
substr(l,2,1)<>substr(l,3,1)and
substr(l,3,1)<>substr(l,4,1)and
substr(l,1,1)<>substr(l,3,1)and
substr(l,2,1)<>substr(l,4,1)and
substr(l,1,1)<>substr(l,4,1)and
instr(l,0)=0 and instr(l,'d')=0 and instr(l,'e')=0 and instr(l,'f')=0
--length(translate('0def','\$'||l,'\$'))=4
and length(translate(to_char(a(i),'fm0xxx'),'\$'||l,'\$'))=4
and length(translate(to_char(b(j),'fm0xxx'),'\$'||l,'\$'))=4
and length(translate(to_char(a(i),'fm0xxx'),'\$'||to_char(b(j),'fm0xxx'),'\$'))=4 then
r:=r+1;
--dbms_output.put_line(to_char(a(i),'fm0xxx')||to_char(b(j),'fm0xxx')||to_char(a(i)+b(j),'fm0xxx'));
end if;
end loop;
if r>=100 then
exit;
end if;
end loop;
time_after := DBMS_UTILITY.GET_TIME;
DBMS_OUTPUT.PUT_LINE ('output:'||(time_after - time_before)||'rows:'||r);
end;
/