Is it really time?

27

3

A time in the format hhMMss is represented by six numbers in the range 0..9 (e.g.100203 for 3 seconds after 2 minutes after 10am (10:02.03), or 155603 for three seconds after 56 minutes after 3pm (15:56.03).

Treating these times as integers, these numbers are therefore in the range 000000 to 235959; but not all numbers in that range are valid times.

Normally, though, integers aren't represented with leading 0s, right?

So, this challenge is to take a numeric input (without leading 0s), and say whether it represents a proper time or not when the leading 0s are put back.

Input

Any integer, as a string or an integer type, in the range 0..235959 inclusive. all numbers as strings will be input with no leading 0s (e.g. 2400, not 002400). The time 000000 maps to 0; or exceptionally as . Inputs outside of this range should return Falsy, but there is no requirement that they are supported.

Output

Truthy/Falsy value - by which I mean there must be a consistent distinction in the output between True and False - e.g. True could be output as 1 and False could be any other output (or even a variable output) - as long as it can be documented how to tell what is True and what is not.

More Challenge Details

Given the input integer, figure out if the number represents a time (truthy) or not (falsy).

A number represents a time if a time (hhMMss) with leading 0s removed is the same as the number.

e.g. 00:00.24 is represented by 24
e.g. 00:06.51 is represented by 651 e.g. 00:16.06 is represented by 1606
e.g. 05:24.00 is represented by 52400
e.g. 17:25.33 is represented by 172533

There are therefore some numbers that can't represent times:

e.g. 7520 - this can't represent hhMMss because 00:75:20 isn't a time

As a general rule, the valid numbers fall into the pattern:

trimLeadingZeros([00..23][00..59][00..59]);

The following numbers are the entire set of inputs and the required answers for this challenge

seconds only (e.g. 00:00.ss, with punctuation and leading 0s removed, -> ss)
0 to 59 - Truthy
60 to 99 - Falsy

minutes and seconds (e.g. 00:MM.ss, with punctuation and leading zeros removed, -> MMss)
100 to 159 - Truthy
160 to 199 - Falsy
etc, up to:
2300 to 2359 - Truthy
2360 to 2399 - Falsy
2400 to 2459 - Truthy
2460 to 2499 - Falsy
etc, up to:
5900 to 5959 - Truthy
5960 to 9999 - Falsy

hours 0..9, minutes and seconds (e.g. 0h:MM.ss with punctuation and leading zeros removed -> hMMss)

10000 to 10059 - Truthy
10060 to 10099 - Falsy
etc, up to:
15800 to 15859 - Truthy
15860 to 15899 - Falsy
15900 to 15959 - Truthy
15960 to 19999 - Falsy

20000 to 20059 - Truthy
20060 to 20099 - Falsy
20100 to 20159 - Truthy
20160 to 20199 - Falsy
etc, up to:
25800 to 25859 - Truthy
25860 to 25899 - Falsy
25900 to 25959 - Truthy
25960 to 25999 - Falsy
etc, up to:
95800 to 95859 - Truthy
95860 to 95899 - Falsy
95900 to 95959 - Truthy
95960 to 99999 - Falsy

hours 10..23, minutes and seconds (e.g. hh:MM.ss with punctuation and leading zeros removed -> hhMMss)

100000 to 100059 - Truthy
100060 to 100099 - Falsy
100100 to 100159 - Truthy
100160 to 100199 - Falsy
etc, up to:
105800 to 105859 - Truthy
105860 to 105899 - Falsy
105900 to 105959 - Truthy
105960 to 109999 - Falsy

This pattern is then repeated up to:

235900 to 235959 - Truthy
(236000 onwards - Falsy, if supported by program)

leading 0s must be truncated in the input, if strings are used.

Code golf, so least bytes wins - usual rules apply

simonalexander2005

Posted 2020-02-25T14:34:15.307

Reputation: 1 157

2I just can't find the left-pad built-in ... – a'_' – 2020-02-25T14:40:13.817

Related (the portion about verifying whether a 6-digit number is a valid time) – Kevin Cruijssen – 2020-02-25T15:04:55.307

5You say input is in the range 0..235959 inclusive, but then you have a test case for 236000 onwards. You should clarify what's the actual range of inputs we need to support (I'd suggest 0..999999). – Grimmy – 2020-02-25T15:05:23.843

@Grimmy if your program accepts inputs outside of the range 0..235959 they should be falsy, but the specification doesn't require your program to be able to deal with inputs outside of that range – simonalexander2005 – 2020-02-25T15:11:11.803

9It's probably too late now, but I think this challenge would be more fun if the range could be beyond the 235959 and possibly even beyond the 999999. Now it simply boils down to (in pseudo-code) max(hh,mm,ss)<60 and we can just ignore the check on hours, since it's guaranteed to be valid. – Kevin Cruijssen – 2020-02-25T16:42:10.247

