43
\$\begingroup\$

Many electronic devices, specially old ones, will show a blinking 12:00 when the time has not been set. The purpose of this challenge is to recreate this.

Specifically, the task is to display 12:00 and --:-- alternatively in an infinite loop.

The period should be 1 second, divided evenly in two periods of 0.5 seconds. Here "1 second" and "evenly" can be interpreted loosely. For example, it is acceptable if the code pauses for 0.5 seconds between displaying the strings, even if the resulting period will then be a little higher than 1 second. An initial pause before displaying the first string is acceptable.

Each new string can be displayed either by replacing the former string or in a new line. Trailing whitespace is allowed, except that if each new string is on a different line there should be no empty lines between consecutive strings.

Shortest code in bytes wins.

\$\endgroup\$
  • 1
    \$\begingroup\$ does this count as kolmogorov-complexity? \$\endgroup\$ – FlipTack Jan 2 '17 at 12:36
  • \$\begingroup\$ @FlipTack I think so, but I wasn't sure. Thoughts, anyone? \$\endgroup\$ – Luis Mendo Jan 2 '17 at 12:45
  • \$\begingroup\$ @LuisMendo I don't think so, I think the KG tag is mostly for a fixed string. This has more to it, the waiting and alternating strings. \$\endgroup\$ – Rɪᴋᴇʀ Jan 2 '17 at 13:25
  • \$\begingroup\$ Can submissions wait 0.5 seconds before showing initial output? \$\endgroup\$ – FlipTack Jan 2 '17 at 18:20
  • 1
    \$\begingroup\$ IMHO, the statement "Each new string can be displayed either by replacing the former string or in a new line" made this challenge not fun. \$\endgroup\$ – Setop Jan 3 '17 at 0:53

66 Answers 66

1
\$\begingroup\$

C (clang), 51 bytes

f(i){puts(i?"12:00":"--:--");usleep(500000);f(!i);}

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Suggest 5e5 instead of 500000 \$\endgroup\$ – ceilingcat Nov 7 '18 at 23:28
  • \$\begingroup\$ @ceilingcat . I originally did that, but you have to cast it to int which is more bytes. \$\endgroup\$ – Logern Nov 7 '18 at 23:46
1
\$\begingroup\$

Dart, 103 bytes

import'dart:io';f({i=1}){while(i>0){print(i++%2>0?"12:00":"--:--");sleep(Duration(milliseconds:500));}}

Try it online!

Sometimes I hate how verbose and strongly typed Dart has to be :D

\$\endgroup\$
1
\$\begingroup\$

Japt, 27 bytes

500t@ßÃOq"12:00--:--"ò5 gT°

Try it

500t@ßà                         :Run the programme again in 500ms
       Oq                       :Clear the output
         "12:00--:--"ò5         :Split the string "12:00--:--" into chunks of length 5
                        gT°     :Get the element at index T (initially 0), postfix incremented
\$\endgroup\$
  • 1
    \$\begingroup\$ Not quite real-time output, @LuisMendo; explanation added. Figured the other version wouldn't be valid for that reason, thanks for clarifying. \$\endgroup\$ – Shaggy Nov 8 '18 at 14:58
0
\$\begingroup\$

under construction, I missed the 1 second delay

awk, 3534 bytes (+11 for 12:00 --:--)

{for(;++i;i=i%2)print$(i)"\033[A"}

for loop alternates i's value between 1 and 2. echo feeds the values to the program into fields $1and $2, we then print $(i). Try it:

$ echo 12:00 --:-- | awk '{for(;++i;i=i%2)print$(i)"\033[A"}'

Edit: Thanks for the ANSI tip to @F.Hauri.

\$\endgroup\$
  • 1
    \$\begingroup\$ Ansi sequence use 1 as default, so the 1 is useless in \033[A. \$\endgroup\$ – F. Hauri Jan 3 '17 at 8:31
0
\$\begingroup\$

C 79 Bytes

f(){while(1){printf("\n12:00");usleep(500000);printf("\n--:--");usleep(500000);}}

so the main would look like int main(){ f(); return 0;}

\$\endgroup\$
  • \$\begingroup\$ Welcome to Programming Puzzles & Code Golf! Just so you know, the downvote was cast automatically by the Community user when you edited your answer. I consider this a bug. \$\endgroup\$ – Dennis Jan 3 '17 at 18:43
  • \$\begingroup\$ You have to write a full program or a function, so you'd have to wrap your code in f(){...} or something. Also, the spec allows printing each output on a separate line, so system("clear"); is not required. \$\endgroup\$ – Dennis Jan 3 '17 at 18:45
  • \$\begingroup\$ You still need the while loop in your submission. Also, you cannot pass a float to usleep. \$\endgroup\$ – Dennis Jan 3 '17 at 18:58
0
\$\begingroup\$

Python 3, 78 bytes

import time;x=0
while 1:x=not x;print("12:00--:--"[x*5:x*5+5]);time.sleep(0.5)

Try it online!

\$\endgroup\$

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.