24
\$\begingroup\$

With roughly one second (plus or minus 10 ms) between outputs, output anything.
The first output must be at most one second after the start of the program, but can be as soon as right when the program starts.
So, the first output can be up to a second after the program starts, the second exactly one second after that, the third a second after that, and so on to infinity.

The outputs do not need to be consistent, nor have any sort of delimiter. However, they must be visible (even if it's only visible when highlighted).

\$\endgroup\$
12
  • \$\begingroup\$ It says "within one second between outputs," but doesn't that simply allow for no delay at all? What prevents me from doing something like while 1:print("") in Python and still be within the rules of the challenge? \$\endgroup\$
    – Aiden Chow
    Jun 26, 2023 at 5:10
  • \$\begingroup\$ @AidenChow It says with one second between outputs, so no, It must be basically exactly one second. Also, the output must be non-empty. \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 5:13
  • 1
    \$\begingroup\$ It is unclear what you mean by "non-empty thing." With print(""), the output is technically a newline, which is not empty. Do you mean to ban whitespace output? If so, that would be a very unnecessary restriction and the rule should be removed from the challenge. \$\endgroup\$
    – Aiden Chow
    Jun 26, 2023 at 5:32
  • 2
    \$\begingroup\$ You might consider adding a grace duration by which the one-second interval may differ. Otherwise, answers can't be correct for sure. \$\endgroup\$
    – chunes
    Jun 26, 2023 at 5:36
  • 1
    \$\begingroup\$ Yes, that's what I mean. \$\endgroup\$
    – chunes
    Jun 26, 2023 at 5:51

45 Answers 45

29
\$\begingroup\$

MacOS shell, 3

top

On the Mac, top's default refresh period is 1 sec.


Linux shell, 7

top -d1

Unfortunately on Linux, top's default refresh period is more like 2 secs, so we need an extra 4 bytes.

Since this is just one command, both variants are shell-agnostic.

\$\endgroup\$
2
  • 12
    \$\begingroup\$ This is the top answer. \$\endgroup\$ Jun 27, 2023 at 1:53
  • 2
    \$\begingroup\$ can't confirm this. On my mac top refreshed once every 1.1 sec. you're off by 100ms \$\endgroup\$
    – Niqql
    Jun 27, 2023 at 12:52
13
\$\begingroup\$

Bash + iputils, 6 bytes

ping 0

send ICMP ECHO_REQUEST to 0 (127.0.0.1) once per second.


Bash + procps-ng, 8 bytes

free -s1

Display amount of free and used memory in the system with one second between outputs.

\$\endgroup\$
0
10
\$\begingroup\$

Python 3, 40 39 bytes

import time
while[help()]:time.sleep(1)

Try it online!

Improved by Sisyphus

\$\endgroup\$
3
  • \$\begingroup\$ while 1:print(time.sleep(1)) is the same size, so you could use python 2 for one less byte \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 5:49
  • 17
    \$\begingroup\$ while[help()]:time.sleep(1) \$\endgroup\$
    – Sisyphus
    Jun 26, 2023 at 13:59
  • 3
    \$\begingroup\$ @Sisyphus That;s cursed \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 17:28
8
\$\begingroup\$

Desmos, 5+3+3+2=13 bytes

Ticker expression (5 bytes)

a->-a

Ticker repeat delay (3 bytes)

999

Main expressions (3 bytes)

a=1

2 bytes for "file boundaries" (treat each expression as a separate "file"; there are 3 "files", so there are two "file boundaries", as per this comment)

Try It On Desmos!

To run, click the ticker icon (the metronome) near the top left of the screen. This switches the variable a between the values 1 and -1 every 999 milliseconds. While this isn't outputting onto the console or stdin in the traditional sense, you can still clearly see the code switching between the 1 and the -1, which hopefully emulates outputting close enough.

\$\endgroup\$
5
  • \$\begingroup\$ You can do it with just a=0, a step of 1, and option 4 for the slider, and the slider running. Slider running is one bit, the four slider options are two more bits, step is one byte + one boundary byte, and a=0 is 3 more bytes (maybe + one boundary) for a total of 5.375 bytes or 6.375 bytes \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 6:32
  • \$\begingroup\$ @Dadsdy How are you calculating that running a slider is one bit, and choosing a slider option is two more bits, and so on? I don't think any of these bit/byte measurements that you are coming up with have any meta consensus backing them up, while I am basing my byte calculations off of the meta post for scoring Desmos answers found here. Unless there is some kind of meta consensus regarding the scoring of sliders and such, I won't be changing my answer to include any of that. \$\endgroup\$
    – Aiden Chow
    Jun 26, 2023 at 6:42
  • \$\begingroup\$ That's fair. I just figured that since each slider is either running or not running, that would be one bit, and because there are four options for the slider that would be two bits, but yeah, I have no meta backing for those numbers. I just think that maybe using a running slider instead of a ticker could be promising. \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 6:51
  • \$\begingroup\$ @Dadsdy To be fair, while there is currently no consensus on scoring sliders (and many other things in Desmos, like graph settings, setting the colors of an expression, tables, and so on), you could potentially post a follow-up meta post of sorts to address these other cases, if you choose to. \$\endgroup\$
    – Aiden Chow
    Jun 26, 2023 at 7:04
  • \$\begingroup\$ Meta post posted \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 7:11
8
\$\begingroup\$

C (gcc), 30 bytes

Prints a newline every second.

main(){main(sleep(puts("")));}

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ Waits a second between writing newlines. Writing a newline takes some amount of time, so it doesn't print something every second. \$\endgroup\$ Jun 26, 2023 at 15:32
  • 3
    \$\begingroup\$ @CrisLuengo The challenge says it has to wait 1 second plus or minus 10 ms. I'm pretty sure printing a newline takes less than 10 ms on most computers. \$\endgroup\$
    – Aiden Chow
    Jun 26, 2023 at 18:05
  • \$\begingroup\$ How exactly does it work? The standard just seems to demand that puts returns a non-negative number on success. I assume it is 1 in this case, which is used as the number of seconds to sleep. But is this guaranteed or does this only work in certain implementations. Or phrased differently, are there implementations of puts where this won't work? \$\endgroup\$ Jun 28, 2023 at 9:17
  • \$\begingroup\$ @infinitezero I believe the return behavior of puts is actually undefined, but for most implementations it appears to return the number of bytes outputted. You could probably call it a "hack"; I think it's a neat way to save a few bytes :) \$\endgroup\$ Jul 5, 2023 at 7:13
  • 1
    \$\begingroup\$ @infinitezero It would be \n, because puts outputs a single newline :) \$\endgroup\$ Jul 5, 2023 at 7:29
