| Bytes | Lang | Time | Link |
|---|---|---|---|
| 106 | Python3 | 251010T000254Z | Ajax1234 |
| 090 | J | 140112T131728Z | Volatili |
| nan | 140112T194350Z | finnbar | |
| 125 | Mathematica | 140112T165104Z | ybeltuko |
| nan | Haskell | 140112T041311Z | swish |
Python3, 106 bytes
def f(s):s=s.replace(':','');return any((s[:i]*k)[:len(s)]==s for i in range(1,4)for k in range(1,len(s)))
J, 113 99 90
Probably still quite golfable.
f=:t#:[:(>:^:([:(3&g+:2&g=.[:*/]=(]$)${.)@(":@{.,3}.7":100#.1,])t#:])^:_)1+(t=.24,2$60)#.]
Takes a vector (h m s) as input, and returns a vector in the same format as output.
Examples:
f 0 0 0
0 1 0
f 4 14 14
4 14 41
f 23 59 59
0 0 0
f 3 14 15
3 14 31
Lua
I've got four different solutions, as I wasn't sure about some of the requirements.
Version 1: removal of 0s, command line input as well as os.time() backup (315)
Minimised:
z=arg if z[1] then y={hour=z[1],min=z[2],sec=z[3],day=1,month=1,year=1}end h,g,e,u=os.date,os.time(y),":",tonumber while 1 do g=g+1 b,c,d=u(h("%H",g)),u(h("%M",g)),u(h("%S",g)) a=b..c..d for x=1,#a/2 do p=1 for _ in a:gmatch(a:sub(1,x))do p=p+1 if p>math.ceil(#a/x) then print(b..e..c..e..d)return 1 end end end end
Full version with comments:
z=arg if z[1] then y={hour=z[1],min=z[2],sec=z[3],day=1,month=1,year=1}end --get command line arguments
h,g,e,u=os.date,os.time(y),":",tonumber --set up references, if command line arguments accepted use y else use current time
while 1 do
g=g+1
b,c,d=u(h("%H",g)),u(h("%M",g)),u(h("%S",g)) --get HH:MM:SS seperately (which allows removal of the zeroes with tonumber())
a=b..c..d --concat
for x=1,#a/2 do --check up to half of the string
p=1
for _ in a:gmatch(a:sub(1,x))do --for each match
p=p+1 --count number of matches
if p>math.ceil(#a/x) then print(b..e..c..e..d)return 1 end --if matches span entire string, cheer (and print in a pretty format)
end
end
end
The other versions are very similar, so I will only post the minimised versions:
Version 2: no command line input (239)
h,g,e,u=os.date,os.time(),":",tonumber while 1 do g=g+1 b,c,d=u(h("%H",g)),u(h("%M",g)),u(h("%S",g)) a=b..c..d for x=1,#a/2 do p=1 for _ in a:gmatch(a:sub(1,x))do p=p+1 if p>math.ceil(#a/x) then print(b..e..c..e..d)return 1 end end end end
Version 3: no 0 removal, with command line input (240)
z=arg if z[1] then y={hour=z[1],min=z[2],sec=z[3],day=1,month=1,year=1}end h,g=os.date,os.time(y) while 1 do g=g+1 a=h("%H%M%S",g) for x=1,3 do p=1 for _ in a:gmatch(a:sub(1,x))do p=p+1 if p>6/x then print(h("%T",g))return 1 end end end end
Version 4: none of the fancy stuff (no 0 removal or command line input) (164)
h,g=os.date,os.time() while 1 do g=g+1 a=h("%H%M%S",g) for x=1,3 do p=1 for _ in a:gmatch(a:sub(1,x))do p=p+1 if p>6/x then print(h("%T",g))return 1 end end end end
Usage instructions
In a terminal, run (versions 1 and 3)
lua interesting.lua HOURS MINUTES SECONDS
or just
lua interesting.lua
If you want it to go off the system clock.
Is there a prize for feature completeness? :P
Mathematica 125
F=Do[#~MatchQ~{#〚-1〛..,_}&&Break@#&@Partition[(i=IntegerDigits)@f[n~i~60,100],m,m,1,a_],
{n,#~(f=FromDigits)~60+1,7^6},{m,3}]&
It returns a pattern of the next interesting time:
F@{11, 11, 11}
F@{4, 14, 14}
{{1, 1, 2}, {1, 1, 2}}
{{4, 1, 4}, {4, 1, a_}}
a_ marks the end of the time.
Haskell - 227223
That's one way of doing it.
import Data.List
e _ []=False
e f s=let (h,t)=f s in t`isPrefixOf`h||h`isPrefixOf`t&&e f t
i [a,b,s]=head[t|s<-[s+1..],f<-map splitAt[1..3],let m=b+s`div`60;h=a+m`div`60;t=[h`mod`24,m`mod`60,s`mod`60],e f$concatMap show t]
Examples
λ: i [11,11,11]
[11,21,1]
λ: i [4,14,14]
[4,14,41]