23
$\begingroup$

My alarm clock has a typical 7-segment digital display showing hours and minutes.

4:13

Every lit segment is equally bright, and every unlit segment is equally dark. The separator (:) is always lit.

12:05

Assuming the clock uses 12-hour time without a leading zero for the hours, at what time does the overall brightness (i.e., the total number of lit segments) of the display change the most?

$\endgroup$
20
$\begingroup$

Logic behind the answer:

The biggest change in brightness is: 7->8 (+4), 0->1 (-4), 1->2 (+3), 6->7 (-3).
Changing time by "tens," the greatest increase is from :19->:20 (+4), which is better than any single digit change.
An hour change (:59->:00) results in +1 brightness, so it is "inefficient" to go down in brightness (change in a single digit, 6->7, is less than :19->:20, and going from 6:59->7:00, is only a change of (-1)). So we are looking for an increase in brightness.

So, without really looking at anything else, my initial guess is:

7:59->8:00

resulting in:

+5 brightness

Note:

There is no lateral thinking tag, but when the clock is at 8:08, unplugging it results in a change of (-20) which is a greater change than (+6).

Edit:

Nine is 6 digits, not 5 like I originally thought.

$\endgroup$
  • $\begingroup$ That "initial guess" looks good, but the math is off...ROT13(qbhoyr-purpx gur erfhyg bs mreb gb bar naq svsgl-avar gb mreb) $\endgroup$ – zennehoy Oct 24 '18 at 11:35
  • $\begingroup$ @zennehoy ROT13(vf avar 5 be 6 havgf)? $\endgroup$ – Greg Oct 24 '18 at 11:38
  • 1
    $\begingroup$ ROT13(avar vf fvk frtzragf) $\endgroup$ – zennehoy Oct 24 '18 at 11:39
  • $\begingroup$ @zennehoy ahh. I corrected $\endgroup$ – Greg Oct 24 '18 at 11:42
  • $\begingroup$ Some googling later I found there actually are clocks with 5-segment nines... Can't remember ever having seen one in real though. Thanks for updating your answer! $\endgroup$ – zennehoy Oct 24 '18 at 11:46
7
$\begingroup$

The answer has already been given, but I show my approach how to get there, just a simple bash script brute-forcing all possibilities:

#!/bin/bash
brightness(){
    local b=0 c
    for ((c=0;c<${#1};c++)); do
    case ${1:$c:1} in
        0) (( b+=6 )); ;;
        1) (( b+=2 )); ;;
        2) (( b+=5 )); ;;
        3) (( b+=5 )); ;;
        4) (( b+=4 )); ;;
        5) (( b+=5 )); ;;
        6) (( b+=6 )); ;;
        7) (( b+=3 )); ;;
        8) (( b+=7 )); ;;
        9) (( b+=6 )); ;;
    esac
done
echo $b
}
biggest_diff=0
bbefore=$(brightness 1159)
for h in {0..11}; do
for m in {00..59}; do
    bnow=$(brightness $h$m)
        diff=$(( bnow - bbefore ))
    if [ ${diff#-} -ge $biggest_diff ]; then
        biggest_diff=${diff#-}
            echo Diff: $diff
        echo Time: $h:$m
    fi
    bbefore=$bnow
    done;
done

Calling it returns ...

./clock | tail -n2

Diff: 5
Time: 8:00

$\endgroup$
  • $\begingroup$ +1 Nice one. Well, your script is short enough to not have side effects. Nevertheless, it would be nicer to declare function-wide variables local. Just write local c b=0 to declare c before the loop, and declare and assign c. $\endgroup$ – rexkogitans Oct 25 '18 at 7:01
  • $\begingroup$ true, edited ... $\endgroup$ – RoVo Oct 25 '18 at 7:52
4
$\begingroup$

Well, it is

+5 brightness from:
7:59 to 8:00

Since:

total of 7:59 is 3 + 5 + 6 = 14
total of 8:00 is 7 + 6 + 6 = 19

$\endgroup$
  • $\begingroup$ Correct! Here's an upvote, but I'll accept Greg's answer since he has more reasoning. $\endgroup$ – zennehoy Oct 24 '18 at 11:45
  • $\begingroup$ Sure, no issue, he deserves it. I came to the answer using a computer :) $\endgroup$ – Ahmed Ashour Oct 24 '18 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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