| Bytes | Lang | Time | Link |
|---|---|---|---|
| 062 | Tcl | 250516T202321Z | sergiol |
| 033 | Ruby | 250516T195923Z | Jordan |
| 008 | Husk | 201031T235922Z | LegionMa |
| 058 | Java JDK | 200829T213723Z | Olivier |
| 047 | R | 200828T215635Z | Dominic |
| 051 | PHP | 200831T101736Z | Kaddath |
| 099 | SimpleTemplate 0.84 | 200831T095300Z | Ismael M |
| 008 | 05AB1E | 200831T064751Z | Kevin Cr |
| 010 | APL Dyalog Unicode | 200828T160847Z | Adá |
| 035 | Wolfram Language Mathematica | 200829T214922Z | att |
| 038 | C gcc | 200828T163116Z | AZTECCO |
| 236 | Assembly MIPS | 200829T075301Z | user9649 |
| 012 | Pip | 200828T164346Z | Razetime |
| 044 | Python 2 | 200829T010434Z | xnor |
| 087 | Batch | 200828T213012Z | Neil |
| 009 | Jelly | 200828T212322Z | Jonathan |
| 047 | Python 3.8 prerelease | 200828T161526Z | user |
| 3433 | x8616 machine code | 200828T180656Z | 640KB |
| 1716 | J | 200828T162017Z | Jonah |
| 087 | SNOBOL4 CSNOBOL4 | 200828T161449Z | Giuseppe |
| 013 | Japt | 200828T171531Z | Shaggy |
| 040 | JavaScript V8 | 200828T155929Z | Arnauld |
Ruby, 33 bytes
Takes input as a ratio of printed lines to blank lines. Prints indefinitely.
->s,m,n{loop{puts (s+$/)*m,$/*n}}
Husk, 8 bytes
~o¢+RøR⁰
Try it online! This program takes the string, the number of lines with text, and the number of lines without text as three separate arguments.
Java (JDK), 58 bytes
(s,n,d)->{for(int i=0;;)System.out.println(i++%d<n?s:"");}
Credits
- 4 bytes saved thanks to Kevin Cruijssen.
R, 48 47 bytes
Edit: -1 byte thanks to Giuseppe
function(t,c)repeat cat(rep(c(t,''),c),sep='
')
Function with arguments specifying text t and vector c of counts of text & blank lines.
PHP, 52 51 bytes
for($a=$argv;;)echo($i++%$a[3]<$a[2]?$a[1]:"")."
";
Nothing new under the sun: PHP arguments and vars prefix eating bytes.. Will go on "forever" (until it overflows the max integer value, and starts using floats for $i, then probably the legendary precision for big floats will cause inconsistent results)
EDIT: newline replaced by.. a newline to save 1 byte
SimpleTemplate 0.84, 99 bytes
Yes, it is quite long, but it works!
{@callexplode intoM":",argv.1}{@while1}{@forfrom 1toM.0}{@echolargv.0}{@/}{@forfrom 1toM.1}{@echol}
Takes input in the form of an array with the format ['text', '1:1'].
If taking input as 2 separate numbers (['text', 1, 1]) is acceptable, the code can be reduced to this (66 bytes):
{@forfrom 1toargv.1}{@echolargv.0}{@/}{@forfrom 1toargv.2}{@echol}
Ungolfed:
Below is a more readable version of the top code:
{@call explode into ratio ":", argv.0}
{@while true}
{@for i from 1 to ratio.0}
{@echo argv.0, EOL}
{@/}
{@for i from 1 to ratio.1}
{@echo EOL}
{@/}
{@/}
Notice that {@echol} and {@echo EOL} do the same thing: output whatever, ending with a newline.
You an try it on: http://sandbox.onlinephpfunctions.com/code/abf48bd44a808e91f130d4a390fcb8a18d6ded39
05AB1E, 8 bytes
[s`¶×?F=
First input is the text, second input is a pair [amount_of_nonempty_lines, amount_of_empty_lines]; outputs the empty lines before the non-empty lines.
Explanation:
[ # Start an infinite loop:
s # Swap the two (implicit) inputs, so the pair it at the top of the stack
` # Pop and push its contents to the stack
¶× # Repeat a newline character "\n" the top value amount of times as string
? # Pop and output it without trailing newline
F # Pop and loop the top value amount of times:
= # And output the top string with trailing newline (without popping)
APL (Dyalog Unicode), 10 bytes (SBCS)
Full program. Prompts for text, then for ratio of lines with text to lines without (as two integers). Runs forever.
⎕←⍣≢↑⎕/⍞''
⍞'' prompt for text and juxtapose with an empty string
⎕/ prompt for replication factors and replicate
↑ stack them on top of each other
⍣≢ repeat until the value changes (i.e. never):
⎕← output
Wolfram Language (Mathematica), 35 bytes
Do[Print@If[i>#2,#,""],∞,{i,#3}]&
Takes [text, num, denom], where num/denom is the ratio of lines without text.
C (gcc), 67 .. 38 bytes
i;f(s,a,t){for(;puts(i++%t<a?s:""););}
- Thanks to @att for 11 byte saved and to @ErikF for 7 bytes saved!
Takes input as string, number of printed lines, total lines.
We flush buffer at every iteration.
puts() returns non negative if no error occours, hope it doesn't return 0 either!
Assembly (MIPS, SPIM), 236 bytes, 6 * 23 = 138 assembled bytes
Full program that takes the input in the order (input string, numerator, denominator). Output is to STDOUT.
.data
m:
.text
main:li$v0,8
la$a0,m
li$a1,99
syscall
li$v0,5
syscall
move$t0,$v0
li$v0,5
syscall
move$t1,$v0
s:li$t2,0
li$v0,4
la$a0,m
l:syscall
add$t2,$t2,1
blt$t2,$t0,l
li$t2,0
li$a0,10
li$v0,11
p:syscall
add$t2,$t2,1
blt$t2,$t1,p
b s
Explanation
.data
msg: # Here's the string input buffer (dynamically allocated)
.text
main:
li $v0, 8 # Set syscall code 8
la $a0, msg # The first operand is the input buffer
li $a1, 99 # The second is the maximum length of input
syscall # Read a line of characters from input
li $v0, 5 # Set syscall code 5
syscall # v0 = integer from input
move $t0, $v0 # t0 = v0
li $v0, 5 # Re-set syscall code 5
syscall # v0 = integer from input
move $t1, $v0 # t1 = v0
start: # Main loop:
li $t2, 0 # t2 = 0 (our counter)
li $v0, 4 # Set syscall code 4
la $a0, msg # First operand: the inputted message at msg
loop: # loop:
syscall # Print the message at msg
add $t2, $t2, 1 # Increment counter
blt $t2, $t0, loop # If t2 < t0, jump back
li $t2, 0 # Clear counter
li $v0, 11 # Set syscall code 11
li $a0, 10 # First operand: '\n'
lop: # second loop:
syscall # Print character in a0
add $t2, $t2, 1 # Increment counter
blt $t2, $t1, lop # if t2 < t1, jump back
b start # Jump back to the main loop
Pip, 26 12 bytes
T0{LbPaLcPx}
-14 bytes after taking ratio as two arguments.
Explanation:
T0 Till 0 (infinite loop)
{Lb Loop b(second argument) number of times
Pa Print a(first argument) with newline
Lc Loop c(third argument) number of times
Px} Print x(empty string) with newline
Python 2, 44 bytes
def f(t,a,b,n=0):print(n%b<a)*t;f(t,a,b,n+a)
Prints until exceeding max recursion depth, which the challenge seems to allow. As a program:
45 bytes
t,a,b=input()
n=0
while 1:print(n%b<a)*t;n+=a
The idea is to to use a counter n that cycles through values modulo b, and only print the text if this is from 0 to a-1, and otherwise print a blank line. We could also do n+=1 in place of n+=a to get a different pattern where the text and blank lines come in clumps rather than mixed throughout.
It almost works to use a float input for the density as below:
40 bytes (not working)
def f(t,p,n=0):print(n%1<p)*t;f(t,p,n+p)
The issue is float imprecision -- a number like 12.6 might have its decimal part be very slightly bigger or smaller than 0.6. This method would work for irrational densities as well, limited precision aside.
Batch, 87 bytes
@set f=@for /l %%i in (1,1,
@set/ps=
:g
%f%%1)do @echo(%s%
%f%%2)do @echo(
@goto g
Takes the text and blank line counts as command line arguments and the text to repeat on standard input. Explanation:
@set f=@for /l %%i in (1,1,
Define what is effectively a macro for two very similar loops.
@set/ps=
Input the text.
:g
Begin an infinite loop.
%f%%1)do @echo(%s%
Print the text the desired number of times.
%f%%2)do @echo(
Print the desired number of blank lines.
@goto g
Rinse and repeat.
Jelly, 9 bytes
Ø.x⁹ẋṄ€1¿
A full program accepting the ratio as a list [empty, full] and the string which prints forever.
How?
Ø.x⁹ẋṄ€1¿ - Main Link: list of integers, ratio ([empty, full]); list of characters, text
e.g.: [3, 2]; "Hello, world!"
Ø. - bits [0, 1]
x - times (ratio) [0, 0, 0, 1, 1]
⁹ - chain's right argument "Hello, world!"
ẋ - repeat (vecorises) ["", "", "", "Hello, world!", "Hello, world!"]
¿ - while...
1 - ...condition: 1 (always)
€ - ...do: for each:
Ṅ - print with trailing newline
Python 3.8 (pre-release), 48 47 bytes
Saved a byte thanks to Dion
def f(t,a,b):
while 1:print((t+'\n')*a+'\n'*b)
t is the text to print, a:b is the ratio of lines of text to empty lines.
x86-16 machine code, IBM PC DOS, 34 33 bytes
Binary:
00000000: be82 00ad 2d30 3092 52fe ca7c 0956 ac3c ....-00.R..|.V.<
00000010: 0dcd 2975 f95e b00a cd29 fece 75eb 5aeb ..)u.^...)..u.Z.
00000020: e7 .
Listing:
BE 0082 MOV SI, 82H ; SI to command line tail
AD LODSW ; load first two chars
2D 3030 SUB AX, '00' ; ASCII convert
92 XCHG AX, DX ; DL = numerator, DH = denominator
PATT_LOOP:
52 PUSH DX ; save original numerator/denominator
FRAC_LOOP:
FE CA DEC DL ; decrement numerator
7C 09 JL LF ; if less than 0, just display LF
56 PUSH SI ; save start of input string
CHAR_LOOP:
AC LODSB ; load next char of string
3C 0D CMP AL, 0DH ; is it a CR?
CD 29 INT 29H ; write to console
75 F9 JNZ CHAR_LOOP ; if not a CR, keep looping
5E POP SI ; restore start of input string
LF:
B0 0A MOV AL, 0AH ; LF char
CD 29 INT 29H ; write to console
FE CE DEC DH ; decrement denominator
75 EB JNZ FRAC_LOOP ; if not 0, keep looping
5A POP DX ; restore numerator/denominator
EB E7 JMP PATT_LOOP ; start over and loop indefinitely
Standalone DOS executable, input via command line. First two chars are numerator / denominator, followed by input string.
(note: program slightly altered to only repeat 3 times for screenshots)
J, 17 16 bytes
$:,[echo@#'',:~]
Note: If the empty lines cannot have spaces, then $:,[echo@>@#a:;~] works for 17 bytes.
how
Uses a kind of "fork bomb" recursion:
$:- calls entire verb again,- then append...[echo@#- the echo of the left argument applied as a line-wise multiplier to...'',:~]- the right argument catted line-wise with an empty string
SNOBOL4 (CSNOBOL4), 100 88 87 bytes
T =INPUT
CODE('N' DUPL('; OUTPUT =T',INPUT) DUPL('; OUTPUT =',INPUT) ':(N)') :(N)
END
Takes input as TEXT, M, N on separate lines.
Using the CODE function, this generates an infinite loop of
N; OUTPUT =T; OUTPUT =T ...; OUTPUT =; OUTPUT =; ... :(N)
Or equivalently (with ; being replaced by newlines):
N
OUTPUT =T
OUTPUT =T
...
OUTPUT =
OUTPUT =
...
OUTPUT =:(N)
Which it then enters with the final :(N) and never leaves.
JavaScript (V8), 40 bytes
Expects (p, q)(s), where \$p/q\$ is the fraction of lines that have the string \$s\$ in them.
This runs until the call stack overflows.
(p,q,t=0)=>g=s=>print(t++%q<p?s:'')&g(s)

