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\$ Commented 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\$ Commented 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\$ Commented 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\$ Commented Jun 26, 2023 at 5:36
  • 1
    \$\begingroup\$ Yes, that's what I mean. \$\endgroup\$ Commented Jun 26, 2023 at 5:51

46 Answers 46

1
2
2
\$\begingroup\$

GBZ80 machine code (DMG mode): 19 bytes

21 0F FF 3E 01 E0 FF 06 78 76 70 05 20 FB 2F E0 47 18 F4 

Assembly:

Entrypoint: ld hl, $ff0f ld a, $01 ldh [$ffff], a ; only accept vblank interrupts .outerLoop: ld b, 120 .innerLoop: db $76 ; directly encoded halt. saves one byte over "halt" in my assembler. ; since by deliberate design IE & IF is sometimes not zero here, we encounter the halt bug. fortunately, "ld [hl], b" is a one byte instruction whose duplication is, excluding time, transparent (with exceptions that would be familiar to those who encounter them) ld [hl], b ; discard the pending interrupt every other pass (even parity) dec b jr nz, .innerLoop cpl ldh [$ff47], a ; invert the palette jr .outerLoop 

This is just counting vblanks, with some mangling to save a single byte from not loading an immediate to clear the vblank interrupt flag. The effect produced every second is inverting the screen colors. This does not work in CGB mode because the register for the DMG background palette does nothing in CGB mode.

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

05AB1E, 5 bytes

