Introduction

hackertyper.net is a website that simulates "hacking" (as the media portrays it) by outputting complicated code from the crypto section of the Linux kernel onto the screen as you type at a rate of 3 characters per one inputted.

Challenge

Your program/function should either accept a file as a command-line argument, have the file path hard-coded, or accept the text [that would be in the file] as a command-line or function argument, and mimic hackertyper.net by outputting 3 characters onto the screen (STDOUT or equivalent) from the file for each one received through STDIN or equivalent.

Once EOF is reached, the program should start outputting characters from the beginning of the file again (wrap).

Specs

For the purposes of simplicity, you can assume that STDIN has already been set to no buffer and no echo mode, that is not waiting until the user presses enter before passing input to your program and not displaying the characters you type.

The file can contain newlines, while the input will not contain newlines.

For a small example written in C (not golfed) that demonstrates how this works, see this.

Green text and a black background are not required.

Example input and output

The file:

#include <stdio.h>
int main() { }



Input:

hello world


Output:

#include <stdio.h>
int main() { }


The file:

hello


Input:

hello world


Output:

hellohellohellohellohellohellohel

• 1. Are functions allowed (that take two strings as an argument and return another string)? 2. Your spec says to output three characters for every input, but the examples only output one for every input.
– Doorknob
Apr 30 '16 at 2:20
• @Doorknob 1. Yes, and 2. That was a mistake, fixed. Apr 30 '16 at 2:23
• Do we have to take the file information in as a file, or can we also receive that information through a function argument or equivalent? If we have to, what will the name of that file be? Will it be in a specific directory away from our script(s), or in the same one as our script(s)? Apr 30 '16 at 2:42
• Related. Apr 30 '16 at 8:54
• Bonuses be bad. And plus very few people will get the penalty, and calling it a "bonus" is confusing. Apr 30 '16 at 18:15

Jelly, 4 bytes

ẋ3ṁ@


Try it online!

How it works

ẋ3ṁ@    Main link. Arguments: s (input string), t (file string)

ẋ3      Repeat s three times.
ṁ@    Mold; reshape t like the previous result.
This repeats the elements of t over and over until the length matches that
of s repeated thrice.

• I've always wondered what "mold" means... Apr 30 '16 at 4:15
• @KennyLau I think it means it's time to throw out the bread. Apr 30 '16 at 6:44

J, 7 bytes

$~(3*#)  Takes two arguments, the text to be repeated and the user's input text. Usage The input text is formatted where , means to join and LF is the newline character.  f =:$~(3*#)
('#include <stdio.h>', LF, 'int main() { }') f 'hello world'
#include <stdio.h>
int main() { }
'hello' f 'hello world'
hellohellohellohellohellohellohel


Try it online. (tryj.tk)

Jelly, 9 bytes

⁴L×3
ẋ¢ḣ¢


Try it online!

⁴L×3     Define nilad as ¢:

L       length of
⁴        second argument
×3     tripled

ẋ¢ḣ¢     Main chain:

the first argument (implicit)
ẋ        repeated
¢       ¢ many times
ḣ¢     then get the first ¢ characters of it.

• I guess you're a bit "jelly" of Dennis' answer? Apr 30 '16 at 17:26
• Jelly is evil.. Apr 30 '16 at 18:54

Pyth, 10 bytes

s@Ljb.z*3l


Try it online!

JavaScript (ES6), 40 bytes

(s,t)=>s.repeat(l=t.length*3).slice(0,l)


Where s is the data string and t is the user string. Assumes s is nonempty and repeats it l times to ensure that its length is at least l so that it can return the first l characters, where l is three times the length of t.

First argument is what's "typed", the second the source to display

(.cycle).take.(3*).length


Or non-pointfree, for (possibly) better readability:

h a=take(3*length a).cycle

• What's cycle? Apr 30 '16 at 16:28
• @CatsAreFluffy cycle takes a list and repeats it infinitely. Eg cycle "hi" == "hihihihi.. Apr 30 '16 at 16:31
• Have you considered $? Apr 30 '16 at 16:36 • @CatsAreFluffy I'm not sure where I'd use it, what were you thinking? Apr 30 '16 at 18:53 Python 3.5, 7765 63 bytes: lambda g,f:''.join((g*len(f))[i:i+3]for i in range(0,len(f)*3,3))  Simple enough. An anonymous function which takes in two arguments, the first one being the "file" (g), and the second being the characters typed in by the user (f). Then this creates a generator containing every three characters in g, which are found by indexing for every i and then i+3 characters in g, where i is in the range of 0=>(length of f)*3. Finally, it returns each object in the generator joined into one big string. You call this function by assigning a variable to it, and then calling the variable wrapped inside a print() expression. So if the function's name was q, it would be executed like print(q(<byte array here>)). Try it online! (repl.it) 05AB1E, 7 bytes Code: 3×g©×®£  Explanation: 3× # Multiply the input string three times. g # Take the length. © # Copy that to the register. × # Multiply by the second input. ® # Retrieve the length from the register. £ # Only keep [0:length * 3] from the new string.  Jolf, 10 bytes ]*iγl*I30γ  Try it here! Explanation ]*iγl*I30γ *i repeat string 1 l*I3 the length of the other string * 3 γ γ = (^) ] 0γ (^).slice(0, γ)  Ruby, 39 bytes In Ruby, $< reads from the supplied file in the command line arguments instead of $stdin if one is given. (If you forget to supply a file, you get a blank output because it reads everything out of $stdin in $<.read and thus STDIN.read.size will be 0.) $><<(\$<.read*s=3*STDIN.read.size)[0,s]