1
\$\begingroup\$

Assume the result of an exam has been published.

After 5 minutes, First person knows the result.

In next 5 minutes, new 8 persons know the result, and in total 9 know it.

Again after 5 minutes, new 27 people know, and total 36 know.

In similar fashion, total 100, 225..... people keep knowing it on 5 minute interval.

Challenge

Given a total number of people knowing (n), and a starting time in hour and minutes, output when total n people will know the result.

Example: If start is 1:02, and n is 225 the output time will be 1:27.

In output colons of time aren't needed, you may input or output as list or seperate variables.

n will be always in the sequence of totals, i.e. (1,9,36,100,225....)

\$\endgroup\$
3
  • \$\begingroup\$ Relevant OEIS entry \$\endgroup\$
    – lyxal
    Nov 13 at 9:21
  • 1
    \$\begingroup\$ Do times wrap around? Can the hour be zero? Test cases would be good. \$\endgroup\$
    – xnor
    Nov 13 at 9:30
  • \$\begingroup\$ @xnor jour can be zero and time will wrap \$\endgroup\$
    – Camel
    Nov 13 at 9:35
0
\$\begingroup\$

Python 3.8 (pre-release), 85 bytes

lambda h,m,x:[(h+(y:=(((((x**.5)*8)+1)**.5)-1)*2.5)//60)%24+(m+y%60)//60,(m+y%60)%60]

Try it online!

The sequence of totals is just sum of first \$n\$ cubes.

It is a known formula that sum of first \$n\$ cubes is the square of \$n\$th triangular number (Proof), i.e.

\$ \{\frac{n(n+1)}{2}\}^2 \$

If we assume given input is \$x\$, then

\$ \{\frac{n(n+1)}{2}\}^2=x \\ \frac{n(n+1)}{2}=\sqrt{x} \\ n(n+1)=2\sqrt{x} \\ n^2+n=2\sqrt{x} \\ n^2+n-2\sqrt{x}=0 \$

We get a quadratic equation with \$a=1, b=1, c=-2\sqrt{x}\$

The formula for the quadratic equation is

\$ \frac{-b\pm\sqrt{b^2-4ac}}{2a} \$

We will only take the positive root and plug in

\$ \frac{-b+\sqrt{b^2-4ac}}{2a} \\ =\frac{-1+\sqrt{(-1)^2-4\times(-2\sqrt{x})\times1}}{2\times1} \\ =\frac{-1+\sqrt{1+8\sqrt{x}}}{2} \\ =\frac{(\sqrt{1+8\sqrt{x}})-1}{2} \$

Which is the formula for the \$n\$, then we just multiply it by 5, divmod by \$60\$ and add with start time.

\$\endgroup\$
4
  • \$\begingroup\$ Fails for input 1, 40, 225 among others. \$\endgroup\$
    – Dingus
    Nov 13 at 9:36
  • \$\begingroup\$ @Dingus works now \$\endgroup\$
    – wasif
    Nov 13 at 9:40
  • \$\begingroup\$ The question is unclear on whether a 12 or 24 hour clock is in use, though comments suggest 24. In that case, this still fails when the time wraps back around, e.g. 23, 40, 225. \$\endgroup\$
    – Dingus
    Nov 13 at 9:49
  • 2
    \$\begingroup\$ You absolutely do not need that many sets of brackets \$\endgroup\$
    – pxeger
    Nov 13 at 14:25
0
\$\begingroup\$

Retina 0.8.2, 103 bytes

\d+
$*
(^1|11\1)+
$#1$*
(^1|1\1)+¶(.+)
$2$1$1$1$1$1
+`:1{60}
1:
+`1{24}:
:
(1*):(1*)
$.1:$.2
:(.)$
:0$1

Try it online! Takes n on the first line and the time (including colon) on the second.Explanation:

\d+
$*

Convert to unary.

(^1|11\1)+
$#1$*

Take the square root.

(^1|1\1)+¶(.+)
$2$1$1$1$1$1

Add 5 times the triangular index to the minutes.

+`:1{60}
1:

Convert 60 minutes to an hour.

+`1{24}:
:

Ignore days.

(1*):(1*)
$.1:$.2
:(.)$
:0$1

Convert to decimal.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.