7
\$\begingroup\$

Factor, 18 bytes

[ .s ] 1e9 every .

Try it online!

every calls a function each time a duration has passed. If every is not given a duration such as 1 seconds, and instead given a number, it defaults to nanoseconds. Thus, one billion (or 1e9) means one second. .s simply prints the contents of the data stack without consuming them, which in this case will print the timer object every uses to do its thing. The . at the end is necessary to satisfy the stack effect checker by removing the item on the data stack (because Factor programs must end with an empty stack), even though it will never be reached.

\$\endgroup\$
2
  • \$\begingroup\$ In the TIO link, the program immediately ends \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 6:06
  • \$\begingroup\$ Well I wouldn't expect TIO to handle threads properly. Works fine locally. \$\endgroup\$
    – chunes
    Jun 26, 2023 at 6:09
7
\$\begingroup\$

Javascript, 22 20 19 Bytes

Thanks to @Kaiido for -2 Bytes Thanks to @Elias Holzmann for -1 Bytes

setInterval({},1e3)

https://jsfiddle.net/ry2sgkz7/

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Please don't link to fiddles that alert infinitely! Gave me quite a scare when I accidentally clicked it on a browser window with lots of unsaved stuff. \$\endgroup\$
    – noodle man
    Jun 26, 2023 at 15:47
  • 2
    \$\begingroup\$ Also, setInterval(alert,1e3) is one ms more accurate for same byte count \$\endgroup\$
    – noodle man
    Jun 26, 2023 at 15:48
  • \$\begingroup\$ @noodleman fixed \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 17:25
  • 4
    \$\begingroup\$ Given that the output can be anything I guess setInterval("a",1e3) would work, this does output "Uncaught ReferenceError: a is not defined" in the console every second for 2 saved bytes. \$\endgroup\$
    – Kaiido
    Jun 27, 2023 at 12:55
  • 1
    \$\begingroup\$ @Kaiido great suggestion, I'm stealing this for my answer ^^ \$\endgroup\$
    – Kaddath
    Jun 28, 2023 at 11:52