[₄=.W 

Keeps printing 1000\n every second.

Try it online.

Explanation:

[ # Start an infinite loop: ₄ # Push 1000 = # Print it with trailing newline (without popping) .W # Pop and sleep that many milliseconds 
\$\endgroup\$
2
\$\begingroup\$

Python 2, 38 Bytes

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

TIO

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

simply, 93 bytes

Outputs a 9x9 image with a random color, every 999 milliseconds - which is within the 10ms error range.

%C=run!CANVAS->init(9,9)run%C->ontick(fn()=>run%C->fillRect(0 0 9 9run%C->getRandomColor)999) 

It does exactly what it's supposed to.


Ungolfed

This code does exactly the same.

$fn = anonymous function() { $color = call %canvas->getRandomColor(); call %canvas->fillRect(0, 0, 9, 9, $color); }; %canvas = call !CANVAS->init(9, 9); call %canvas->ontick($fn, 999); 

I'm too lazy to write a full English-like version.


If you need more information, to confirm it does do what it's supposed to do, just add this after the code:

// Golfed version: call %C->showDebug(); // Ungolfed version: call %canvas->showDebug(); 

To make sure it is running, just check that the (manually) underlined value changes at a rate of ~1 second:
Debug output

That value represents the number of frames that were actually drawn.
By default, the code avoids re-drawing the canvas if there were no updates.
And each call to fillRect will trigger a single update.

You can replace ontick with onframe or onclick to verify that the value really represents what I've said.

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

PowerShell, 16 bytes

Paste it into a PS console (Windows or Core) (not using TIO because that will only show the output once the script is stopped):

for(){sleep 1;1} 

Will print 1 every second until Ctrl-C is pressed.
Nothing remarkable, just for the sake of completeness when it comes to languages.

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

QBasic, 13 bytes

I'm not sure how rules-bendy to get, but here's the shortest possible version:

? SLEEP 1 RUN 

You can try it at Archive.org.

Explanation

? ' Print a blank line SLEEP 1 ' Wait 1 second RUN ' Restart the program 

Once the screen is filled up with blank lines, you won't be able to see new output happening, and you can't select the outputted text. So here's a 15-byte version that will be visually different each time something is printed:

?0; ' Print 0 without a newline SLEEP 1 ' Wait 1 second RUN ' Restart the program 
\$\endgroup\$
1
\$\begingroup\$

Wolfram Language (Mathematica), 21 bytes

Dynamic@Floor@Clock@2 

A dynamic object that alternates between 0 and 1 every second. This only works in the Notebook interface, so no TIO link.


Wolfram Language (Mathematica), 23 bytes

Echo@True~While~Pause@1 

Try it online!

Prints True every second.

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

><> -t0.5, 2 bytes

1n 

Try it online!

><> has an extra flag to set the time between ticks, presumably to help with debugging. This code simply outputs a 1 every 2*0.5 seconds.

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

Vyxal , 5 Bytes

{1¨w, 

Try it online (collects all the output received in ten seconds (or sooner if it halts) and prints it all at once.)

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

ARM Thumb machine code + Linux syscalls, 28 bytes

00: 2202 movs r2, #2 // 2 bytes 02: 2704 movs r7, #4 // write() 04: 2001 movs r0, #1 // stdout 06: a104 adr r1, #0x18 // pointer to 0x18 "!\n" 08: df00 svc #0 // syscall write(1, "!\n", 2) 0a: 27a2 movs r7, #162 // nanosleep() 0c: a001 adr r0, #0x14 // pointer to 0x14 0e: 2100 movs r1, #0 // NULL 10: df00 svc #0 // syscall nanosleep(&{1, 2593}, 0) 12: e7f6 b.n #0x02 // jump to 0x02, r2 won't have changed 14: 0000 0001 .word 1 // 1 second 18: 0000 0a21 .word 0x0a21 // "!\n" or 2593 nanoseconds 
\$\endgroup\$
1
\$\begingroup\$

Commodore BASIC (Commodore C64/C128, C16/+4, VIC-20, PET), ~61 ~45 tokenised BASIC bytes

0printti$:b=val(ti$)+1 1ifval(ti$)<bthen1 2goto 

This works by using the Commodore TI$ system variable. Firstly, this outputs the value of TI$ to the screen (which is in HHMMSS format). It then take the value of TI$ as a number and add one to it. It then waits until the current numeric value of TI$ is no longer a less significant number than the B variable, and then we GOTO line 0 to output the new value of TI$ to the screen. This continues until the STOP key is pressed, which will break the program (it may be continued with the CONT command).

Screenshot reflects an older iteration of this entry.

Output each second running on a Commodore C64

\$\endgroup\$
3
  • \$\begingroup\$ "The first output ... can be as soon as right when the program starts" so I don't think you need the initial FOR loop on line 0... \$\endgroup\$ Commented Jun 27, 2023 at 13:57
  • \$\begingroup\$ ...but, if 0 TO 937 really takes 'approximately one second', why not just PRINT 1 on line 1, and then GOTO 0 on line 2...? \$\endgroup\$ Commented Jun 27, 2023 at 14:02
  • \$\begingroup\$ This method definitely takes ~1 second (plus whatever overheads from the KERNAL and BASIC interpreter). According to Commodore BASIC, 0ti$="000000":forb=0to946:next:?ti/60 is ~1 second (again, slight variation on Commodore machine and PAL/NTSC), but thanks for the byte saving tips. \$\endgroup\$ Commented Jun 27, 2023 at 20:35
1
\$\begingroup\$

Minecraft Function, 30 bytes

say a schedule function a:b 1s 

Must be run as a function named b in a data pack named a. It prints [Server] a to chat once per second.

The first command simply says a, and the second command schedules the function to execute again in one second.

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

Ruby, 15 bytes

loop{p sleep 1} 

Attempt This Online!

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

Swift 6 (Linux w/ C interop), 41 40 39 38 bytes

import Glibc while sleep(1)<1{print()} 

Prints a newline every second. Needs import Darwin instead of import Glibc on macOS.

Swift 6 (pure), 55 bytes

while 0<1{print(try await Task.sleep(for:.seconds(1)))} 
\$\endgroup\$
0
\$\begingroup\$

Uiua, 11 bytes

⍥(&pπ&sl1)∞ 

Doesn't work online, but works locally.

⍥(&pπ&sl1)∞ ⍥( )∞ # infinite loop &sl1 # sleep for one second &pπ # print pi 
\$\endgroup\$
0
\$\begingroup\$

TI-Basic (TI-84), 15 bytes

startTimer Disp Ans Repeat checkTmr(Ans End prgmA 

needs to be stored in prgmA for the recursion

based on and improved over Yousername's answer

\$\endgroup\$
1
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.