0
\$\begingroup\$

A boring version of yourself

Have you ever dreamed of a boring version of you which types the text you just typed ?

No ? Because that's exactly what I'm challenging you to do !

The program needs to check how many time it took for the user to input a text at program launch and then retype the text again using the same period of time (approximatively).

Here's my Python3 implementation with additional information :

import time

start = time.time()
userInput = input("Cool human input :")
endHuman = time.time() - start
duration =  endHuman / len(userInput)
start = time.time()
print("Boring robot input : ", end="")
for i in userInput:
  print(i, end="")
  time.sleep(duration)
end = time.time() - start
print()
print(endHuman, "vs", end)

This is a code-challenge so be creative !

Here are the rules :

  • User must input the initial text, no program args
  • Text input length is > 0 (No need to check)
  • The sleep duration between each letter is not imposed, it can be (timeTookByUser / numberOfLetters) like in my implementation, it can be random (as long as the total time is approximatively equal), it can sleep for the total time at first and then print all (but it's not fun).
  • The "robot timer" must stop when the last letter is typed by the robot, you can't print everything and then sleep and end the program.
  • As long as the robot prints the text passed in input, you can print other stuff (additional informations etc..)
  • You don't have to use the console, you can input the text using a graphical text input and render it letter by letter using DELs but you will have to specify it in your answer
  • Be creative !
\$\endgroup\$
  • 4
    \$\begingroup\$ What is the winning criterion? \$\endgroup\$ – Luke Jan 26 '17 at 16:47
  • 3
    \$\begingroup\$ Should the robot reproduce the use of backspace, cursor moves, text overwriting, etc.? \$\endgroup\$ – Arnauld Jan 26 '17 at 16:52
  • \$\begingroup\$ @Luke Winner is the most creative solution I guess ? \$\endgroup\$ – Sygmei Jan 26 '17 at 16:54
  • \$\begingroup\$ @Arnauld Nope, it does not have to. But that would be a nice solution ! \$\endgroup\$ – Sygmei Jan 26 '17 at 16:54
  • \$\begingroup\$ All challenges on PPCG must have an objective winning criterion, such as shortest code or fastest to run. I'd suggest shortest code (that is, code-golf) for this particular challenge. \$\endgroup\$ – ETHproductions Jan 26 '17 at 16:55
6
\$\begingroup\$

Bash + linux utilities, 37

This will measure the time taken to enter each character (including backspaces) and play back verbatim. Use ^C or ^D to end user input.

script -qta -csed\ d
scriptreplay -ta

Creates a temporary files typescript and a in the current directory.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ I'll try that when I'll be on Linux :) \$\endgroup\$ – Sygmei Jan 26 '17 at 17:20
  • \$\begingroup\$ Wow ! Neat one :) Nice use of Linux utilities \$\endgroup\$ – Sygmei Jan 26 '17 at 18:46
  • \$\begingroup\$ You can actually get bash for windows if you like what you see. That is what Git for Windows uses. \$\endgroup\$ – nurchi Jan 26 '17 at 20:18
  • \$\begingroup\$ That's cheating BTW, script and scriptreplay are not a bash utility or of any other shell I know. They are binaries. If this is considered a legitimate answer then I can put these two commands inside an executable called a and give ./a as an answer ;-D \$\endgroup\$ – saga Jan 28 '17 at 15:17
  • \$\begingroup\$ @Saga. The point is the language here is "Bash + linux utilities" and not "Pure Bash" (in which case the answer would only contain bash builtins). On my vanilla Ubuntu machine, this includes old favourites such sed and script. From the point of view of PPCG, these utilities effectively form a "standard library" to bash. That they are implemented as binaries is an irrelevant implementation detail. Look around - you'll see this seems to be well accepted by the PPCG community. \$\endgroup\$ – Digital Trauma Jan 28 '17 at 17:28
3
\$\begingroup\$

MATLAB / Octave, 38 bytes

tic;x=input('','s');pause(toc);disp(x)

Starts a timer (tic) and prompts the user for input. Then the program pauses for however long it took for the user to input the text (toc) and prints out the input text.

\$\endgroup\$
  • 4
    \$\begingroup\$ Commands named tic and toc? That's genius :-) \$\endgroup\$ – ETHproductions Jan 26 '17 at 17:03
2
\$\begingroup\$

MATL, 7 5 bytes

2 bytes saved thanks to @Luis

jZ`Y.

This solution will determine how long the user takes to enter the input and then wait that same amount before printing the user's input back to them all at once.

Unfortunately doesn't work online since the online interpreters don't support interactive input.

enter image description here

Explanation

        % Implicitly start the timer
j       % Grab user input as a string (will prompt the user)
Z`      % Stop the timer and return the elapsed time in seconds
Y.      % Pause for this many seconds
        % Implicitly display the user-input string
\$\endgroup\$
  • 2
    \$\begingroup\$ GIF in the post always makes it better ! \$\endgroup\$ – Sygmei Jan 26 '17 at 17:19
0
\$\begingroup\$

Python 3.5, 61 bytes

from time import*
s,i=time(),input()
sleep(time()-s)
print(i)
\$\endgroup\$

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