Finding My Favorite Times

JavaScript (ES6), 87 83 bytes

Saved 4 bytes thanks to @l4m2

Takes input as a string. Returns either 0 or a 2-element array.

t=>[i=0,83,588,83,588,83,15].every(d=>(k=t-(t/25>>2)*40)>(j=i,i+=d))|i-k&&[k-j,i-k]

Test cases

let f =

t=>[i=0,83,588,83,588,83,15].every(d=>(k=t-(t/25>>2)*40)>(j=i,i+=d))|i-k&&[k-j,i-k]

console.log(f('0000')) // YAY!!!
console.log(f('0020')) // 20 63
console.log(f('0105')) // 65 18
console.log(f('0122')) // 82 1
console.log(f('0123')) // YAY!!!
console.log(f('0124')) // 1 587
console.log(f('0852')) // 449 139
console.log(f('1111')) // YAY!!!
console.log(f('1113')) // 2 81
console.log(f('1200')) // 49 34
console.log(f('1234')) // YAY!!!
console.log(f('1357')) // 83 505
console.log(f('1759')) // 325 263
console.log(f('1800')) // 326 262
console.log(f('1801')) // 327 261
console.log(f('2222')) // YAY!!!
console.log(f('2244')) // 22 61
console.log(f('2345')) // YAY!!!
console.log(f('2351')) // 6 9

How?

We do not care about the result of the .every() loop. Provided that the input is valid, it will always be falsy. What we're really interested in is when we exit this loop.

We exit as soon as we find a favorite time i (expressed in minutes) which is greater than or equal to the reference time k (the input time t converted in minutes). We then return 0 if i == k or the 2 delays otherwise.


Jelly, 34 33 32 31 28 bytes

3 bytes thanks to Mr. Xcoder's .ị and ³ tricks.

d³ḅ60;15j83,588ṁ5¤_\ṠÞAµ.ịxẠ

Try it online!

Some parts are exactly as in Jonathan Allan's answer, but I'm posting it as I think it is sufficiently different from it and independently written based on my Pyth answer (and shorter :D). Should also have room for improvement.

Input is an integer, output is an array of previous and next times or the empty array for special times.

Explanation

Using example input 1200.

  • converts the time to base 100, into hours and minutes: [12,0].
  • ḅ60 converts from base 60 to get total minutes: 720.
  • ;15 pairs it with 15: [720, 15].
  • 83,588 creates the array [83, 588].
  • ṁ5 makes it length 5: [83, 588, 83, 588, 83].
  • ¤ combines the two above actions. Just a technicality.
  • j joins the pair with the array: [720, 83, 588, 83, 588, 83, 15].
  • _\ subtracts each array value from the first and gets intermediate results: [720, 637, 49, -34, -622, -705, -720].
  • ṠÞ stably sorts these by signum: [-34, -622, -705, -720, 720, 637, 49].
  • A takes the absolute values: [34, 622, 705, 720, 720, 637, 49].
  • µ starts a new monadic chain. Again, a technicality.
  • .ị takes the last and first items: [49, 34].
  • ×Ạ repeats that once if there are no zeroes, or zero times otherwise: [49, 34].

Befunge-93, 88 85 86 80 74 bytes

&:"d"/58**-:"S"-:"b"6*-:"S"v
@._v#!:<\-*53:-"S":-*6"b":-<
:$#<$$\^@.._\#`0

Try it online!

Outputs the number of minutes since the last favourite time, followed by the number of minutes until the next favourite time (separated by the two character sequence: space, hyphen). If it is already a favourite time, then a single zero is returned.

Tags:

Date

Code Golf