-2
\$\begingroup\$

Create a program that calculates my reading speed!

The challenge

Write a program which takes some text as input and waits for a start signal from the user to display the input. When to user gives a second end signal, the program should output the reading speed of the user, which is defined as the number of words in the input divided by the time between both signals in minutes.

The word count of the input text is determined by splitting the text at white space.

Input

  • A block of text via any standard input means.
  • A start and end signal by the user, either a click or pressing a certain key of your choice.

Output

  • The block of input text.
  • The reading speed of the user as defined above.

Rules

  • The start and end signal may not be running and ending the program.
  • The text may wrap or the user may scroll.
  • The reading speed value may be returned in any of the standard methods in the meta post found here, though the text must be displayed beforehand to the user, e.g. by printing to stdout.
  • This is , so the shortest code in bytes wins.
\$\endgroup\$
  • \$\begingroup\$ the time in minutes my guess is that most people can read this in less than a minute, so maybe seconds would work the best. \$\endgroup\$ – zeppelin Mar 10 '17 at 16:51
  • \$\begingroup\$ @zeppelin yeah but then the point of Words per minute is ruined \$\endgroup\$ – Christopher Mar 10 '17 at 16:51
  • \$\begingroup\$ It would change the calculate to words per second \$\endgroup\$ – Christopher Mar 10 '17 at 16:52
  • 9
    \$\begingroup\$ All of these comments and questions are why we strongly encourage people to use the Sandbox. \$\endgroup\$ – AdmBorkBork Mar 10 '17 at 16:56
  • \$\begingroup\$ @AdmBorkBork I normally do but I thought that for once I could not Sandbox something for a simple challange \$\endgroup\$ – Christopher Mar 10 '17 at 16:59
5
\$\begingroup\$

MATL, 24 bytes

O$Y.Y`OYDtDYbn60*O$Y.Z`/

Explanation

O$Y.    % Wait for the user's keypress
Y`      % Start the timer
        % Implicitly grab the input
OYD     % Converts control characters and creates a string
tD      % Duplicate the string and display
Ybn     % Split the string into words and count them
60*     % Multiply by 60 to convert words per second to words per minute
O$Y.    % Wait for user to press a key
Z`      % Get the elapsed time in seconds
/       % Divide the number of words (times 60) by the time in seconds
        % Implicitly display the result
\$\endgroup\$
4
\$\begingroup\$

Octave, 59 bytes

pause;tic;disp(x=input(''));pause;numel(strsplit(x))*60/toc

Explanation

pause               % Wait for a user's keypress
tic                 % Start the timer
disp(..)            % Display paragraph
pause;              % Wait for user's keypress
numel(strsplit(x))  % Determine number of words
*60                 % Multiply by 60 to convertwords per second to words per minute 
/toc                % Divide by the total time that it took (in seconds)
\$\endgroup\$
2
\$\begingroup\$

Processing Js 77 bytes

var i="",b=second();println(i);i.split(" ");keyTyped=function(){println(i.length/(second()-b));};

Try it out

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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