6
\$\begingroup\$

shell + GNU/Linux core utils, 11 bytes

watch -n1 w

A bit of a boring answer.

\$\endgroup\$
6
\$\begingroup\$

*><>, 4 bytes

Prints "10" on startup, and once every second

a:nS

Try it online!

Explanation

a      # Push 10 onto the stack
 :     # Duplicate it
  n    # Pop a value off the stack, and print it as a decimal number
   S   # Pop a value off the stack, and sleep for 100ms * the popped value
\$\endgroup\$
6
\$\begingroup\$

Vyxal j, 5 bytes

⁽kNḞU

Don't Try it Online! - it doesn't work there.

This one's kind of hilarious. It creates an infinite list of times, and then uniquifies them. The j flag is necessary due to how Vyxal handles printing infinite lists.

   Ḟ  # Generate an infinite list from...
⁽     # A function that returns
 kN   # The current time of day (hh:mm:ss)
    U # Get unique values

enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ Does it work if left on for an entire day? \$\endgroup\$ Jul 4, 2023 at 9:08
  • \$\begingroup\$ @UnrelatedString It's linear in space complexity, so... probably? Eventually it will reach a point where it can't perform the check in time. \$\endgroup\$
    – emanresu A
    Jul 4, 2023 at 11:23
  • \$\begingroup\$ I say an entire day because if it's only uniquifying hours-minutes-seconds, the intended outputs should cease to be unique after a full day. \$\endgroup\$ Jul 4, 2023 at 11:40
  • 3
    \$\begingroup\$ @UnrelatedString Oops. \$\endgroup\$
    – emanresu A
    Jul 4, 2023 at 11:54
  • \$\begingroup\$ You can shrink it by using the = flag, but apparently I shouldn’t poke Vyxal answers with a comment like this. \$\endgroup\$ Jul 9, 2023 at 13:41
5
\$\begingroup\$

MATL, 7 bytes

`@D1Y.T

This displays the natural numbers in order. Try at MATL online!

How it works

`      % Do...while
  @    %   Push iteration index, starting at 1
  D    %   Display
  1    %   Push 1
  Y.   %   Pause for that many seconds
  T    %   Push true. This is used as loop condition, causing an infinite loop
       % End (implicit)
\$\endgroup\$
5
\$\begingroup\$

(,), 60 62 61 Chars or \$61\log_{256}(3)\approx\$ 12.09 Bytes

((),((()))((())))((()),((())))(,((()),(),(),,((())),()),,,())
((),((()))((()))) Sets variable 1 to -2.
((()),((()))) sets variable -2 (time) to itself. (AKA setting the current time to 0)
(, Start of loop
((()),(),(),,((())),()) If variable -2 (time) is at least 1, reduce it by 1 and output 1\n
,,,()) Loop forever

First solution sometimes had the second output less than a second after the first.

\$\endgroup\$
2
  • \$\begingroup\$ What does this mean? Could you post an explanation? \$\endgroup\$ Jun 26, 2023 at 15:32
  • \$\begingroup\$ @CrisLuengo Does this help? \$\endgroup\$
    – Dadsdy
    Jun 26, 2023 at 23:19
