楼主: newkid

[每日一题] puzzleup 2018

[复制链接]
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
211#
发表于 2018-11-8 06:41 来自手机 | 只看该作者
本帖最后由 〇〇 于 2018-11-8 07:46 编辑

10秒减01秒最小?
21-12
32-23
43-34
54-45
都一样

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
212#
发表于 2018-11-8 07:43 | 只看该作者
newkid 发表于 2018-11-2 22:17
这也能扯上“用PLSQL的”?你的逻辑太强大。

我看了一下MMA的识别,竟然把0认成9,这识别出来的程序还 ...

训练不足

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
213#
发表于 2018-11-8 08:45 | 只看该作者
本帖最后由 〇〇 于 2018-11-8 09:57 编辑

alter session set nls_date_format ='mmddyyhh24mi';

with t as (select to_char(date'2018-11-08'+ interval '1' MINUTE * (level-1),'hhmi') d from dual connect by level<24*60),
a as(select t.d from t where not exists(select 1 from (select level-1 l from dual connect by level<=10) where instr(d,l,1,2)>0 ))
select min(a.d-a1.d) from a,a a1 where a.d>a1.d and translate('a'||a.d,'a'||a1.d,'a')='a';

9

使用道具 举报

回复
论坛徽章:
8
玉兔
日期:2015-11-16 10:18:00铁扇公主
日期:2015-10-27 21:47:42九尾狐狸
日期:2015-12-11 22:31:15
214#
发表于 2018-11-8 10:03 来自手机 | 只看该作者
这也能叫puzzle? 题目中1705892346 稍微变异一下1706892345, 1706892354,咱用mma的根本就不写代码

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
215#
发表于 2018-11-8 10:44 | 只看该作者
lugionline 发表于 2018-11-8 10:03
这也能叫puzzle? 题目中1705892346 稍微变异一下1706892345, 1706892354,咱用mma的根本就不写代码

改成最大的呢

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
216#
发表于 2018-11-8 11:13 | 只看该作者
# 15
好吧,你们都口算,我还是暴力一把吧