Strictly speaking as long as it can be documented how to tell what is True and what is not means we can no-op. I believe you really want outputs to be in one of these four pairs: truthy vs falsey; falsey vs truthy; unique value, x vs anything but x; anything but x vs unique value x. – Jonathan Allan – 2020-02-25T18:40:58.950

2This is assuming a day with no leap second, or possibly TAI. For example, 2016-12-31 18:59:60 US/Eastern is a valid time. – aschepler – 2020-02-26T06:37:05.627

Answers

14

Python, 45 43 38 27 bytes

For inputs up until 239999:

lambda n:n/100%100<60>n%100

You can try it online! Thanks @Jitse and @Scurpulose for saving me several bytes ;)

For inputs above 239999 go with 36 bytes:

lambda n:n/100%100<60>n%100<60>n/4e3

RGS

Posted 2020-02-25T14:34:15.307

Reputation: 5 047

@ElPedro thanks!! :) May be still more golfable – RGS – 2020-02-25T15:14:43.327

Also, the Python 2 solution works in Python 3, too. Float instead of int division does not matter. – Jitse – 2020-02-25T16:10:58.200

Can save some more bytes by using n/4100 instead of n/c**2*2.5. Try it online!

– Surculose Sputum – 2020-02-25T16:15:05.707

@SurculoseSputum good find! But divide by 4000 then, as 100**2/2.5 = 4000. As variable c is now redundant, this can be reduced to lambda n:max(n%100,n/100%100,n/4e3)<60 for 38 bytes. – Jitse – 2020-02-25T16:18:58.583

