| Bytes | Lang | Time | Link |
|---|---|---|---|
| 043 | Lua | 231215T212540Z | bluswimm |
| 028 | Vim | 231215T190428Z | Aaroneou |
| 006 | Thunno 2 | 230721T062842Z | The Thon |
| 035 | JavaScript | 221206T113450Z | Shaggy |
| 019 | ><> | 221206T105919Z | Emigna |
| 009 | Japt | 221030T202634Z | Shaggy |
| 097 | x86‑64 machine code on Linux | 221101T195054Z | Kai Burg |
| 037 | Julia 1.0 | 221101T202127Z | amelies |
| 017 | Gaia | 221030T111412Z | Cliff |
| 019 | Pushy | 221030T104939Z | FlipTack |
| 030 | jq R | 221030T100659Z | pmf |
| 039 | Python | 220731T184703Z | solid.py |
| 047 | C clang | 220817T124431Z | jdt |
| 137 | Swift | 220817T101826Z | Leena |
| 076 | Regex Boost | 220811T001922Z | Deadcode |
| 044 | sed | 220801T213951Z | Jiří |
| 026 | Zsh | 220810T064046Z | pxeger |
| 038 | C# function | 220804T094332Z | Acer |
| 055 | C gcc | 220805T154411Z | c-- |
| 179 | PHP function | 220802T203515Z | Ram Chan |
| 180 | brainfuck | 220804T172807Z | engineer |
| 041 | *><> | 220804T153139Z | Geoffrey |
| 015 | J | 220803T152005Z | Conor O& |
| 035 | Ruby | 220803T142713Z | game0ver |
| 054 | Alice | 220803T022228Z | Julian |
| 041 | R function | 220803T014012Z | qdread |
| nan | simply | 220731T173713Z | Ismael M |
| 145 | Rust full program | 220802T090604Z | mousetai |
| 037 | PowerShell | 220802T053736Z | mazzy |
| 023 | Knight | 220801T232715Z | 97.100.9 |
| 035 | PowerShell Core | 220801T220547Z | user3141 |
| 046 | vim | 220801T212931Z | Ray |
| 038 | Excel | 220801T212654Z | Engineer |
| 009 | 05AB1E | 220801T071221Z | Kevin Cr |
| 005 | Vyxal s | 220731T120234Z | lyxal |
| 023 | Perl 5 + pl | 220731T090135Z | Dom Hast |
| 039 | Kustom | 220801T105225Z | Leaf |
| 015 | BQN | 220801T085715Z | Dominic |
| 005 | Vyxal | 220731T192728Z | naffetS |
| 008 | Jelly | 220731T175918Z | Jonathan |
| 025 | Pyth | 220731T172011Z | princesa |
| 025 | lin | 220731T140454Z | Mama Fun |
| 4535 | JavaScript | 220731T080333Z | m90 |
| 033 | Factor + sequences.repeating | 220731T070540Z | chunes |
| 030 | Haskell | 220731T063940Z | xnor |
| 033 | Haskell | 220731T062014Z | Christia |
| 027 | Retina | 220731T061906Z | Neil |
| 013 | Charcoal | 220731T061740Z | Neil |
Vim, 28 bytes
D@=le<Tab>@")
iHelloWorld<Esc>@=
|lD
Explanation
D # Delete the input into the @" register
@= # Set @= register to:
le<Tab> ) # The length of:
@" # The @" register
iHelloWorld<Esc> # Type "HelloWorld" @= times
@= #
| # Move cursor to position @=
lD # Delete everything after the cursor
Thunno 2, 6 bytes
khỊsØE
Explanation
khỊsØE # Implicit input
khỊ # Push "HelloWorld"
sØE # Extend/truncate it
# to the input's length
# Implicit output
JavaScript, 35 bytes
I/O as an array of characters.
s=>s.map((_,x)=>"HelloWorld"[x%10])
><>, 19 bytes
"HelloWorld"i0(?;{o
Explanation
"HelloWorld" # push the string "HelloWorld"
i0(?; # take input, if there isn't more input, exit program
{o # else print the bottom of the stack
Japt, 9 bytes
î`HÁMWld
î`HÁMWld :Implicit input of string
î :Repeat & slice the following to length of input
`HÁMWld : Compressed string "HelloWorld"
x86‑64 machine code on Linux, 97 B
input
/dev/stdinconnected to a pipe or terminal in cooked mode- possibly empty input
- Linux zeros processor registers upon process initialization (with the obvious exception of
rsp).
source code
Uses NASM – the Netwide Assembler. Overview of algorithm:
- Infinitely wait until data become available. (
select) - Query total number of Bytes immediately available for reading. (
FIONREAD) - Discard input. (
TCIFLUSH) - Integer division: Bytes that were available for reading count divided by 10.
- Loop: Whole 10 Byte writes of
'HelloWorld'. - Write remainder of integer division Bytes.
global _start
bits 64
default rel
; These two constants rather serve as documentation:
STDIN_FILENO equ 0
STDOUT_FILENO equ 1
; Linux (`syscall`) system call numbers used in this program:
sys_exit equ 60
sys_ioctl equ 16
sys_select equ 23
sys_write equ 1
; `ioctl(2)` requests used:
FIONREAD equ 0x0000541B
TCFLSH equ 0x0000540B
; Argument to `TCFLSH` request:
TCIFLUSH equ 0
; ==============================================================
section .text
hello_world:
db 'Hello'
db 'World'
; 'HelloWorld'’s length is `10`, but this is cleaner style:
hello_world_length equ $ - hello_world
_start:
; rax rdi rsi rdx r10 r8
; select( 1, [rsp], NULL, NULL, NULL)
push 1 ; bitfield with LSB set
mov rsi, rsp ; *readfds
pop rdi ; nfds
push rdi ; rsp for get_iteration_count
mov al, sys_select
syscall
get_input_length:
; rax rdi rsi rdx
; ioctl(STDIN_FILENO, FIONREAD, [rsp])
xor edi, edi ; fd := 0 (STDIN_FILENO)
xchg rsi, rdx ; bytes available buffer
mov si, FIONREAD ; ioctl(2) request number
mov al, sys_ioctl
syscall
discard_input:
; rax rdi rsi rdx
; ioctl(STDIN_FILENO, TCFLSH, TCIFLUSH)
mov edx, edi ; TCIFLUSH = 0 → copy zero
mov sil, TCFLSH & 0xFF ; TCFLSH − 0x10 = FIONREAD
mov al, sys_ioctl
syscall
; `rax` may be non-zero now, in particular −ENOTTY.
test eax, eax ; for dumb last char = "\n" test
setns dil ; subtrahend = 0 for ENOTTY
get_iteration_count:
; Retrieve number of Bytes that were available for reading.
pop rax
sub eax, edi ; subtract 1 if this is terminal
jc exit ; user typed ^D (detach input)
; Load divisor.
push hello_world_length
pop rcx
; eax := number of whole writes; edx := Bytes in partial write
div ecx
; Save Bytes in partial write for `finish_write` below.
; The `push rdx`/`pop rdx` pattern is just two 2 Bytes.
push rdx
; Use `ebx` as loop counter, because `syscall` clobbers `rcx`
; and this does not require a REX prefix like r8 – r15 do.
xchg eax, ebx
write:
; rax rdi rsi rdx
; write(STDOUT_FILENO, hello_world, 10)
xchg edx, ecx
lea rsi, [hello_world]
mov dil, STDOUT_FILENO
test ebx, ebx ; zero _whole_ writes test
jz finish_write ; zero entire 10B writes
keep_writing:
mov al, sys_write
syscall
dec ebx
jnz keep_writing
; Write the remainining ≤ 9 Bytes.
finish_write:
pop rdx
mov al, sys_write
syscall
exit:
xchg ebx, edi ; rdi := 0 (= “successful”)
push sys_exit ; need to wipe entire register
pop rax ; because we may have jumped
syscall ; here from get_iteration_count
; vim: ft=nasm:
disassembly
helloWorld.o: file format ELF64-x86-64
Disassembly of section .text:
0000000000000000 <hello_world>:
0: 48 rex.W
1: 65 6C gs ins byte ptr es:[rdi], dx
3: 6C ins byte ptr es:[rdi], dx
4: 6F outs dx, dword ptr ds:[rsi]
5: 57 push rdi
6: 6F outs dx, dword ptr ds:[rsi]
7: 72 6C jb 75 <exit + 0x1B>
9: 64 fs
000000000000000A <_start>:
A: 6A 01 push 0x1
C: 48 89 E6 mov rsi, rsp
F: 5F pop rdi
10: 57 push rdi
11: B0 17 mov al, 0x17
13: 0F 05 syscall
0000000000000015 <get_input_length>:
15: 31 FF xor edi, edi
17: 48 87 F2 xchg rdx, rsi
1A: 66 BE 1B 54 mov si, 0x541B
1E: B0 10 mov al, 0x10
20: 0F 05 syscall
0000000000000022 <discard_input>:
22: 89 FA mov edx, edi
24: 40 B6 0B mov sil, 0xB
27: B0 10 mov al, 0x10
29: 0F 05 syscall
2B: 85 C0 test eax, eax
2D: 40 0F 99 C7 setns dil
0000000000000031 <get_iteration_count>:
31: 58 pop rax
32: 29 F8 sub eax, edi
34: 72 24 jb 5A <exit>
36: 6A 0A push 0xA
38: 59 pop rcx
39: F7 F1 div ecx
3B: 52 push rdx
3C: 93 xchg ebx, eax
000000000000003D <write>:
3D: 87 D1 xchg ecx, edx
3F: 48 8D 35 BA FF FF FF lea rsi, [rip + 0XFFFFFFFFFFFFFFBA]
46: 40 B7 01 mov dil, 0x1
49: 85 DB test ebx, ebx
4B: 74 08 je 55 <finish_write>
000000000000004D <keep_writing>:
4D: B0 01 mov al, 0x1
4F: 0F 05 syscall
51: FF CB dec ebx
53: 75 F8 jne 4D <keep_writing>
0000000000000055 <finish_write>:
55: 5A pop rdx
56: B0 01 mov al, 0x1
58: 0F 05 syscall
000000000000005A <exit>:
5A: 87 DF xchg edi, ebx
5C: 6A 3C push 0x3C
5E: 58 pop rax
5F: 0F 05 syscall
Having the 'HelloWorld' string in the .text section is weird, but putting (read-only) data into an already/definitely existing section, i. e. .text, makes the executable file smaller.
The stripped ELF64 executable file has a size of merely 440 B, not that that really mattered for code golfing.
output
- output lacks of a trailing newline
HelloWorldrepeating until the input’s length is reached- on a terminal input length − 1 accounting for a presumed terminating
"\n"[even if the user actually detached from inputCtrl‑D]
limitations
- I am not sure, but maybe the
FIONREADioctl(2)I am utilizing is capped at0x7FFFF000because oneread(2)can transfer at most this many Bytes? Therefore this program’s output will be limited to 2,147,479,552 Bytes accordingly. - At any rate, there’s a 32-bit
div ecx, so a string length ≥ 232 is not handled correctly. - If we’re reading from a pipe, the pipe’s capacity may be the limiting factor. In
pipe(7), § pipe capacity, it says the default value is 65536 B (so it can be changed). Similarly, a terminal’s input buffer may have comparable “low” dimensions. Yet these are implementation details outside of this program.
Gaia, 17 bytes
l:“HelloWorld”פ<
Pretty standard approach I think. It's a shame Gaia does not have a reshape to length built-in like BQN/J :(
Explained
l:“HelloWorld”פ<
l # Length of the input
: # push a second copy of that
“HelloWorld” # push the string "HelloWorld" to the stack
× # repeat that string by the length of the input
¤< # push the second copy of the length to the top of the stack and get the first n characters of the string
Python, 39 bytes
lambda s:('HelloWorld'*len(s))[:len(s)]
Python, 39 bytes
Alternative version proposed by mazunki:
lambda s:('HelloWorld'*(l:=len(s)))[:l]
Swift, 137 bytes
var a = readLine()!,h = "HelloWorld",c = h.count,j = a.count,i = Int(j/c),s="";for _ in 0..<i {s += h};s += String(Array(h)[0..<j - i*c])
Regex (Boost), 76 bytes
s/(.(.(.(.(.(.(.(.(.(.)?)?)?)?)?)?)?)?)?)?/?1H?2e?3l?4l?5o?6W?7o?8r?9l?10d/g
This is a single regex substitution, to be applied once.
It uses nested conditional replacement. The number of capture groups that get set is the number of characters matched, and they will always be consecutively numbered starting at 1.
It will start by matching the full 10 character length as many times as possible, which will be replaced each time with the full HelloWorld string. Then when it reaches a point where there are fewer than 10 characters remaining, it will do its last replacement.
Regex (PCRE2), 116
s/(.(.(.(.(.(.(.(.(.(.)?)?)?)?)?)?)?)?)?)?/${1:+H${2:+e${3:+l${4:+l${5:+o${6:+W${7:+o${8:+r${9:+l${10:+d}}}}}}}}}}/g
Try it on regex101!
Try it online!
PCRE2's conditional replacement syntax is quite a bit more verbose. But you can run this on regex101 and see it work in real time as you type (make sure to erase the test cases first, so it's as fast as possible).
C# (function), 38 bytes
x=>x.Select((_,i)=>"HelloWorld"[i%10])
---
C# (full program), 102 96 bytes
-6 bytes thanks to TKirishima
using System.Linq;System.Console.WriteLine(args[0].Select((_,i)=>"HelloWorld"[i%10]).ToArray());
This is a complete program in C#10 thanks to implicit top-level statements. TIO doesn't support this, but .NET Fiddle does.
PHP (function), 179 bytes
Used own logic and avoid system define function
function fnc($rs,$as){$dr="";$fv=explode(".",strval(strlen($as)/strlen($rs)));while((int)$fv[0]>0){$dr.=$rs;(int)$fv[0]--;}return $dr.=substr($rs,0,(int)strlen($as)%strlen($rs));}
PHP, 90 bytes
Sugested by @Steffan
function fnc($a){for($f=strlen($a);$f--;)$d.="HelloWorld";return substr($d,0,strlen($a));}
brainfuck, 180 bytes
>+[++[++>]<<+]>+[->>+>+>+>+>+>+>+>+>+<<<<<<<<<<]-[>+<-------]>->-------->>++++++>+++>--------------------->+++>>>------->,[>+<,]>[-<<[[->+<]<]>>.>>>>>>>>>[-<<<<<<<<<<+>>>>>>>>>>]>]
Can likely be golfed quite a bit more, as the majority of the code is setting up the string "HdlroWolle" on the tape.
Explanation:
>+[++[++>]<<+]>+ 108 = 'l'
[->>+>+>+>+>+>+>+>+>+<<<<<<<<<<] ptr before '\0lllllllll'
-[>+<-------]>- ptr on 'H'
>-------- 'd'
> 'l'
>++++++ 'r'
>+++ 'o'
>--------------------- 'W'
>+++ 'o'
> 'l'
> 'l'
>------- 'e' ("HdlroWolle")
> ,[>+<,] [Read all input, counting the length of it 2 cells after the string.]
>[-< Do len(input) times:
<[ Shift the string right by 1
[->+<]
<
]
[see https://www.codingame.com/playgrounds/50443/brainfuck-part-2---working-with-arrays]
[Print the first character of the string and move the far
right cell back to the beginning, rotating the string.]
>>.>>>>>>>>>[-<<<<<<<<<<+>>>>>>>>>>]
>] End loop
*><>, 41 bytes
Uses the -i flag to initialize the stack with our input value.
l1["dlroWolleH" v
or1-:?!;rl2(?!u20.O>
Explanation
l Push the length of the stack onto the stack
1[ Pop that length value into a new stack
"dlrowolleh" Push "HelloWorld" reversed onto the stack
v Change IP Direction downward
> Change IP direction rightward
o Pop a value off the stack, print it as a char
r Reverse the stack, putting the length value on the top of the stack
1-: Subtract one from that value
?!; If that value is 0, halt execution
r Reverse the stack
l Check the length of the stack
2( Is it less than two (Do we have more to print, but have run out of our HelloWorld string)
?!u If NOT, ignore instructions until the next O
20. If so, jump to [0,2] in the code box, just before pushing HelloWorld onto the stack
O Else, continue onto the >
J, 15 bytes
'HelloWorld'$~#
Very straightforward.
Explanation
'HelloWorld'$~#
$~ reshape
'HelloWorld' this string
# by the length of the input
Alice, 54 bytes
/ H l o o l " \w>?hn$vihn$@?]oK
" e l W r d ! ^(H' <
Flattened
/"HelloWorld"!\w>?hn$vihn$@?]oK
^(H' <
/"HelloWorld"!\ Pushes the hello world string on the tape
w ihn$@ K While where are characters to read on the input
>?hn$v If the tape is outside of "HelloWorld"
^(H' < Rewind the tape
?]o Print one character from the tape and move to the next one
R (function), 41 bytes
`substr<-`(a,1,90,strrep("HelloWorld",9))
I assume this can be improved...
This takes advantage of a feature of substr() I learned when I was today years old: substr() has a replacement function, and if the string replacing the substring is longer than the substring, it is cut off at the appropriate place, which works perfectly for this challenge. We can replace the entire input string a with a string of concatenated "HelloWorld"s with the last one truncated. This will not work for any string longer than 90 characters but no test cases in the input are that long. To make it work for longer strings, you can replace both of the 90 and 9 with nchar(a).
simply, 111 106 bytes
This is (yet another) language I'm just working on, for fun.
It is a very verbose language, and still in progress, which is why the algorithm is ... less conventional and very convoluted...
def&f($v){$C=&str_chunk("HelloWorld"&len($v));send$C[0];}echo&join(&array_map(&str_chunk($argv[0]10)&f)'')
Due to oversights in the parser, the values don't have to have to be separated by commas.
Ungolfed:
Create a function called &handle_chunk with arguments ($value).
Begin
Assign $len the value of executing the function &len with argument $value.
Set the variable $chunks with the value of calling the function &str_chunk with the arguments "HelloWorld", $len.
Return the value $chunks[0].
End.
Display the result of calling &join(
Call the function &array_map with the arguments (
Run &str_chunk($argv[0], 10),
&handle_chunk
),
""
).
Should be self-explanatory.
How to run:
Download the repository and open índex.html.
Unintended method:
This is simply a re-implementation of m90's answer:
%c="";def&f($s)call%c->padEnd(&len($s)"HelloWorld");
Works the same way as the intended way.
Rust (full program), 145 bytes
The full program rule doubles the length.
fn main(){for l in std::io::stdin().lines(){print!("{}",(0..).zip(l.unwrap().chars()).map(|i|b"HelloWorld"[i.0%10]as char).collect::<String>())}}
Rust (function), 85 bytes
|l:&str|(0..).zip(l.chars()).map(|i|b"HelloWorld"[i.0%10]as char).collect::<String>()
PowerShell Core, 35 bytes
% L*h|%{'HelloWorld'*$_|% S*g 0,$_}
Windows PowerShell, 38 bytes
% L*h|%{'HelloWorld'*$_|% S*g -a 0,$_}
Same as above, but PS 5.1 requires actually naming the parameter "-ArgumentList" (shortened to "-a") for the Substring() method call.
Input comes from the pipeline.
Nothing fancy; this is basically
ForEach-Object {$l = $_.Length; ('HelloWorld' * $l).Substring(0, $l)}
The expensive method calls can be golfed by using the cmdlet ForEach-Object (that is, its alias "%"), and its possibility to call a method of the input object by name, accepting wildcards.
% L*h|%{'HelloWorld'*$_|% S*g 0,$_}
% L*h # "ForEach-Object -MemberName Length": invoke the method "Length" for the string passed in the pipeline
| # Pipe the length of the input string to the next cmdlet
%{ # "ForEach-Object -ScriptBlock {"
'HelloWorld'*$_ # repeat the string 'HelloWorld' <Length> times
| # and pipe the 'HelloWorldHelloWorld...' to the next cmdlet
% S*g 0,$_ # "ForEach-Object -MemberName Substring -ArgumentList 0, <Length>": invoke the method "Substring" for the string passed in the pipeline, get <Length> chars starting at 0
} # }: end of the scriptblock; Output is implicit
vim, 46 bytes
$mma<C-R>=col('$')
aHelloWorld<C-V><ESC><ESC>`mlDo<ESC>@"khjllDkdd
Annotated
$mm # Go to the end of input and mark our position
a # Append...
<C-R>=col('$') # The column offset/line length
aHelloWorld<C-V><ESC> # This exact string
<ESC> # ...which yields a command that prints "HelloWorld"
# once per char in the original input. (All that matters
# is that this string is at least as long as the output
# needs to be.)
`mlD # Delete the string we just appended, copying into register "
o<ESC>@" # Run the command, putting a bunch of "HelloWorld"s on next line
khjllD # Make the new line the same length as the input
kdd # delete the input
<C-R> is 0x12, <ESC> is 0x1b, <C-V> is 0x16.
Excel, 38 bytes
=LEFT(REPT("HelloWorld",3276),LEN(A1))
Input is in the cell A1. Output is wherever the formula is.
Repeats the string as many times as allowed based on the limitations of inputs to LEFT() and the truncates all but the left-most characters based on the length of the input.
05AB1E, 9 bytes
”Ÿ™‚ï”áI∍
Input as a list of characters.
Try it online or verify all test cases.
Explanation:
”Ÿ™‚ï” # Push dictionary string "Hello World"
á # Only keep letters to remove the space: "HelloWorld"
I # Push the input-list
∍ # Shorten/extend the "HelloWorld" string to its length
# (after which the result is output implicitly)
See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ”Ÿ™‚ï” is "Hello World".
Vyxal s, 5 bytes
ẏkhȧİ
Can't believe I had to find a new 5 byter because someone got my answer by 2 bytes shorter :p.
Explained
ẏkhȧİ
ẏ # The range [0, len(input)]
khȧ # The string "HelloWorld"
İ # The range indexed into the characters of the string.
Vyxal sr, 5 bytes
khȧf•
More flags and more ways that I won't be outgolfed again. Takes input as a list of characters
Explained
khȧf•
khȧf # The string "HelloWorld" as a list of chars
• # Molded to the shape of the input
Perl 5 + -pl, 23 bytes
Inspiration taken from @Neil's Retina answer. 3 bytes saved thanks to @Sisyphus!
$_&=HelloWorld x y//./c
Explanation
Sets $_ (which will be implicitly output via -p) to the result of stringwise ANDing a string of HelloWorlds repeated once for the count of each char in the input (implicitly stored in $_ via the implicit -n from -p) when tr///ansliterated (y///) from any char to \xFFs. This operation results in a string the length of the original input with the content HelloWorld truncated accordingly.
Kustom, 39 bytes
Basically just this Javascript answer.
The extra byte is for the global variable name.
$tc(rpad,"",tc(len,gv(i)),HelloWorld)$
BQN, 15 bytes
"HelloWorld"⥊˜≢
"HelloWorld"⥊˜≢
≢ # get the shape (length) of the input
⥊˜ # and use this to reshape
"HelloWorld" # the string "HelloWorld"
# (recycling elements if required)
Jelly, 8 bytes
“ ⁷ỴNt»ṁ
A monadic Link that accepts a list of characters and yields a list of characters.
How?
Pretty simple...
“ ⁷ỴNt»ṁ - Link: list of characters, S
“ ⁷ỴNt» - dictionary lookup -> "HelloWorld"
ṁ - mould like S
lin, 25 bytes
"HelloWorld"`cyc.~ len `t
Try it here! Returns an iterator.
For testing purposes:
"how are you" ; `_` outln
"HelloWorld"`cyc.~ len `t
Explanation
Cycle and take (input length) items.
Haskell, 30 bytes
map fst.zip(cycle"HelloWorld")
A cute way to truncate one string to the length of another is to zip them together, which truncates the longer string, then extract the desired string with map fst.
Longer alternatives:
fst.unzip.zip(cycle"HelloWorld")
zipWith const$cycle"HelloWorld"
Retina, 27 bytes
T`p`~
Y`~`\He\l\l\oW\or\l\d
Try it online! Explanation:
T`p`~
Translate all the characters to ~s.
Y`~`\He\l\l\oW\or\l\d
Cyclically translate all the ~s to the characters HelloWorld. Note that unfortunately most of them have special meanings to translate so that they have to be quoted.
Charcoal, 13 bytes
…HelloWorldLS
Try it online! Link is to verbose version of code. Explanation:
HelloWorld Literal string `HelloWorld`
… Reshaped to length
L Length of
S Input string