5
\$\begingroup\$

Jelly, 5 bytes

1œSṄ¿

A full program which prints 1 and a newline and then after (just over) one second has elapsed prints another, then repeats this step forever.

It's "just over" as it takes some time to do the work. The first pause could take more than 1 second on slow hardware as Jelly has to initialise Python, and itself (create an interpreter, import some cruft, etc.) and parse the code. Subsequent pauses are unlikely to be over the 1.01 second threshold however as it just needs to check that the result is truthy and print to STDOUT.

Try it online! (TIO does not output anything as a program runs, but kill it while in flight and take a look; killing within a second should give a single 1 in the "Output" section, leaving it running longer should give more outputted 1s for each second that passed.)

How?

1œSṄ¿ - Main Link: no arguments
1     - set the left argument to one
    ¿ - while...
 Ṅ    - ...condition: print {left=1} and a newline, and yield {left=1}
  œS  - ...action: sleep for {implicit right=left=1} seconds and yield {left=1}

Replace with Ȯ for no newlines.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Congratulations on 100001! \$\endgroup\$ Jun 27, 2023 at 11:37
  • 1
    \$\begingroup\$ Thanks @DominicvanEssen, hitting the palindrome at the same time as passing the 100K milestone is a lovely little bit of icing on that internet-point cake :) \$\endgroup\$ Jun 27, 2023 at 17:06
4
\$\begingroup\$

PHP, 22 21 17 bytes

for(;;a)sleep(1);

Try it online!

I think the naive approach will be the shortest here. On TIO the output will be visible only when stopping the program of course

EDIT: saved 1 byte by echoing the falsey result of sleep, it works because sleep returns zero instead of false which would have lead to an empty string

EDIT 2: stole the suggestion from this JS answer by triggering a warning instead of an echo

\$\endgroup\$
4
\$\begingroup\$

TI-Basic (TI-84+), 22 bytes