@Jitse Nice golf! For some reason I thought that245959 was a valid time, hence the 4100 :( – Surculose Sputum – 2020-02-25T16:28:07.300

Note that the the program doesn't have to support input greater than 235959, so we can do away with the hour check. – Surculose Sputum – 2020-02-25T17:27:20.197

1Even keeping the hour check, lambda n:n%100<60>n/100%100<60>n/4e3 is 2 bytes shorter – Poon Levi – 2020-02-25T18:35:14.043

8

Perl 6, 33 25 bytes

-7 bytes thanks to Kevin Cruijssen

60>*.polymod(100,100).max

Try it online!

nwellnhof

Posted 2020-02-25T14:34:15.307

Reputation: 10 037

126 bytes – Kevin Cruijssen – 2020-02-25T16:46:56.707

6

APL (Dyalog Extended), 19 bytesSBCS

-10 bytes thanks to Kevin Cruijssen.

Anonymous tacit prefix function. Takes argument as integer.

⍱59<100∘⊤

Try it online!

100∘⊤ convert To base-100

59< are they, each, greater than 59?

 are none of them true?

Adám

Posted 2020-02-25T14:34:15.307

Reputation: 37 779

I don't know APL, but can't you save some bytes by checking if the maximum is $<60$ after the 100∘⊤? It halved the byte-counts of both my MathGolf answer and the 05AB1E answer, so I assume it should be able to save some bytes for your solution as well. (Note that the challenge states the valid input is in the range $[0,235959]$, so we won't need to check the hours.. I liked the challenge more when a larger range was possible tbh.) – Kevin Cruijssen – 2020-02-25T16:38:58.050

@KevinCruijssen Yes, of course, since we know that we'll never get 240000 or above. Thanks! – Adám – 2020-02-25T16:46:36.960

5

05AB1E, 14 13 12 bytes, supports inputs > 235959

твR₅0šR12*‹P

Try it online!

тв             # convert input to base 100
  R            # reverse
   ₅           # 255
    0š         # convert to list and prepend 0: [0, 2, 5, 5]
      R        # reverse: [5, 5, 2, 0]
       12*     # times 12: [60, 60, 24, 0]
          ‹    # a < b (vectorizes
           P   # product

Grimmy

Posted 2020-02-25T14:34:15.307

Reputation: 12 521

2

You beat me to it. I was just working on an answer. Had already prepared a test suite, so feel free to edit it in. XD

– Kevin Cruijssen – 2020-02-25T15:03:01.143

You can shorten the [60, 60, 24] for 11 bytes

– Expired Data – 2020-02-25T15:35:28.190

@ExpiredData Although smart, the unprintable isn't part of 05AB1E's codepage, so in that case the entire program should be counted in a different codepage (i.e. UTF-8), and it would only increase. Still a good way to save bytes if the 24 was $\geq32$, though. – Kevin Cruijssen – 2020-02-25T16:12:31.787

@KevinCruijssen why doesn't TIO count it as extra then, like it does with mathematica when using the extended symbols? – Expired Data – 2020-02-25T16:14:08.380

1

@KevinCruijssen here's 12 then

– Expired Data – 2020-02-25T16:17:53.257

@ExpiredData Nice 12-byter alternative! :) And TIO only shows UTF-8 encoding correct a.f.a.i.k., for languages which uses UTF-8 like your mentioned Mathematica or Java for example. Any codegolf language with a custom code-page on TIO simply uses the 'SBCS encoding' (which basically means each character is counted as a single byte). I forgot what SBCS stands for, but I thought it was something along the lines of Single Byte Code Source (not sure about the CS part..) – Kevin Cruijssen – 2020-02-25T16:25:07.463

16 bytes I liked this challenge more when inputs above 235959 were allowed as input.. – Kevin Cruijssen – 2020-02-25T16:31:26.560

1@KevinCruijssen probably CS stands for character set? – Expired Data – 2020-02-25T16:37:03.533

4

Python, 35 bytes

f=lambda n:n<1or(n%100<60)*f(n/100)

A recursive function which returns 1 or True (which are truthy) if valid or 0 (which is falsey) if not.

Try it online! *

How?

True and False are equivalent to 1 and 0 respectively in Python.

The function (f=lambda n:...) checks that the last up-to-two digits as an integer (n%100) are less than sixty (<60), chops them off (n/100) and multiplies by a recursive call *f(...) until an input of zero is reached (n<1or) at which point True is returned. If at any stage the check fails a False is placed in the multiplication, which will then evaluate to 0 (a falsey value).


* Only f(0) evaluates to True, but set((True, 1, 1, ..., 1)) evaluates to {True} due to the equivalence of True and 1 in Python.

Jonathan Allan

Posted 2020-02-25T14:34:15.307

Reputation: 67 804

3

J, 32 26 23 16 bytes

60*/ .>100#.inv]

Try it online!

-16 bytes (!!) thanks to Adam. This new solution uses the approach from his APL answer so be sure to upvote that.

Convert the input to base 100, check that all digits are less than 60.

Note the most significant digit is guaranteed to be less than 24 by the allowed inputs.

Jonah

Posted 2020-02-25T14:34:15.307

Reputation: 8 729

Can you not combine [:*/ and > into */ .> ? – Adám – 2020-02-25T15:15:00.693

No need to stringify. You can take the argument as a string. – Adám – 2020-02-25T15:18:06.610

Re: your first comment, you can indeed and it's cool observation but doesn't change the byte count. I'll change per your 2nd comment in a sec. – Jonah – 2020-02-25T15:18:42.287

26: 24 60 60*/ .>_3{.100&#.inv Try it online!

– Adám – 2020-02-25T15:22:37.353

1Very nice, I like that much better than my original approach. Thanks Adam! – Jonah – 2020-02-25T15:27:52.547

You're welcome. It is simply a port of mine.

– Adám – 2020-02-25T15:28:37.430

1

23: 24 60 60*/ .>(3$100)&#: Try it online!

– Adám – 2020-02-25T15:30:03.013

16: 60*/ .>100#.inv] Try it online!

– Adám – 2020-02-25T16:50:44.243

Ah because the input constraint gives us the 24, nice! – Jonah – 2020-02-25T16:53:03.603

3

Perl 5 -p, 27 22 bytes

$_=!/[6-9].(?=(..)*$)/

Try it online!

Since the input is guaranteed to be less than 236000, the hours can be ignored as they will always be valid. This pattern match checks if there is a 6, 7, 8, or 9 in the tens digit of the minutes or seconds. The match is then negated to get truthy for valid dates and falsy for invalid ones.

Xcali

Posted 2020-02-25T14:34:15.307

Reputation: 7 671

what about 18 bytes

– Nahuel Fouilleul – 2020-02-27T05:44:04.880

3

Java 8, 38 bytes

n->n%100<60&n%1e4<6e3&n%1e6<24e4&n<1e6

Try it online!

Basically an improvement of @Kevin Cruijssen's solution; I don't have enough reputation for a comment.

Joja

Posted 2020-02-25T14:34:15.307

Reputation: 31

1Why wouldn't I accept an improvement on my answer? But indeed a nice improvement Joja, +1 from me (now you should have enough rep to create comments ;p). PS: @a'_' Your name is annoying to tag in a comment, since the underline triggers the italic text.. – Kevin Cruijssen – 2020-02-26T10:58:15.000

2

Red, 63 bytes

f: func[n][either n % 100 > 59[return 0][if n > 1[f n / 100]]1]

Try it online!

Of course the recursive function with integers is much shorter than the below version that works on strings.

Red, 139 130 115 bytes

func[s][s: pad/left/with s 6 #"0"
not any collect[foreach n collect[loop 3[keep to 1 take/part s 2]][keep n > 60]]]

Try it online!

Galen Ivanov

Posted 2020-02-25T14:34:15.307

Reputation: 13 815

I don't know Red, but you can probably save some bytes by checking if the maximum after the [s: pad/left/with s 6 #"0" t: collect[loop 3[keep to 1 take/part s 2]]] is smaller than 60. – Kevin Cruijssen – 2020-02-25T17:35:16.200

@Kevin Cruijssen Red's max function takes exactly 2 arguments and doesn't work on lists. – Galen Ivanov – 2020-02-25T18:06:34.300

1Ah ok. Yeah, Java is the same unfortunately. It would only increase the byte-count instead of decreasing it. :) – Kevin Cruijssen – 2020-02-25T18:08:42.303

2

Java 8, 45 43 bytes

n->n%100<60&n%1e4/100<60&n%1e6/1e4<24&n<1e6

Improved by @Joja's Java answer by removing the divisions, so make sure to upvote him/her as well!

Try it online.

Explanation:

n->              // Method with integer parameter and boolean return-type
  n%100<60       //  Check whether the seconds are smaller than 60
  &n%1e4/100<60  //  and the minutes are smaller than 60
  &n%1e6/1e4<24  //  and the hours are smaller than 24
  &n<1e6         //  and the entire number is smaller than 1,000,000

Kevin Cruijssen

Posted 2020-02-25T14:34:15.307

Reputation: 67 575

2

Turing Machine Code, 336 548 bytes

Prints 't' for true and 'f' for false.

0 * * r !
! * * r "
! _ _ l b
b * _ l t
" * * r £
" _ _ l c
c * * l c
c _ _ r 4
£ * * r $
£ _ _ l d
d * * l d
d _ _ r 3
$ * * r ^
$ _ _ l e
e * * l e
e _ _ r 2
^ * * r &
^ _ _ l g
g * * l g
g _ _ r 1
& * * l &
& _ _ l O
O 1 1 r a
O 2 2 r 1
O * * * f
a * * r 2
1 0 0 r 2
1 1 1 r 2
1 2 2 r 2
1 3 3 r 2
1 * * * f
2 0 0 r 3
2 1 1 r 3
2 2 2 r 3
2 3 3 r 3
2 4 4 r 3
2 5 5 r 3
2 * * * f
3 * * r 4
4 0 0 r t
4 1 1 r t
4 2 2 r t
4 3 3 r t
4 4 4 r t
4 5 5 r t
4 * * * f
f * * l f
f _ _ r n
n * _ r n
n _ f * halt
t * * l t
t _ _ r y
y * _ r y
y _ t r halt


Try it online!

Added a chunk of bytes thanks to @Laikoni for spotting my misread of the question.

ouflak

Posted 2020-02-25T14:34:15.307

Reputation: 925

Looks like this fails for hours >2, e.g. 30000 returns f though it is a valid time. – Laikoni – 2020-02-26T11:59:34.737

Upon closer inspection, it looks like you require leading zeros, as e.g. 3 fails but 000003 does not. However, the point of the challenge is that no leading zeros are given. – Laikoni – 2020-02-26T12:02:13.433

@Laikoni, Thanks, I read through that too quickly and thought it simply meant I had to handle leading zeros, not actually imply them myself in the input myself. I'll sort it out.... – ouflak – 2020-02-26T12:07:23.867

As friendly competition, I also gave it a shot: https://codegolf.stackexchange.com/a/200153/56433. To keep the byte count down, I took a rather liberal approach to indicate true or false, though this is usually fine for challenge on this site.

– Laikoni – 2020-02-26T13:34:50.677

2

Jelly, 13 7 bytes

bȷ2<60Ạ

Try it online!

A monadic link taking an integer and returning 1 for true and 0 for false.

Thanks to @KevinCruijsen for saving 6 bytes!

Nick Kennedy

Posted 2020-02-25T14:34:15.307

Reputation: 11 829

2I don't know Jelly, but based on that “<<ð‘ (which I think is [60,60,24]?) you can probably save some bytes with a different approach: convert to base 100 as list, get the maximum, check if it's smaller than 60. (In pseudo-code: max(hh,mm,ss)<60.) The range is guaranteed to be $[0,235959]$. – Kevin Cruijssen – 2020-02-25T17:41:13.140

Posted a couple of different sevens too. – Jonathan Allan – 2020-02-26T04:55:47.070

2

LibreOffice Calc, 43 bytes

=MAX(MOD(A1,100),MOD(A1/100,100),A1/4e3)<60

Basically a blatant rip-off respectful port of @RGS excellent Python answer so go and upvote them. Only posted as I have not seen a LibreOffice Calc answer on here before and I was messing about while calculating my tax return this evening (code golf is much more fun). Screenshot of some test cases below.

enter image description here

ElPedro

Posted 2020-02-25T14:34:15.307

Reputation: 5 301

2

x86-16, IBM PC DOS, 46  44  39 bytes

00000000: d1ee 8a0c ba30 4c88 5401 03f1 4ed1 e9fd  .....0L.T...N...
00000010: b303 ad86 e0d5 0a4b 7502 b628 3ac6 7d02  .......Ku..(:.}.
00000020: e2f0 d6b4 4ccd 21                        ....L.!

Build and test ISTIME.COM with xxd -r.

Unassembled listing:

D1 EE       SHR  SI, 1              ; SI = 80H
8A 0C       MOV  CL, BYTE PTR[SI]   ; CX = input length
BA 4C30     MOV  DX, 4C30H          ; DH = 60+16, DL = '0'
88 54 01    MOV  BYTE PTR[SI+1], DL ; 'zero' pad byte to the left of input
03 F1       ADD  SI, CX             ; SI to end of input string
4E          DEC  SI                 ; remove leading space from length
D1 E9       SHR  CX, 1              ; CX = CX / 2
FD          STD                     ; read direction downward
B3 03       MOV  BL, 3              ; counter to test if third iteration (meaning hours)
        LOD_LOOP:
AD          LODSW                   ; AX = [SI], SI = SI - 2
86 E0       XCHG AH, AL             ; endian convert
D5 0A       AAD                     ; binary convert
4B          DEC  BX                 ; decrement count
75 02       JNZ  COMP               ; if not third time through, go compare
B6 28       MOV  DH, 40             ; if third, set test to 24+16
        COMP:
3A C6       CMP  AL, DH             ; is number less than DL?
7D 02       JGE  NOT_VALID          ; if not, it's invalid
E2 F0       LOOP LOD_LOOP           ; otherwise keep looping
        NOT_VALID: 
D6          SALC                    ; Set AL on Carry
B4 4C       MOV  AH, 4CH            ; return to DOS with errorlevel in AL
CD 21       INT  21H                ; call DOS API

A standalone PC DOS executable. Input via command line, output DOS exit code (errorlevel) 255 if Truthy 0 if Falsy.

I/O:

Truthy:

enter image description here

Falsy:

enter image description here

Thanks to @PeterCordes for:

  • -2 bytes use DOS exit code for Truthy/Falsy result
  • -3 bytes eliminate ASCII conversion before AAD

640KB

Posted 2020-02-25T14:34:15.307

Reputation: 7 149

Isn't [SI+1] (81h) the first byte of the arg string that you're overwriting? I would have thought you'd want to store to [si] and just replace the length byte with '0' padding. – Peter Cordes – 2020-02-27T20:45:59.820

@PeterCordes [80h] is the length byte and [81h] is the char (can only be a space (20H) or a forward slash) between the command invocation and the start of the command line argument string that starts at [82h]. – 640KB – 2020-02-27T20:51:00.417

Ah, https://cs.lmu.edu/~ray/notes/x86assembly/ and How to pass/retrieve DOS command-line parameters in a 16-bit assembly program? weren't clear about that. Makes sense now, I'd forgotten that DOS allowed a non-whitespace separator between command and args.

– Peter Cordes – 2020-02-27T20:53:08.097

Yes, it's quite annoying really because that leading space is counted in the length byte, so you pretty much always have to decrement that before you can use it. – 640KB – 2020-02-27T20:55:18.313

You're spending a bunch of bytes to check that hours <= 24. The problem statement in the question guarantees that the max integer is 23... so you can make a version that only solves that simpler problem. Also, I think your code will accept repeated hours pairs, like 23230000, so not arbitrary integer. You could just check the tens digits (AH) for being <= '5' in the loop, instead of aad those bytes into a binary integer. (And BTW, I think you can skip the sub ax, '00' before AAD: 10*0x30 + 0x30 = 0x210, so you just need to check that the AAD result in AL is < 60+16 or 24+16). – Peter Cordes – 2020-02-27T21:05:56.150

Can you use a non-zero exit status instead of printing a '0/1' to save bytes? At least the ret could go. – Peter Cordes – 2020-02-27T21:08:10.520

@PeterCordes yeah, I know I could shave off a few bytes not making it callable and not a standalone DOS .com, just return a ZF or CF. What stopped me was having to refactor everything when I couldn't count on being able to overwrite input string pointer - 1 with the zero pad. I think the only way to return an exit code is to use INT 21H / AH=4CH (a lot more bytes). Give me a bit to digest your previous post and see what we can squeeze out! – 640KB – 2020-02-27T21:40:08.407

I didn't mean a function, I meant a DOS program that exits with int 21h/ah=4Ch with an exit status of AL = 0 or -1 (from salc = Set AL from Carry - a 1-byte (undocumented) instruction that's like sbb al,al without writing flags). That should save 2 bytes net: drop the ret and turn the 2-byte adc into 1-byte salc. Code-golf answers don't even have to be fully portable, and salc works in 16 and 32-bit mode on at least every Intel CPU including current ones.

– Peter Cordes – 2020-02-28T00:59:55.577

@PeterCordes brilliant idea eliminating the ASCII conversion before AAD in this case! That never would have occurred to me that it would work in this case! I've changed it to return a DOS exit code instead of output to console. So odd that SALC would be left in all chips and not documented, wonder why? Thanks as always! – 640KB – 2020-02-28T20:33:17.870

@PeterCordes you said the code will accept repeated hour pairs. Is that a problem? Rules state input will be only in the range of 0..235959 so shouldn't have to handle 23230000 right? – 640KB – 2020-02-28T20:34:12.780

re: 23232323: it's not a problem per-se, but if you're spending extra bytes to apply a tight bound for hours, it might not make sense if you don't catch other too-high-number problems. (You could look at it as formatting error vs. semantic error, though.) Re: undocumented opcodes: perhaps an extremely conservative approach to maintaining backwards compat with possible existing binaries? That was Agner Fog's guess in his Stop the Instruction Set War article.

– Peter Cordes – 2020-02-29T20:35:08.250

1

Charcoal, 11 bytes

‹⌈⍘N⭆¹⁰⁰℅ι<

Try it online! Link is to verbose version of code. Accepts input from 0 to 239999 and outputs a Charcoal boolean, - for times, no output for non-times. Explanation:

     ¹⁰⁰    Literal 100
    ⭆       Map over implicit range and join
         ι  Current index
        ℅   Unicode character with that ordinal
   N        Input as a number
  ⍘         Convert to string using string as base
 ⌈          Character with highest ordinal
‹           Is less than
          < Character with ordinal 60
            Implicitly print

BaseString always returns 0 for a value of 0 (bug?) but fortunately this is still less than <.

Alternative solution, also 11 bytes:

⌈⍘N⭆¹⁰⁰›ι⁵⁹

Try it online! Link is to verbose version of code. Link is to verbose version of code. Accepts input from 0 to 239999 and outputs 0 for times, 1 for non-times. Explanation:

    ¹⁰⁰     Literal 100
   ⭆        Map over implicit range and join
        ι   Current index
       ›    Greater than
         ⁵⁹ Literal 59
  N         Input as a number
 ⍘          Convert to a string using string as base
⌈           Maximum
            Implicitly print

BaseString doesn't require the string base to have distinct characters, so this string just has 60 0s and 40 1s.

Unfortunately taking the base numerically returns an empty list for an input of zero, which takes an extra three bytes to handle, pushing the byte count above 11. But fortunately I can substitute an acceptable non-zero number in only two bytes, so another 11-byte alternative is possible:

›⁶⁰⌈↨∨Nχ¹⁰⁰

Try it online! Link is to verbose version of code. Accepts input from 0 to 239999 and outputs a Charcoal boolean, - for times, no output for non-times. Explanation:

 ⁶⁰         Literal 60
›           Is greater than
      N     Input as a number
     ∨      Logical Or
       χ    Predefined variable `10`
    ↨   ¹⁰⁰ Convert to base 100 as a list
   ⌈        Maximum
            Implicitly print

Neil

Posted 2020-02-25T14:34:15.307

Reputation: 95 035

1

MathGolf, 18 9 bytes

◄+░2/i╙╟<

Try it online.

Explanation:

◄+        # Add builtin 10,000,000 to the (implicit) input-integer
  ░       # Convert it to a string
   2/     # Split it into parts of size 2: [10,hh,mm,ss]
     i    # Convert each to an integer
      ╙   # Pop and push the maximum
       ╟< # And check if it's smaller than builtin 60
          # (after which the entire stack joined together is output implicitly)

Kevin Cruijssen

Posted 2020-02-25T14:34:15.307

Reputation: 67 575

1

JavaScript (V8), 34 bytes

a=>a.match(/\d\d/g).every(x=>x<60)

Try it online!

Expired Data

Posted 2020-02-25T14:34:15.307

Reputation: 3 129

1

K (ngn/k), 14 bytes

{0=+/59<100\x}

Try it online!

Based on Adám's APL solution and Kevin Cruijssen's suggestion.

Galen Ivanov

Posted 2020-02-25T14:34:15.307

Reputation: 13 815

1

Japt, 7 bytes

ìL e<60

Try it

Shaggy

Posted 2020-02-25T14:34:15.307

Reputation: 24 623

I love an answer in Japt! I've just noticed that this will fail on anything where the hour is between 24 and 59. – JustCarty – 2020-02-26T09:50:30.400

1

Bash, 33 32 bytes

p=%100\<60;echo $[$1$p&$1/100$p]

Try it online!

Input is passed as an argument.

Output is 0 (falsey) or 1 (truthy).

(I've deleted an earlier 45-byte version that used egrep.]

Mitchell Spector

Posted 2020-02-25T14:34:15.307

Reputation: 3 392

1

Retina 0.8.2, 12 bytes

[6-9].(..)?$

Try it online! Link includes test cases. Accepts input from 0 to 239999 and outputs 0 for times, 1 for non-times. Explanation: Simply checks whether the second or fourth last digit is greater than 5.

Neil

Posted 2020-02-25T14:34:15.307

Reputation: 95 035

1

Zsh, 28 bytes

e=%100/60;(($1$e||$1/100$e))

Try it online!

Returns via exit code.

Since $parameters are expanded before ((arithmetic)), $e expands to %100/60 before arithmetic is done.

There are 2 other 28 byte solutions I found as well, albeit not as interesting:

((h=100,$1%h/60||$1/h%h/60))
(($1%100/60||$1/100%100/60))

GammaFunction

Posted 2020-02-25T14:34:15.307

Reputation: 2 838

1

W, 6 bytes

Source compression ftw!

♀♥@p▒ö

Uncompressed:

2,a60<A

Explanation

2,      % Split number into chunks of length 2
        % The splitting is right-to-left *instead* of left-to-right.
      A % Is all items in the list ...
  a60<  % ... less than 60?

a'_'

Posted 2020-02-25T14:34:15.307

Reputation: 1 099

Does 2, split from right-to-left? If not, wouldn't this fail for an input like 659, which I assume becomes [65,9] instead of [6,59]? – Kevin Cruijssen – 2020-02-26T10:50:18.773

Ah ok, nice, +1 from me in that case. (Your first sentence of your comment is reversed, but your edit in the answer is correct.) Most languages I know would split from left-to-right, so I was surprised to see it works from right-to-left in W. Btw, has there been any word from Dennis when W might be added to TIO? I think this is the third answer I see you post in W. – Kevin Cruijssen – 2020-02-26T13:00:16.440

1

T-SQL, 42 bytes

Supports all positive integer input

Returns 1 for true, 0 for false

DECLARE @ INT=235959

PRINT-1/~(@/5000/48+@/100%100/60+@%100/60)

I was able to golf it 1 byte

@/10000/24 was changed to @/5000/48

t-clausen.dk

Posted 2020-02-25T14:34:15.307

Reputation: 2 874

1

Turing Machine Simulator, 299 272 269 bytes

0 _ _ l 1
0 * * r 0
1 * _ l 2
* _ t * t
2 6 f * f
2 7 f * f
2 8 f * f
2 9 f * f
2 * _ l 3
3 * _ l 4
4 6 f * f
4 7 f * f
4 8 f * f
4 9 f * f
4 * _ l 5
5 0 _ l 6
5 1 _ l 6
5 2 _ l 6
5 3 _ l 6
5 * _ l 7
6 _ t * t
6 1 t * t
6 2 t * t
6 * f * f
7 _ * * t
7 1 _ * t
7 * f * f

Run in Turing Machine Simulator. Halts with t on the tape for true inputs and a prefix of the input and f for false inputs.

Laikoni

Posted 2020-02-25T14:34:15.307

Reputation: 23 676

Yeah I tend to pontificate a bit with my true/false outputs. This is nice, very succinct. I only too briefly considered the idea of starting at the end of the input. – ouflak – 2020-02-26T14:11:45.023

0

Wolfram Language (Mathematica), 76 bytes

supports any number

!FreeQ[FromDigits/@Join@@@IntegerDigits/@Tuples[Range/@{24,6,10,6,10}-1],#]&

Try it online!

J42161217

Posted 2020-02-25T14:34:15.307

Reputation: 15 931

0

Perl 5, 42 39 +1 (-p) = 40 bytes

$_=0|!($_%100>59|$_/1e4%10>5|$_/1e5>23)

Saved 3 bytes by changing to exponent notation (1000 => 1e4)

Try it online!

andytech

Posted 2020-02-25T14:34:15.307

Reputation: 189

0

T-SQL, 64 bytes

SELECT*FROM t WHERE 60>LEFT(RIGHT('000'+v,4),2)AND 60>RIGHT(v,2)

Input is taken from pre-existing table t with varchar field v, per our input standards.

Outputs 1 row (with the original value) for "true", and 0 rows for "false".

Accepts only values in the specified range (0 to 235959), so doesn't validate the first 2 digits.

BradC

Posted 2020-02-25T14:34:15.307

Reputation: 6 099

0

Python 3, 90 85 bytes

lambda t:{t}&s
s={0}
import time
while len(s)<86400:s|={int(time.strftime("%H%M%S"))}

Try it online!

The idea is to simply create a set of all valid time (as int), then check if the given number is in the set. The set is created by repeatedly adding the current time to the set until all 86400 distinct values are added. Returns: non-empty set if t is valid time, otherwise empty set.

Surculose Sputum

Posted 2020-02-25T14:34:15.307

Reputation: 317

0

JavaScript (ES6),  27 26  21 bytes

Takes input as an integer in hhmmss format. Returns \$0\$ or \$1\$.

n=>n%100<60&n%1e4<6e3

Try it online!

How?

n=>n%100<60&n%10000<6000

is just as long as:

n=>n%100<60&n/100%100<60

But from there we can use the scientific notation to save 3 bytes:

n%10000<6000
n%1e4<6e3

Arnauld

Posted 2020-02-25T14:34:15.307

Reputation: 111 334

0

JavaScript (Babel Node), 71 52 bytes

t=i=>{[,,m,,s]=(i+'').padStart(6,0);return m<6&&s<6}

Try it online!

Sarreph

Posted 2020-02-25T14:34:15.307

Reputation: 111

48 bytes – Expired Data – 2020-02-25T23:17:37.153

0

PHP, 60 bytes

<?=preg_match('#\d+([01]\d|2[0-3])([0-5]\d){2}#',$argn+1e6);

Try it online!

Basically regex and not much golfable, but fun. Inputs above 235959 are indeterminate.

Guillermo Phillips

Posted 2020-02-25T14:34:15.307

Reputation: 561

0

Wolfram Language (Mathematica), 44 bytes

#&@@TimeObject[x=IntegerDigits[#,100,3]]==x&

Try it online!

Works for values above 235959!

The built-in TimeObject command can automatically round up each element!

Explanation

x=IntegerDigits[#,100,3]

Split input in base-100 (i.e. in chunks of 2 digits), padded to length 3. Store that list in x.

TimeObject[...]

Convert that to a TimeObject.

#&@@...

Extract the rounded string

...==x

Check if that is equal to x (i.e. nothing rounded up).

The boring version, 28 bytes

Max@IntegerDigits[#,100]<60&

Try it online!

JungHwan Min

Posted 2020-02-25T14:34:15.307

Reputation: 13 290

0

C (gcc), 30 bytes

f(n){n=n%100<60&n/100%100<60;}

Doesn't check hours.

Try it online!

C (gcc), 39 bytes

f(n){n=n%100<60&n/100%100<60&n/1e4<24;}

Checks hours.

Try it online!

S.S. Anne

Posted 2020-02-25T14:34:15.307

Reputation: 1 161

0

MUMPS, 74 70 64 40 bytes

t(t) s l=$l(t)-5 f f=l:2:7 q:$e(t,f,f+1)>$s(f-l:59,1:23)
 q f>5

Ah, I didn't consider that you only need to handle values up to 239999. That drops it from 64 to 40.

t(t) f f=$l(t)-3:2:7 q:$e(t,f)>5
 q f>5

Michael Donnelly

Posted 2020-02-25T14:34:15.307

Reputation: 11

0

Jelly, 7 bytes

ṚHÐoṀ<6

Try it online!

How?

ṚHÐoṀ<6 - Link: integer, n                 e.g.  236059
Ṛ       - (implicit digits of n) reversed        [9  , 5  , 0  , 6  , 3  , 2  ]
  Ðo    - apply to odd indices:
 H      -   halve                                [4.5, 5  , 0  , 6  , 1.5, 2  ]
    Ṁ   - maximum                                6
      6 - six                                    6
     <  - less than?                             0

Alternative 7:

ṚḊm2Ṁ<6 - reverse, dequeue, modulo-2-slice, maximum, less than 6?

Jonathan Allan

Posted 2020-02-25T14:34:15.307

Reputation: 67 804

0

JavaScript (Node.js), 49 bytes

t=> !!(t+'').padStart(6,0).match(/..([0-5]\d){2}/)

Simple Javascript Regular Expression

Try it online!

user3335941

Posted 2020-02-25T14:34:15.307

Reputation: 41

0

VBA, 149 bytes

x=1: i=""
If Len(i)<6 Then Do Until Len(i)=6: i="0"&i: Loop
s = Right(i, 2): m = Left(Right(i,4),2): h = Left(i,2)
If s>59 Or m>59 Or h>23 Then x=0

Works for values above 235959, assigns x to output 1 or 0 with input as i

Allen W. Marx

Posted 2020-02-25T14:34:15.307

Reputation: 1