SQL> with t as (select level -1 n from dual connect by level <=100),
  2       d as (select lpad(n,2,'0') dd from t where n between 1 and 31 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  3       m as (select lpad(n,2,'0') mm from t where n between 1 and 12 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  4       y as (select lpad(n,2,'0') yy from t where n between 0 and 99 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  5       h as (select lpad(n,2,'0') hh from t where n between 0 and 23 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  6       i as (select lpad(n,2,'0') mi from t where n between 0 and 59 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  7       s (time_num) as (
  8          select dd||mm||yy||hh||mi time_num
  9            from d,m,y,h,i
10           where instr(dd,substr(mm,1,1))=0 and instr(dd,substr(mm,2,1))=0
11             and instr(dd||mm,substr(yy,1,1))=0 and instr(dd||mm,substr(yy,2,1))=0
12             and instr(dd||mm||yy,substr(hh,1,1))=0 and instr(dd||mm||yy,substr(hh,2,1))=0
13             and instr(dd||mm||yy||hh,substr(mi,1,1))=0 and instr(dd||mm||yy||hh,substr(mi,2,1))=0
14       )
15  select min(abs(a.time_num - b.time_num))
16    from s a,s b
17   where a.time_num <> b.time_num
18  /
MIN(ABS(A.TIME_NUM-B.TIME_NUM)
------------------------------
                             9

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
217#
发表于 2018-11-8 11:15 | 只看该作者

SQL> with t as (select level -1 n from dual connect by level <=100),
  2       d as (select lpad(n,2,'0') dd from t where n between 1 and 31 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  3       m as (select lpad(n,2,'0') mm from t where n between 1 and 12 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  4       y as (select lpad(n,2,'0') yy from t where n between 0 and 99 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  5       h as (select lpad(n,2,'0') hh from t where n between 0 and 23 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  6       i as (select lpad(n,2,'0') mi from t where n between 0 and 59 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
  7       s (time_num) as (
  8          select dd||mm||yy||hh||mi time_num
  9            from d,m,y,h,i
10           where instr(dd,substr(mm,1,1))=0 and instr(dd,substr(mm,2,1))=0
11             and instr(dd||mm,substr(yy,1,1))=0 and instr(dd||mm,substr(yy,2,1))=0
12             and instr(dd||mm||yy,substr(hh,1,1))=0 and instr(dd||mm||yy,substr(hh,2,1))=0
13             and instr(dd||mm||yy||hh,substr(mi,1,1))=0 and instr(dd||mm||yy||hh,substr(mi,2,1))=0
14       )
15  select min(abs(a.time_num - b.time_num)),max(abs(a.time_num - b.time_num))
16    from s a,s b
17   where a.time_num <> b.time_num
18  /
MIN(ABS(A.TIME_NUM-B.TIME_NUM) MAX(ABS(A.TIME_NUM-B.TIME_NUM)
------------------------------ ------------------------------
                             9                     1501979184

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
218#
发表于 2018-11-8 12:02 | 只看该作者
solomon_007 发表于 2018-11-8 11:15
SQL> with t as (select level -1 n from dual connect by level

怎么保证是合法的日期

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
219#
发表于 2018-11-8 13:45 | 只看该作者
〇〇 发表于 2018-11-8 12:02
怎么保证是合法的日期

--加个日期格式验证                                                         
SQL>  with function fn_valid_date(p_str in varchar2)
  2        return int
  3        is
  4          l_date date;
  5        begin
  6          l_date := to_date(p_str,'ddmmyy');
  7          return 1;
  8        exception when others then
  9          return 0;
10        end;
11        t as (select level -1 n from dual connect by level <=100),
12        d as (select lpad(n,2,'0') dd from t where n between 1 and 31 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
13        m as (select lpad(n,2,'0') mm from t where n between 1 and 12 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
14        y as (select lpad(n,2,'0') yy from t where n between 0 and 99 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
15        h as (select lpad(n,2,'0') hh from t where n between 0 and 23 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
16        i as (select lpad(n,2,'0') mi from t where n between 0 and 59 and substr(n,1,1)<> nvl(substr(n,2,1),'x')),
17        s (time_num) as (
18           select dd||mm||yy||hh||mi time_num
19             from d,m,y,h,i
20            where instr(dd,substr(mm,1,1))=0 and instr(dd,substr(mm,2,1))=0
21              and instr(dd||mm,substr(yy,1,1))=0 and instr(dd||mm,substr(yy,2,1))=0
22              and instr(dd||mm||yy,substr(hh,1,1))=0 and instr(dd||mm||yy,substr(hh,2,1))=0
23              and instr(dd||mm||yy||hh,substr(mi,1,1))=0 and instr(dd||mm||yy||hh,substr(mi,2,1))=0
24              and fn_valid_date (dd||mm||yy) = 1
25        )
26   select min(abs(a.time_num - b.time_num)),max(abs(a.time_num - b.time_num))
27     from s a,s b
28    where a.time_num <> b.time_num
29  /
MIN(ABS(A.TIME_NUM-B.TIME_NUM) MAX(ABS(A.TIME_NUM-B.TIME_NUM)
------------------------------ ------------------------------
                             9                     1501979184               

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
220#
 楼主| 发表于 2018-11-9 03:51 | 只看该作者

因为日,月,小时的第一位都很有限,所以最大最小是很容易推理出来的。

我还是玩了一把SQL,BITAND真是好东西,速度比加菲猫快:
WITH n as (select to_char(level-1) n,power(2,level-1) b from dual connect by level<=10)
,ddmm as (
select dm,sum(b) b
   from (select to_char(date '2001-1-1'+level-1,'ddmm') dm from dual connect by level<=365)
       ,n
   where instr(dm,n)>0
group by dm having count(*)=4
)      
,hhmi as (
select hhmi,sum(b) b
  from (select to_char(date '2001-1-1'+level/(24*60),'hh24mi') hhmi from dual connect by level<24*60)
      ,n
   where instr(hhmi,n)>0
group by hhmi having count(*)=4
)
,ddmmhhmi as (
select dm,hhmi,trunc(log(2,b)) b1,round(log(2,b-power(2,trunc(log(2,b))))) b2
  from (select dm,hhmi,power(2,10)-1-ddmm.b-hhmi.b b from ddmm,hhmi
        where bitand(ddmm.b,hhmi.b)=0
       )
)
select min(str),max(str) from (
select dm||decode(n,1,b1||b2,b2||b1)||hhmi as str
  from ddmmhhmi,(select * from n where n<2)
);

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表