startTmr
While 1
If checkTmr(Ans:Then
Disp Ans
startTmr
End
End
\$\endgroup\$
4
\$\begingroup\$

Racket, 43 37 28 26 bytes

Changelog

  1. Thanks to @Dadsdy for the -2 bytes.
  2. The -4 bytes comes from converting #lang racket to #!racket.
  3. Another -9 as I found out that language statements may go into the header of TIO, and as such, don't contribute to number of bytes.
  4. I just learnt about Racket's do loop! -2 bytes! 🎉

Code

(do()(#f)(write(sleep 1)))

Try it online!


Explanation

We create a do loop that runs infinitely. Since we used #f (false) in dos second argument, the loop won't terminate as it will only terminate if there is a #t value.

If we were to expand this out and make it more readable, it would look like this:

(do () (#f)
  ; (sleep 1) doesn't return anything, so #<void> will be printed.
  (write (sleep 1)))

The do loop acts a bit similar to JavaScript's while loop:

while (!false) {
  // ...
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ -2 bytes with write(sleep 1) \$\endgroup\$
    – Dadsdy
    Jul 8, 2023 at 19:07
3
\$\begingroup\$

GFA-Basic 3.51 (Atari ST), 15 bytes

A manually edited listing in .LST format. All lines end with CR, including the last one.

DO
?0
PA 50
LO

which expands to:

DO
  PRINT 0
  PAUSE 50
LOOP

We could use DELAY 1 instead of PAUSE 50. Unfortunately, the shortest unambiguous abbreviation of DELAY is DELA.

Output

After 5 seconds:

output

\$\endgroup\$
3
  • \$\begingroup\$ It's strange that PAUSE works with value in 1/50th second :P \$\endgroup\$
    – Kaddath
    Jun 27, 2023 at 10:54
  • \$\begingroup\$ @Kaddath It's most probably based on the vertical blank interrupt, which occurs 50 times per second on a PAL / SECAM machine. \$\endgroup\$
    – Arnauld
    Jun 27, 2023 at 11:00
  • \$\begingroup\$ It would however require some tweaks to work with NTSC (60Hz) and hi-resolution mode (70Hz). According to the documentation, the value is always expressed in 1/50th second, no matter the system or the screen resolution. \$\endgroup\$
    – Arnauld
    Jun 27, 2023 at 11:25
3
\$\begingroup\$

x86-16 machine code, PC DOS, 14 bytes

00000000: b42c cd21 3ac6 74fa 8ac6 cd29 ebf4       .,.!:.t....)..

Listing

B4 2C       MOV  AH, 2CH        ; DOS API get system time function 
        SEC_LOOP: 
CD 21       INT  21H            ; Read time: DH = seconds 
3A C6       CMP  AL, DH         ; second changed? 
74 FA       JE   SEC_LOOP       ; continue polling if not 
8A C6       MOV  AL, DH         ; save new second 
CD 29       INT  29H            ; write AL to console 
EB F4       JMP  SEC_LOOP       ; loop indefinitely 

A standalone executable DOS COM program. Spams the DOS time function and writes the corresponding ASCII codepoint for the number of seconds.

Several minutes later...

enter image description here

\$\endgroup\$
3
\$\begingroup\$

Batch, 15 13 9 bytes

ping -t 0

After some initial output, outputs the following every second:

PING: transmit failed. General failure.

Edit: Saved 4 bytes thanks to @c--.

Previous 15-byte solution:

timeout/t 1
%0

Repeatedly outputs the following:


C:\Users\Neil>timeout/t 1 

Waiting for 1 seconds, press a key to continue ...0

C:\Users\Neil>262205.bat

When output is to the screen, the cursor is moved so that the 0 overwrites the 1.

\$\endgroup\$
0
3
\$\begingroup\$

C# (Visual C# Interactive Compiler), 45 bytes

Nothing special

for(;;){Thread.Sleep(1000);Console.Write(1);}

Try it online!

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

Nim, 36 bytes

import os
while 0<1:echo 1;sleep 999

Attempt This Online!

\$\endgroup\$
3
\$\begingroup\$

Perl 5, 19 bytes

say 2 while sleep 1

Try it online!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ I don't think the space between 2 and while is necessary. And if you're fine with just printing newlines, there are multiple 16 byters: 1while sleep say or {sleep say;redo} \$\endgroup\$
    – ovs
    Jun 27, 2023 at 13:26
  • \$\begingroup\$ This will not do. sleep 1 will sleep for at least 1 second (unless you have an old version of perl 5, then it may sleep less), but perl won't guarantee it won't sleep longer. It will be at the mercy of the OS it's running on. But to be fair, most, if not all submissions will suffer from this. \$\endgroup\$
    – Abigail
    Jun 30, 2023 at 2:13
3
\$\begingroup\$

Julia 1.0, 24 21 bytes

!x=!show(sleep(1))
!0

Try it online!

-3 bytes thanks to ovs: improve recursion, and redefine an operator (An argument has to be passed to it, but this can be ignored by the function)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think !x=!show(sleep(1));!0 would work for 21 as a full program \$\endgroup\$
    – ovs
    Jun 27, 2023 at 13:31
3
\$\begingroup\$

Japt, 7 4 bytes

Outputs a ReferenceError.
Any lowercase letter word work instead of the second i.

A³ii

Test it (Open your browser's console)

\$\endgroup\$
2
  • \$\begingroup\$ Perhaps I'm missing something obvious here, isn't the last A redundant? \$\endgroup\$
    – Etheryte
    Jun 28, 2023 at 21:49
  • 1
    \$\begingroup\$ Sadly not, @Etheryte; as it turns out, if you don't pass an argument to O.l() then it does nothing. \$\endgroup\$
    – Shaggy
    Jun 28, 2023 at 23:34
3
\$\begingroup\$

ELF (x86/x64, Linux), 112 bytes

Prints 'A' about once per second, indefinitely.

00000000: 7f45 4c46 fec0 505f e81b 0000 0000 0000  .ELF..P_........
00000010: 0200 3e00 0000 0000 0400 0000 4100 0000  ..>.........A...
00000020: 3800 0000 0000 0000 5e40 80c6 3f50 5a0f  8.......^@..?PZ.
00000030: 0504 2256 eb32 3800 0100 0000 0500 0000  .."V.28.........
00000040: 0000 0000 0000 0000 0000 0000 4100 0000  ............A...
00000050: 0100 0000 0000 0000 7000 0000 0000 0000  ........p.......
00000060: 7000 0000 0000 0000 5faf 0f05 eb96 0000  p......._.......

Try it online! (Prints 60 A's before TIO kills the process)

Explanation

The file abuses a lot of undefined behavior within the Linux ELF loader; the kernel is able to make a lot of (correct) assumptions when certain fields are not the right value. Here is the full NASM source.

Basically, the executable is just an ELF header, a program header (partially merged into the ELF header), and the actual program (which is spread throughout the two headers so that it doesn't take up any additional space). The full program calls sys_write(stdout, "A", 1), then sys_nanosleep({tv_sec=1, tv_nsec=112}, <nonsense valid pointer>), and then loops back to the start.

\$\endgroup\$
2
\$\begingroup\$

R, 27 25 bytes

Edit: -2 bytes thanks to @Dominic van Essen.

repeat show(Sys.sleep(1))

Try it online!

This works well on my local machine, but TIO accumulates output until it finishes execution, so you don't see the progress.

\$\endgroup\$
4
  • \$\begingroup\$ repeat show(Sys.sleep(1)) is 25 bytes... \$\endgroup\$ Jun 26, 2023 at 7:34
  • \$\begingroup\$ @DominicvanEssen Didn't think of that, thanks! \$\endgroup\$
    – pajonk
    Jun 26, 2023 at 8:24
  • \$\begingroup\$ This answer also waits 1 s between printing things, which is not the same as printing something every second because the act of printing takes time. \$\endgroup\$ Jun 26, 2023 at 15:33
  • 2
    \$\begingroup\$ @CrisLuengo, fortunately the printing is pretty fast and takes less than 10ms (at least on my machine). \$\endgroup\$
    – pajonk
    Jun 26, 2023 at 17:19
2
\$\begingroup\$

Arturo, 23 bytes

whileø[1:s>>{a}1pause]
whileø[     ; start infinite loop (while loop with null for condition)
    1:s     ; push duration of 1 second to stack
    >>{a}1  ; create/overwrite file named a
    pause   ; pause execution for one second (which we left on the stack earlier)
]           ; end while
\$\endgroup\$
2
\$\begingroup\$

Pyth, 6 bytes

#.d
.j

Try it online!

Explanation

#        # loop forever until error (no error will occur)
   .j    # imaginary number i, printed
 .d      # sleep for abs(i) seconds

It may seem weird that I have to sleep for \$|i|\$ seconds, why not just 1? While that would save a byte, unfortunately .d1 is a predefined macro which returns the amount of time which has passed since the program started, which is not really useful for this challenge.

\$\endgroup\$
2
\$\begingroup\$

Charcoal, 10 bytes

RWφψPI¬ΣKK

Try it online! Link is to verbose version of code. Uses control codes to toggle the top left corner between 1 and 0, so on TIO you need to let it run for a few seconds and then interrupt it to see the control codes and 1s and 0s. Explanation:

RWφψ

Repeat indefinitely, showing the current canvas with a 1000ms delay on each repeat.

PI¬ΣKK

Toggle the current character between 1 and 0.

\$\endgroup\$
2
\$\begingroup\$

Lua, 50 bytes

o=os.time::a::t=o()repeat until t<o()print()goto a

Try it online!

A platform independent solution. You can make this shorter by using os.execute, but that solution is both platform dependent and not very interesting.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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