text:
Find the smallest file
Goal:
Create a program to find the smallest file in the current folder.

File size may be measured in bytes or characters.

If multiple files have the same size, you can either choose one or display all of them.

You can assume there will be at least one file in the folder, and no files will have a size of 0.

Assume that all files in the folder can be loaded by the language you're using.

Assume that there are no folders in the current directory.

Input:
The program should not take any input from the user, unless:

If your language doesn't have a "current folder", it may ask the user for a folder name/path.
If your language cannot directly access files on your computer, it may allow the user to upload files. (JavaScript, for example)

Output:
The name of the smallest file should be displayed.

Leading/trailing symbols are allowed, as long as it's clear which file has been chosen.
(Printing a list of all the files is against the rules).

Notes:

Standard Loopholes are not allowed.
You cannot modify/create/delete files in the folder to change the result.
This is code-golf; shortest answer (in bytes) wins.

Can we assume files can have a size of 0?

Also, what does "assume that all files in the folder can be accessed" mean? does that mean hidden files don't need to be shown?

What if there are multiple files of the same size? does any work?

Can we assume files can have a size of 0?: sure
"assume that all files in the folder can be accessed": If your language is only able to access, for example, .png files (for some reason), you can still post an answer.
What if there are multiple files of the same size?: You can display one or all of them.

So if your language can only support it, not if it just takes more bytes?

Can I assume there are no folders on the current folder? It makes all the difference if you have a language function that returns both files and folders instead of only files!

Whenever possible you should avoid making edits that invalidate existing answers. Also, I don't know what work if there are other folders means. Should it simply not break or should it search recursively for the smallest file?

The only other choice was to leave an ambiguity in the question.

Not necessarily. You may assume that there are no directories inside the current directory is unambiguous and doesn't invalidate any answers.

Now that I think about it, that would be closer to the original intent of the challenge.

You never answered my question about more bytes vs actually impossible. For example, bash's ls can access hidden files, but it takes the -a flag. Are we required to use that? You say "If your language is only able to access .png", but that's a bit unclear.

(sorry I haven't replied sooner, my internet connection was down for a few days) The problem I have with allowing you to skip hidden files is that it seems to open a lot of loopholes. Allowing you to skip files that are "slightly harder to access" would mean people could do something like only checking the first 9 files because it saves a few bytes.

Vim 12 bytes
!!ls -Sa
Gd{

Try it online!
Explanation:
!! is the filter command. It pipes the contents of the current line to an arbitrary system command, and sends the output back into the buffer. It's useful for using external tools for things that bash is better at than vim, for example !!rev to reverse the current line, or !Gxxd to hexdump the buffer. In our case, the buffer is empty so it's equivalent to :r!ls, which just feeds the output of the command into the current line.
Now the cursor is on line 1, and we want to delete every line but the last one. The naïve approach is
G       " Go to the last line
 k      " Go up one line
  d     " Delete:
   gg   "   Everything up to the first line

But we can do better. Like I explained in this tip, the { can usually (but not always) be equivalent to gg. Here, it's even better. Because the motion is character-based, not line-based like gg is, we don't have to go up a line first, leaving us with
Gd{

Bash + coreutils, 13 bytes
ls -Sar|sed q

Explanation:
ls -Sar|sed q
ls            # list files
   -S         # sorted, biggest first
     a        # show hidden files
      r       # reversed (smallest first)
       |sed q # q is quit at first line that matches given regex,
              # given regex is empty so guaranteed match.

Posted this as my own answer, but I think it's too similar to yours. ls -1Sa|tail -1 is 3 bytes shorter and has cleaner output.

I don't think you need the '-1', pipe automatically puts one file per line.

@EasterlyIrk I think GB is right.  if ls detects output is to the terminal it will format the output into multiple columns.  But if output is a pipe it will just do 1 per line.  Compare ls vs ls|cat

Two bytes shorter: ls -Sar|sed q

@DigitalTrauma ah, true. and thanks!

Doesn't this fall into the "using other programs" loophole?

@MichealJohnson which one? That's not a loophole... It's perfectly allowed to import modules in a submission, and coreutils is basically a module for bash that doesn't need to be imported

PowerShell, 30 24 21 bytes
(ls|sort le*)[0].Name

Try it online!
ls is an alias for Get-ChildItem. That's piped to sort-object with the length attribute, so the files are sorted by size. We index into that with the (...)[0] to get the first (i.e., smallest), and then take the .Name thereof. Output via implicit Write-Output happens at program completion.
Saved 6 bytes since we're guaranteed that only files exist in the directory. Saved an additional 3 thanks to ConnorLSW.

Can you not get rid of the -file since only files are in the current directory?

@Mutantoe Yes -- that was edited into the challenge after I posted this answer. Thanks!

you can use sort le* to shave some bytes since powershell will accept it.

@ConnorLSW Yes, of course. Thanks!

Python 2 3, 94 76 74 54 bytes
-18 bytes thanks to @orlp
-2 bytes thanks to @Jonathan Allan
-20 bytes thanks to a change in challenge specs
from os import*
print(min(listdir(),key=path.getsize))

print min(filter(path.isfile,listdir(".")),key=path.getsize) is cleaner and substantially shorter.

Save two bytes moving to Python 3 since "." is the default. print(min(filter(path.isfile,listdir()),key=path.getsize))

Also I count 76 not 77.

@JonathanAllan I measured the byte count count with wc which gave me 1 byte more

The extraneous byte would be due to a trailing newline, which is not required for Python. Additionally, since the challenge was updated to state that there are no subdirectories present, the whole filter bit is unnecesary. This also doesn't work in Python 3, since print is a function. The following would work, and be substantially shorter: print(min(listdir(),key=path.getsize))

Ruby, 61 40 38 37 bytes
Thanks G B and Value Ink
p Dir[?*,".*"].min_by{|x|File.size x}

You can use ?. instead of Dir.pwd, and min_by{} to get the smallest file. Dir.foreach(?.).min_by{|x|File.size x} gets the same result in 38 bytes.

@GB Thanks!

It's a shame that "all" files the language can access must be looked at, because Dir[?*] is much shorter but doesn't include hidden Unix files like .bash_profile...

Maybe Dir[?,".?"] could work. I haven't tried. And it's shorter.

@GB It'd actually be Dir[?*,".*"]. Glob string .?* won't match file .a if it exists.

Java 7, 149 142 bytes
String f(){String n="";long s=-1>>>1,p;for(java.io.File f:new java.io.File(".").listFiles())if((p=f.length())<s){n=f.getName();s=p;}return n;}

Try it online!
-7 bytes thanks to CAD97

I think you want File::length not File::getTotalSpace

Untested Java 8: ()->java.utils.stream(new java.io.File(".").listFiles()).max((a,b)->a.length()-b.length).get().getName() for 104 bytes

@CAD97 You're right! What was I thinking...

Mathematica, 35 bytes
FileNames[]~MinimalBy~FileByteCount

FileNames[] produces a list of names of all the files (and directories) in the current directory; ~MinimalBy~FileByteCount selects the name of the file whose byte count is smallest. FileByteCount throws a bunch of errors when it's applied to directories, but the errors don't derail the program.

SH (Linux/Unix) 15 14 13 14 bytes
ls -aS|tail -1

-S sorts by size (descending),
-rreverses and tail -1 outputs the last file in the list.
@ Dennis Thanks for saving 1 byte
@Dani_l Thanks for saving 1 byte.

That finds the largest file, no?

Nevermind, I'm tired. You could use tail though instead of reversing, and -1 is a shorthand for -n1.

@Dennis Updated

@EasterlyIrk Now it should :)

@AbelTom cool, thanks for fixing.

What's specific to BASH in your solution?

@yeti I'm not sure I understand exactly what you mean. The solution would also work on UNIX shell ( /bin/sh ), /bin/bash is the program that use on my machine.

@AbelTom — BASH has more features than SH, so if you do not use them, label your solution with SH... that was the direction I wanted to point at...

@yeti Updated Sir.

Scala, 52 bytes
Old version, 79 bytes
new java.io.File(".").listFiles.map(a=>a.getName->a.length)sortBy(_._2)apply(0)

Adjusted according to jaxad0127's advice.  It is only 52 bytes now.
new java.io.File(".").listFiles.sortBy(_.length)head

Using head instead of apply(0) is shorter. Also, the toString method of File is fine, no need to call get name.

MATLAB / Octave, 52 48 bytes
d=dir;[~,n]=min([d.bytes]./~[d.isdir]);d(n).name

Explanation
This gets a directory listing of all files and folders in the current directory using dir. The output of dir is a struct containing the filename, whether it's a directory or not, the size (in bytes), etc.
We can then take an array of the sizes of each in bytes [d.bytes] and perform element-wise division with a boolean indicating whether it's a directory or not ~[d.isdir] which will yield Inf where it's a directory (division by zero) and the size in bytes otherwise (division by 1).
We find the index of the minimum of this array using the second output of min and use that to index into the initial struct and display the name with d(n).name

You should add disp(...) around the output to properly print it. Otherwise if for example there was a file called ans that is not the smallest in the folder the output wouldn't be clear as to which file is the smallest to anyone unfamiliar with MATLAB.

@TomCarpenter Hmmm I interpreted "Leading/trailing symbols are allowed, as long as it's clear which file has been chosen" to mean that the ans =  is ok

I've just realised MATLAB adds the implicit . (current folder) and .. (folder above), so cant remove the directory check it seems. Sorry about that.

Batch, 43 39 35 bytes
@dir/b/os|(set/pf=&call echo %%f%%)

Output includes a leading space for some reason, but fortunately that's allowed. Edit: Now assuming there are no directories to save 4 bytes.

Oh, using /p like that, dang clever!

@AdmBorkBork Ah, I hadn't noticed that was allowed, thanks!

You're guaranteed that no sub-directories exist (the challenge was updated) so you can eliminate the /a-d.

J, 21 20 bytes
>{.,(/:2&{"1)1!:0'*'

Saved a byte thanks to @Conor.
Explanation
>{.,(/:2&{"1)1!:0'*'
                 '*' Glob all files in current directory
             1!:0    Table of file metadata in that directory
       2&{"1         Get the file size of each
     /:              Sort the files by that
   ,                 Flatten
 {.                  Get the first value
>                    Unbox

Perl 6,  33 32 31  16 bytes
'.'.IO.dir.grep(*.f).min(*.s).put

Try it
put '.'.IO.dir.min:{try .s//Inf}

Try it
put $*CWD.dir.min:{try .s//Inf}

Try it
put dir.min: *.s

Try it
Expanded:
put        # print with trailing newline
dir        # the list of files in the current directory
.min:      # find the minimum by
  *.s      # calling the `s` method (size) in a Whatever lambda

The function form of dir defaults to $*CWD, and the task description says you can assume there won't be any folders, so I think you can shorten that to dir.min(*.s).put.

When I wrote this, it said the program must ignore folders.

BATCH File, 77 72 63 60 bytes
@FOR /F tokens^=* %%G IN ('dir/o-s/b')DO @SET[=%%G
@ECHO %[%

There's no direct equivalent of head or tail in BATCH, at least to my knowledge, so here's a kludgy work-around. (with much assistance from @Neil - thanks!)
The dir command, with /o-s to sort in descending file size, and /b to output only the file names. We loop through those with FOR /F, setting the variable [ to the file name each time. Finally, we output just the last one with ECHO %[%.
Saved 9 more bytes thanks to Neil and thanks to guarantees that no directories are present.
Saved 3 bytes thanks to HackingAddict1337.

Your FOR variable needs two %s to work in a script. Otherwise, a few golfing tricks: 1. Don't use @ECHO OFF on short scripts, add a @ to each line and after DO. 2. Delete the space before DO. 3. The spaces and :s aren't needed in the dir command.

@Neil Ack, thanks. Sorry, pretty rusty since I've been doing PowerShell... Thanks!

tokens^=* instead of "tokens=*" using [ as the variable name will save you one byte, because set[=%%G is enough. the space in front of do is optional...

PHP, 84 62 bytes
$t=array_map(filesize,$g=glob('*'));asort($t);echo$g[key($t)];

Since the question was updated with the assumption that there will be no folders in the current directory, I was able to remove the file check stuff and golf this down.

Here is my old answer:
$t=array_map(filesize,$g=array_filter(glob('*'),is_file));asort($t);echo$g[key($t)];

This is the best I could do. Maybe there is a better way I'm missing.
$t=array_map(              # visit each array element and...
    filesize,              # map each filename to its filesize...
    $g=array_filter(       # using an array of...
        glob('*'),         # all files and directories...
        is_file            # filtered by files...
    )                      #
);                         #
asort($t);                 # sort the array of filesizes, then...
echo$g[key($t)];           # print element from the array of files using the first key of the sorted array as an index

R, 36 bytes
x=file.info(y<-dir())$s;y[x==min(x)]

Explained
file.info() returns a data.frame of "file information" when given a character or character vector of file/folder names which when used on the list of files/folders in the current directory (dir()), looks something like:
                                                               size isdir mode               mtime               ctime               atime exe
Polyspace_Workspace                                               0  TRUE  777 2014-11-28 17:29:25 2014-11-28 17:29:25 2014-11-28 17:29:25  no
Python Scripts                                                    0  TRUE  777 2016-03-21 23:59:41 2016-03-21 23:59:41 2016-03-21 23:59:41  no
R                                                                 0  TRUE  777 2015-12-23 20:11:02 2015-12-23 20:11:02 2015-12-23 20:11:02  no
Rockstar Games                                                    0  TRUE  777 2015-04-14 12:23:05 2015-04-14 12:23:03 2015-04-14 12:23:05  no
TrackmaniaTurbo                                                   0  TRUE  777 2016-03-24 17:15:05 2016-03-24 13:13:48 2016-03-24 17:15:05  no
ts3_clientui-win64-1394624943-2014-06-11 03_18_47.004772.dmp 314197 FALSE  666 2014-06-11 02:18:47 2014-06-11 02:18:47 2014-06-11 02:18:47  no

Subsequently we just have the find the name of the file for which the size column (abbreviated using $s) is the smallest. Consequently, if there are more than one file with the smallest size, all will be returned.
Bonus: if we also wanted to disregard folders in the current directory we could simply search for size when isdir == FALSE: x=file.info(y<-dir());y[x$s==min(x$s[!x$i])] which turns out to be 44 bytes.

Bit late, but file.size is shorter because you don't have to do $s afterwards.

SmileBASIC, 110 bytes
DIM F$[0]FILES"TXT:",F$FOR I=0TO LEN(F$)-1F$[I][0]="TXT:
S=LEN(LOAD(F$[I],0))IF!Z||S<Z THEN Z=S:B=I
NEXT?F$[B]

Only looks at TXT: files, since DAT: files cannot be loaded unless you already know their size, making it impossible to load a random one.

How do you load a DAT:  file? Could you brute-force every name/file size in the folder?

Trying to load a 3-dimensional DAT: file into a 2-dimensional array (for example) will cause an error, so you can't brute force it. You just have to know the number of dimensions beforehand, which you normally would.

Could you load a 2-d DAT:  file into a 3-d array? Then you could create a maximum size array. And you can't catch errors in any way?

Nope, that will cause a Type mismatch error. And there's no way to catch errors either.

Tcl, 88 bytes
set s Inf
lmap f [glob -ty f *] {if [set m [file si $f]]<$s {set n $f
set s $m}}
puts $n

Try it online!

Node.js (using walk), 114 bytes
Ignore newline:
require('walk').walk(__dirname).on('file',(r,s,n)=>
(m=s.size>m.size?m:s,n()),m=0).on('end',_=>console.log(m.name))

This invokes a walker that traverses through the current directory (__dirname) and for each file calls a function with its stat s and a function next n() that must be invoked to continue the traversal. Then at the end, it prints a filename with the minimum size in bytes found. s.size>m.size returns false when m.size is undefined, so after the first callback, m is equal to the first file found, and continues from there normally.

C#, 277 bytes
Not the shortest, but what would you expect from C#?
Golfed
using System.Linq;using static System.IO.Directory;class P{static void Main(){var x=GetFiles(GetCurrentDirectory());var d=new long[]{}.ToList();foreach(var s in x){var b=new System.IO.FileInfo(s).Length;if(!d.Contains(b))d.Add(b);}System.Console.Write(x[d.IndexOf(d.Min())]);}}

Ungolfed
//Linq using for List.Min()
using System.Linq;
//Static using to save bytes on GetCurrentDirectory() and GetFiles()
using static System.IO.Directory;

class P
{
    static void Main()
    {
        //String array containing file paths
        var x = GetFiles(GetCurrentDirectory());
        //Creating a Long array and converting it to a list, less bytes than "new System.Collections.Generic.List<long>()"
        var d = new long[] { }.ToList();
        foreach (var s in x) //Loop through all file paths
        {
            //Getting file size in bytes
            var b = new System.IO.FileInfo(s).Length;
            if (!d.Contains(b))
                //If there isn't already a file with this size in our List, add the file path to list
                d.Add(b);

        }
        //Get index of the smallest Long in our List, which is also the index of the file path to the smallest file, then write that path
        System.Console.Write(x[d.IndexOf(d.Min())]);
    }
}

Groovy, 49 bytes
m={f->f.listFiles().sort{it.length()}[0].getName()}

Try it online!
Closure, usage: m(new File("location"))

Röda, 32 31 bytes
{ls""|sort key=fileLength|pull}

It's an anonymous function that sorts the files in the current directory by file length and selects then the first file with pull.
Use it like this: main{ {ls""|sort key=fileLength|pull} }

Apparently ls"" works just as well as ls".". I think you can save a byte from that

@KritixiLithos It seems to. Thanks!

Zsh -C4, 9 bytes

-C: enables noclobber (Zsh will not redirect to files which already exist)
-4: enables globdots (* matches files beginning with ..

Leading/trailing symbols are allowed, as long as it's clear which file has been chosen.

The following prints the file name, preceded by $0:1: file exists:  and followed by a newline, to stderr:
>*(oL[1])

Try it online!
Try it online!

Try it online!

(oL) sorts by size
[1] selects the first match

I used to have just *(oL[1]) and rely on Zsh printing "command not found", but if the file matches the name of a builtin or executable, this would break.  Additionally, the previous echo methods would break if the smallest file was -e or - or similar (interpreted as a flag to echo). This new method works for all file names and is still very short.

SmileBASIC 3, 105 bytes (competing?)
Beats 12Me21's answer but still suffers from inability to load DAT files (which feels very cruel to be disqualifying considering the circumstances.)
DIM F$[0],T[0]FILES"TXT:",F$FOR I=0TO LEN(F$)-1F$[I][0]="TXT:
PUSH T,LEN(LOAD(F$[I]))NEXT
SORT T,F$?F$[0]

The shorter version above is annoying and prompts you on every file to load, but it does work. For two bytes more you can suppress the prompt; change line 2 to this:
PUSH T,LEN(LOAD(F$[I],0))NEXT

Batch File, 33 bytes
Batch files are moderately competitive this time, oddly enough.
@dir/os/b>..\q&set/pa=<..\q&"%a%.

Output

Find a way to stop the creation of q prior to dir/os/b being run and you'll save a maximum of 6 bytes by not needing to put the output file in a separate directory.
@dir/os/b>q&set/pa=<q&"%a%

Will always output q as the smallest file (unless tied for another 0 byte file) as it is created as an empty file before dir/b/os gathers a list of files.

C++17 (gcc), 180 bytes
#include<filesystem>
using namespace std::filesystem;auto f(){std::error_code e;path r;size_t m=-1,s;for(auto&p:directory_iterator(".")){s=file_size(p,e);if(s<m)m=s,r=p;}return r;}

Try it online!
Requires a recent standard library that implements std::filesystem.

PowerShell 6+ for Windows, 20 bytes
ls|sort l* -t 1|% n*

Try it online!
Unrolled:
ls|sort length -top 1|% Name

See also AdmBorkBork's answer.

Red, 56 bytes
first sort/compare read %. func[a b][(size? a)< size? b]

Pyth, 51 bytes
.ml$open(b,"rb").read()$$__import__("os").listdir()

I feel like Pyth might not be the best tool for the job here...
Try it online!


text:
Golf Me A Bubble Sort
Your task is to create a program that performs a bubble sort on a given array until it is sorted.

Algorithm
In order to qualify as a bubble sort, the program must operate as follows:

Each pass goes through the array, looks at every two adjacent elements in turn, and potentially swaps them.
Each pass goes through the array in the same direction and without gaps. There are no partial passes - each pass must go through the whole array.
The program must never compare or swap array elements that aren't adjacent.
A sufficient (and finite) number of passes must be performed, such that the output array is guaranteed to be sorted. (E.g. you can safely stop if there was a whole pass without any swaps, or after len(array) passes have been made, etc.)

Rules

You must provide a sufficient explanation for how your answer does a bubble sort.
You may not use built-in or standard library sorting algorithms. You must make your own code.
Your program should take an array of numbers as input and output them in the correct order.

Input: 10 5 9 2 . . . (and so on)
The program should always output the sorted array.
Output can be an array returned by the program when run, or it can modify the input array in-place.
Output can also be the correctly ordered values separated by whitespace.

Speed does not matter as much as if the program functions.

Test Cases

10 5 9 2 1 6 8 3 7 4 (you can format it differently depending on your language)
1 2 5 4 3

This is code-golf, so the shortest answer in bytes wins.

@Suever There is no set number of comparisons for this challenge.

Saying "use this algorithm" is usually seen as a non-observable requirement. Perhaps "perform one iteration" of bubble sort is a better challenge?

Also, 10 minutes in the sandbox isn't very long. You should leave it there for longer (at least a day, if not more) to get more feedback first.

@FlipTack I will remember for next time I ask something

It seems very similar to this challenge, except that one has a parameter for max comparisons.

It's well known that many people mix up the various simple quadratic sorts. I agree with FlipTack that asking specifically for bubble sort makes a bad question, but I would add that if you do want to require a specific algorithm then you must clearly specific exactly what qualifies as that algorithm. This question as it stands is inviting arguments over the difference between insertion sort, selection sort, and bubble sort.

@PeterTaylor: It could be distinguished from those two, by requiring that comparisons are only ever allowed between two adjacent elements.

@smls, that doesn't distinguish insertion sort from bubble sort, which rather supports my point.

http://codegolf.stackexchange.com/questions/92753/bubble-sorting-in-progress

@carusocomputing This challenge requires you to perform a bubble sort until the array is sorted, rather than a specific number of times.

And we're saying that's not a good requirement, because [code-golf] generally only cares about input and output, not process.

@mbomb007 There are differences. My challenge asks that it takes 1 input and outputs an array that is in order no matter what, while the other challenge takes 2 inputs and only outputs the array if it is sorted in n iterations of bubble sort, where n is the second argument.

Maybe you should read the meta post that Fliptack linked to.

ckjbgames, I edited the task to add a clear(er) specification of what counts as a bubble sort is. Feel free to revert if you don't agree. @PeterTaylor, does this sufficiently distinguish it from insertion sort?

@smls I think this distinguishes it enough.

Bubble sort is well defined and the OP has a link to the wikipedia article for it. In my opinion this should be more than sufficient when it comes to distinguishing bubble sort from other sorts.

@FlipTack in his defense, it has been upvoted 3 times.

@JackBates yes, but also two downvotes, and the post was actually closed at first until it was more clearly specified. These flaws could have been eliminated by posting in the sandbox first, as everyone should.

Haskell, 55 53 bytes
f(a:b:c)=min a b:f(max a b:c)
f x=x
foldr(\_->f)=<<id

Usage example: foldr(\_->f)=<<id $ [3,1,6,4,3,8,3,1,1,2] -> [1,1,1,2,3,3,3,4,6,8]. Try it online!.
How it works: f does one iteration by keeping the minimum of the first two elements and appending a recursive call with the maximum of the first two elements and all the other elements. It stops when there are less than two  elements in the list. The main function calls f length <input> times by iterating over the input list via fold but ignoring the elements.

Octave, 77 75 bytes
i=1;while any(diff(x)<0),i=mod(i,rows(x)-1)+1;x(i:i+1)=sort(x(i:i+1));end,x

A crude first attempt. I'm sure I'll be able to golf this a bit. Takes input as a row vector.
Explanation:
i=1;                           % Initialize iterator to 1;
    while                      % Start loop
              diff(x)     % diff(x) creates a vector with the difference between
                          % adjacent elements

              diff(x)<0   % Checks if there are less than 0 (unsorted vector)

          any(diff(x)<0)  % True if there's at least one negative difference

i=mod(i,rows(x)-1)+1      % i++, but loop around if it's equal to the number of rows
x(i:i+1)=sort(x(i:i+1);   % Take two adjacent elements, sort them and put them back in
end,x                     % End loop and display result

Perl 6, 44 bytes
{.[*]=.[1,0]if [<] $_ for |(.[1..*]Z$_)xx$_}

Takes an array of numbers, and modifies it in-place (so that it is sorted after calling the lambda).
How it works
{                                          }  # A lambda taking one argument.
                                              # e.g [a,b,c]
                            .[1..*]Z$_        # Zip it with itself offset by one.
                                              # e.g. (b,a),(c,b),(d,c)
                          |(          )xx$_   # Repeat this by the input's length.
                                              # e.g. (b,a),(c,b),(d,c),(b,a),(c,b),(d,c),(b,a),(c,b),(d,c)
                      for                     # For each of those pairs:
            if [<] $_                         # If its 1st element is less than the 2nd:
 .[*]=.[1,0]                                  # Swap their values.

This works because the elements of a Perl 6 array are actually mutable item containers (akin to pointers in C except that they hide themselves well). So in the list we iterate over, each pair consists of two item containers from the array.

It is fine to use this.

SmileBASIC, 79 bytes
DEF S A
FOR Z=0TO I
FOR I=1TO LEN(A)-1SWAP A[I-(A[I-1]>A[I])],A[I]NEXT
NEXT
END

This one is pretty simple. It just runs LEN(A) (actually LEN(A)+2 just in case) iterations of bubble sort, which is guaranteed to sort the array.
The only slightly interesting part is how I avoided using IF/THEN:
SWAP A[I-(A[I-1]>A[I])],A[I]. If the two adjacent values are in the wrong positions (if (A[I-1]>A[I]) is true), it swaps A[I-1] with A[I], otherwise it swaps A[I-0] with A[I], which does nothing.

Javascript 98, 97, 91 Bytes
edit: removed unneeded semicolon and fixed broken code. Also moved some variable declarations and increments around.
x=>{for(h=1;h--;){for(i=d=0;d<x.length;i=d++){if(x[i]>x[d]){y=x[i];x[i]=x[d];x[d]=y;h=1}}}}

Ungolfed:
x=>{
    for(h=1;h--;){
        for(i=d=0;d<x.length;i=d++){
            if(x[i]>x[d]){
                y=x[i];
                x[i]=x[d];
                x[d]=y;
                h=1
            }
        }
    }
}

Explanation:
x=>{
    for(h=1;h--;){  //set the change tracker, h, to true. On the start of each loop, evaluate it, then decrement it.
                    //If true, sets to false. If false, exits the loop and sets it to -1.

        for(i=d=0;d<x.length;i=d++){ //i and d are our array indexers. They're both set to null for the first loop, then on subsequent loops i is set to d, then d is incremented.
                                     // Therefore, on each subsequent loop, d will be 1 more than i.

            if(x[i]>x[d]){ //if the previous value, i, is greater than the current value, d, switch their places using the temporary variable y.
                y=x[i];
                x[i]=x[d];
                x[d]=y;
                h=1     //set the change tracker to true.
            }
        }
    }
}

It's rather simple and embarrassingly long, so any suggestions are greatly appreciated!

Explanation please? That is in the requirements.

Sorry about that! I've edited it into the bottom of my original post.

Python 2, 104 bytes
Straightforward implementation.
L=input()
while L!=sorted(L):
 for i in range(len(L)-1):
    if L[i]>L[i+1]:L[i],L[i+1]=L[i+1],L[i]
print L

Try it online
While not sorted, for each index in the list, swap with next item if greater.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Implement a Stopwatch
Implement a simple digital Stopwatch,
which will display the time elapsed in seconds and minutes, as described below.

Important
Please read both Display and Controls sections !

Display
Time elapsed, should be displayed in the MM:SS format,
by replacing the previously displayed time string "in-place"
(clearing the whole or a part of the screen is also allowed).
The stopwatch must be updated at least every second.
Examples:
0 minutes, 0 seconds
00:00

0 minutes, 33 seconds
00:33

1 minute, 50 seconds
01:50

Initially, you can start with '00:00' or with any other value in range [00:00-59:59].
Once your Stopwatch reaches 59:59, it should reset to 00:00 and continue afresh.
You can use a different base (instead of decimal) or even a different numeral system if you wish, as long as you follow the general pattern.
For example 13:03 can be displayed as:
Decimal
13:03

Hexadecimal
0D:03

Base64
N:D

Quater-imaginary base
10101:3

Roman Numerals
XIII:III

Beware that if you use a non-decimal numeral system/base, it must be encoded using printable ASCII (or Unicode) characters, e.g. using two binary (unprintable) bytes for minutes and seconds is not allowed.
You must also left-pad your output with zeroes as appropriate, if your numerical system allows for that.
Replacing the separator character : with any other printable character (including digits) is also acceptable.
Controls
The stopwatch should start paused, and stay in this state, until user explicitly starts it, by pressing the 'control' key (see below).
If, while stopwatch is counting, user presses the 'control' key again, the stopwatch should pause (keeping the current time), until the 'control' key is pressed a one more time.
The 'control' key can be a single keystroke, e.g. s,
or any combination of keys, e.g. Ctrl+Shift+X, but it must be 'atomic', pressing multiple keys in sequence, e.g. s then Enter, is not allowed.
The same 'control' key (or combination) must be used to pause and resume the stopwatch.
You must use a specific 'control' key, i.e. 'any key' is not allowed.
Alternatively, you can use a single or double mouse-click, instead of a keypress for 'control'.

Rules

This is code-golf, the shortest answer in bytes wins;
Standard code-golf loopholes apply;
Your program must (theoretically) be capable of running forever.

Can the 'control' key be enter?

@Loovjo Yes, any single key or combination of keys will do, including Enter (as long it can be paused and then resumed using the same key).

related

Do we need sub-second granularity? I.e. if the user pauses approximately 7000 milliseconds after 00:05 is printed, and then at some point resumes again, must the 00:06 appear 3000 milliseconds after the resume key was pressed, or is it okay to print it a full second after the resume key was pressed?

@smls It is ok to wait a full second, after the resume.

SmileBASIC, 86 77 71 bytes
@L
N=N!=DIALOG(FORMAT$("%02D:%02D",F/60MOD 60,F MOD 60),,,N)F=F+1GOTO@L

DIALOG displays a textbox on the touch screen. N is the number of seconds the text box will stay on screen before it disappears. If N is 0, it stays until the user presses the button on the touch screen.
DIALOG Returns 1 if the user pressed the button, and 0 if it closed automatically. So when the user pushes the pause button, it returns 1, and the display time is set to 0, pausing the stopwatch. After the user presses the button again, we set the display time back to 1, resuming the timer. Basically, every time DIALOG returns 1, the display time is switched between 1 and 0 using !=, which is eqivilant to a logical XOR as long as both inputs are 1 or 0.

This looks awesome ! If you could also provide an animated "screencast" of how it works, that would be greatly appreciated !

Ok, I'll do it soon

It could also be tested on this emulator: https://citra-emu.org/game/smilebasic/

Python 2, 167 129 bytes
-36 bytes mostly* from using Maltysen's idea of catching ctrl-c using an exception - go give credit!
-4 bytes thanks to DLosc (init n and b to 0 rather than f())
-1 byte thanks to FlipTack (use p^=1 rather than p=1-p)
-2 bytes thanks to Felipe Nardi Batista (remove precision specifiers)
import time
f=time.time
n=b=p=0
while 1:
 try:n=[n,f()][p];t=n-b;print'\r%02d:%02d'%(t/60%60,t%60),
 except:b=[b-n+f(),b][p];p^=1

Works the same as my original, below, but with the control key sequence of ctrl+c.
(Tested by me with Python 2.7.8 on Windows 7, 64bit;
Tested by Brian Minton with Python 2.7.13 on linux, 64bit)
* also collapsed if statement to a list lookup in order to get the try as a one-liner.
My original:
import time,msvcrt as m
f=time.time
n=b=p=0
while 1:
 if m.kbhit()and m.getch()==b'p':b=[b-n+f(),b][p];p^=1
 if p:n=f()
 t=n-b;print'\r%0.2d:%0.2d'%(t/60%60,t%60),

(Tested by me with Python 2.7.8 on Windows 7, 64bit - this code, however, is Windows specific due to the use of the msvcrt library)
The control key is 'p'.
n and b are initialised to the same value at start-up, giving an "offset" of 0; p is initialised to 0, indicating a paused state.
Whenever the control key is pressed the value of p is switched. When switching from a paused state to an active state b is updated to a new value keeping any current offset from the previous active state(s) with b-n.
During an active state n is repeatedly updated to the current time by calling time.time().
The difference between n and b, t, is then the total number of seconds (including a fractional part) elapsed during active state(s).
The minutes elapsed are then t/60 and each of the minutes and seconds are displayed mod 60 with (t/60%60,t%60). Leading zeros are prepended for each using string formatting of the integer part with '...%0.2d...'. Printing a tuple (the trailing ,) where the first item has a leading carriage return (the \r) causes the previously printed text to be overwritten.

Ah yes, good catch, I originally did have ^= but switched at some point during formulation.

@DLosc indeed, thanks...

It's not Windows specific.  I just tested this on linux 64 bit with Python 2.7.13 and it worked. (with the control key of Ctrl-C)

@BrianMinton thank you for letting me know!

what's the need for the . in %0.2d ? it works just fine as %02d

@FelipeNardiBatista You're right, they are redundant (precision specification does not do much for decimal integers!) I shall remove them - thanks.

Python - 160 159 143 bytes
Thanks to @JonathanAllan for saving me 18 bytes!
Only uses builtin libraries, so the control key is ctrl-c, catching it with an except keyboardInterrupt.
import time
Z=0
print'00:00'
while 1:exec"try:\n while 1:\n  %s\nexcept:1\n"*2%(1,"print'\033c%02d:%02d'%divmod(Z%3600,60);Z+=1;time.sleep(1)")

Oh nice. I think maybe it could shorter with just except:? I have a working version of mine doing it...

@JonathanAllan oh cool, didn't know you could do that.

bash + Unix utilities, 90 or 93 bytes
90-byte version:
trap d=\$[!d] 2;for((n=0;;)){((d|!n))&&dc<<<DP60dod*d$n\r%+n|colrm 1 4&&: $[n++];sleep 1;}

93-byte version:
trap d=\$[!d] 2;for((n=0;;)){((d|!n))&&dc<<<DP60dod*$n+n|colrm 1 4&&n=$[(n+1)%3600];sleep 1;}

Ctrl-C is the resume/pause character.  A space is the delimiter between minutes and seconds.
The difference between the two versions is that the 90-byte program will work for 2^63 seconds (at which point, bash will give me an integer overflow).
The 93-byte version will truly work forever.
The original problem included the requirement: "Your program must (theoretically) be capable of running forever."
If running for 2^63 seconds is sufficient to meet that requirement, then the 90-byte solution works.  That duration is more than 20 times the age of the universe!
If the program needs to be able to run for longer than that, I'll have to go with the 93-byte solution.

I should probably point out that this solution, as well as at least some of the others posted, will very slowly fall behind the true elapsed time.  This slippage is because the program is sleeping for one second between each execution of the body of the loop, but the body of the loop does take some tiny amount of time to execute.  This will be inconsequential in practice.

It looks like this will not display an initial value on the screen, until you "unpause" it.

"The stopwatch should start paused, and stay in this state, until user explicitly starts it, by pressing the 'control' key (see below)."  Is there a spec I missed?

yep this is correct, but it should still display an initial value Initially, you can start with '00:00' or with any other value in range [00:00-59:59], which will stay on the screen until you press 'control' for the first time. Sorry if I have not been able to formulate this clear enough !

OK, that makes sense -- I'll modify it.

I've changed the programs to start with an initial display of 00 00 (still in the paused state though). I also made a couple of other changes (a 1-byte improvement and a copy-and-paste error fix).

Looks all good now !

Why is the backslash in \r needed? It seems to work without it.

The 93 byte could be reduced by using (n+d) instead of (n+1). No need for ((d|!n)). The code becomes: trap d=\$[!d] 2;for((n=0;;)){ dc<<<DP60dod*$n+n|colrm 1 4&&n=$[(n+d)%3600];sleep 1;} at 84 bytes.

Furthermore, as it is assumed that d starts at 0, the same could be assumed for n, removing the need for n=0. The code then reduces to 81 bytes.

QBasic, 213 211 bytes
Control key is tab. Leaving this running may cause laptop fires. You have been warned.
DO
WHILE k$<>CHR$(9)
k$=INKEY$
LOCATE 1
?CHR$(48+m\10);CHR$(48+(m MOD 10));":";CHR$(48+(d MOD 60)\10);CHR$(48+(d MOD 10))
IF r THEN
n=TIMER
d=v+n-b+86400
m=d\60MOD 60
END IF
WEND
k$=""
v=v+n-b
r=1-r
b=TIMER
LOOP

Here it is in action, pausing at  10, 15, and 20 seconds:

Ungolfed and commented
' Outer loop runs forever
DO
  ' The WHILE-WEND loop runs until tab is pressed
  WHILE key$ <> CHR$(9)
    key$ = INKEY$
    ' Output the stopwatch value at top left of screen
    LOCATE 1
    ' Unfortunately, QBasic's PRINT USING doesn't have a format for printing
    ' with leading zeros, so we have to do it manually by printing the
    ' 10s digit and the 1s digit
    PRINT CHR$(48 + minute \ 10); CHR$(48 + (minute MOD 10));
    PRINT ":";
    PRINT CHR$(48 + second \ 10); CHR$(48 + (second MOD 10))
    ' Update the current time if the running flag is set
    IF running THEN now = TIMER
    ' Take the difference between now and the last time we started the
    ' stopwatch, plus the amount of saved time from previous runs,
    ' plus 86400 to account for the possibility of running over midnight
    ' (since TIMER is the number of seconds since midnight, and QBasic's
    ' MOD doesn't handle negative values like we would need it to)
    diff = saved + now - lastStarted + 86400
    second = diff MOD 60
    minute = diff \ 60 MOD 60
  WEND
  ' If we're outside the WHILE loop, the user pressed tab
  key$ = ""
  ' Add the previous run's time to the saved amount
  saved = saved + now - lastStarted
  ' Toggle running between 0 and 1
  running = 1 - running
  ' If we're starting, we want to put the current time in lastStarted;
  ' if we're stopping, it doesn't matter
  lastStarted = TIMER
LOOP

Note that values of TIMER are floating-point. This doesn't affect the output, since MOD and \ truncate to integers. But it does add accuracy to the amount of saved time: if you pause the timer right before a tick, you'll see when you start it up again that the number changes in less than a second.

Batch, 132 bytes
set/ar=0,m=s=100
:l
cls
@choice/t 1 /d y /m %m:~1%:%s:~1% /n
set/as+=r,m+=c=s/160,s-=c*60,m-=m/160*60,r^^=%errorlevel%-1
goto l

Pressing n will (un)pause the timer. The output flicker can be reduced at a cost of three (or four) bytes.

Pure bash, 141 bytes
set -m
while ! read -t 1;do printf '\r%02i:%02i' $[s=s>3598?0:s+1,s/60] $[s%60];done&trap 'fg>/dev/null' TSTP
printf '00:00'
kill -STOP $!
read

This uses nothing but Bash builtins (no external tools). The control character is Ctrl-Z, so that standard SIGTSTP handling pauses the stopwatch.

set -m enables job control, which is usually off in a script.
A subshell process is backgrounded (&).

read -t 1 waits one second for input from the user, then fails.
The until loop continues as long as read keeps failing.
printf outputs the correctly-padded and -formatted time
$[s=s>3598?0:s+1,s/60] arithmetic expansion first computes the updated time, checking whether to wrap and otherwise incrementing the seconds counter s, and then returns the floored division s/60.
$[s%60] gives the seconds remainder.

The outer script sets up a trap handler for TSTP, the signal Ctrl-Z generates. When Ctrl-Z is pressed while the outer script is running, it will run fg>/dev/null and put the subshell back into the foreground. >/dev/null is necessary to stop fg printing out the subshell command every time.
The script prints the initial 00:00 and sends a STOP signal to the child process $!, which will pause the process.
read waits for input forever, keeping the script alive.

If Ctrl-Z is pressed while the subshell is foregrounded, it will pause execution and return the outer script to the foreground, where it will wait silently. If the outer script is foregrounded, the trap handler will resume the subshell's execution, and it will count up again.

C 309 179 bytes
f(){m=0,s=0;A: while(getchar()^'\n'){if(s++==59){if(m++==59)m=0;s=0;}printf("\r%02d:%02d",m,s);sleep(1);system("clear");if(getchar()=='\n'){break;}}while(getchar()^'\n'){}goto A;}

Ungolfed version:
void f()
{
   int m=0,s=0;

   A: while(getchar()^'\n')
      {
       if(s++==59)
       {
         if(m++==59)
           m=0;

         s=0;
       }
       printf("\r%02d:%02d",m,s);
       sleep(1);
       system("clear");

        if(getchar()=='\n')
        {
          break;
        }
      }

       while(getchar()^'\n')
       {}
       goto A ;
}

Usage: Press Enter to Pause and Resume the Stopwatch.
Explanation:

Wait for Enter keystroke, break the first while loop and wait until next Enter comes.
Upon next Enter keystroke, goto first while loop and resume counting.

Now, I know goto is a bad coding practice in C, but I could not figure out another way.

The code doesn't compile. Furthermore, getchar() blocks until some character is pressed.

compiles and runs on a linux machine

The ungolfed version perhaps, but the golfed version does not. Already at m=0,s=0; it fails, because you did not declare these variables anywhere.

HTML + JavaScript (ES6), 191 192 187 183 174 bytes
<b onclick='b=b?clearInterval(b):setInterval("a.innerHTML=`${(d=(((c=a.innerHTML.split`:`)[1]>58)+c[0])%60)>9?d:`0`+d}:${(e=++c[1]%60)>9?e:`0`+e}",1e3)'onload='b=0'id=a>00:00

Explanation
Click the timer to start or pause the stopwatch. As such, a single click is the control key. The separator between the two values is a colon.
Whenever the user clicks the click, the value of b is checked. It is initialised to 0 which evaluates to false, so a string of code is evaluated every 1000 milliseconds. This sets the variable to the id of the interval, so it can be stopped later. If b contains a number, it evaluates to true, so the interval is stopped. This returns the value undefined, so the cycle continues.
The string of code changes the html of the element with id a (the stopwatch). First the minutes are parsed by taking the previous stopwatch value, splitting it by the colon, and getting the minutes value, which is increased by 0 if the value of the seconds is not 59 (greater than 58), and 1 otherwise, modulo 60. Then this value is padded. Then comes the colon, and lastly, the seconds. The code simply gets the old value, increases it by 1, takes modulo 60 and optionally pads it.

This doesn't seem to work at all. I just get ReferenceError: d is not defined

You can probably also save a few bytes by removing the href=# since it's not actually needed since you're using onclick.

I just fixed that. I also removed the href, because you were right. Thanks!

Can't you put the onclick on the b tag and specify so in the answer?

I suppose that works. It saved 9B. Thanks a lot!

Javascript in Chrome console, 143 bytes
f=document,m=s=g=i=0;setInterval(()=>{if(g%2){m=(i/60|0)%60;s=i++%60}f.write((m>9?m:'0'+m)+':'+(s>9?s:'0'+s));f.close();f.onclick=()=>g++},1e3)

When entered in console it inits the counter to 00:00 and then enables the control which is keypress on the document.
Not much magic going on, notably the (i/60)|0 floors the number
Done and tested in Chrome console

Nice answer. You can remove some bytes by using a dummy argument for the functions that don't take an argument, and you can replace the first argument in the setInterval by a string containing the code.

132 B: m=s=g=i=0;(f=document).onclick=_=>g++;setInterval("g%2&&f.close(f.write(\${(m=i/60%60|0)>9?m:'0'+m}:`+((s=i++%60)>9?s:'0'+s)))",1e3)`

Ohh, nice :) Learned a couple of things here. String in interval and the _=>g++ . Thanks :)

Javascript, 124 bytes
s=i=1,setInterval("s&&(d=document).close(d.write(`0${i/60%60|0}:`.slice(-3)+`0${i++%60}`.slice(-2))),d.onclick=_=>s=!s",1e3)

The 'control key' is a click on the document.
To test this, paste the code in the console or in a html file inside the <script> tag.
Explanation:
let s = 1
let i = 1
setInterval(() => {
    //If s = true then check after the "&&" operator else false
    s && (d = document).close( //put the document variable inside the d variable, so now i don't need to use anymore the long word 'document, then i close the document
            d.write( //Write into the document the next string
                `0${i/60%60|0}:`.slice(-3) + `0${i++%60}`.slice(-2) //Here is the magic, here I update the 'i' variable and convert the 'i' value to minutes and seconds
            )
        ),
        d.onclick = _ => s = !s //Add onclick event to the document, if s = true then s = false, if s = false then s = true
}, 1e3) //1e3 = 1000

Tested in Chrome

Welcome to the site! Would it be possible to edit in a link to an online testing site, such as Try it online!, so that other users can verify your answer?

Thanks @cairdcoinheringaahing, this is with jsfiddle: https://jsfiddle.net/xjw7o0ps/

C# 220 Bytes
using static System.Console;
using static System.DateTime;
class P
{
    static void Main()
    {
        var l = Now;
        var d = l-l;
        for( var r = 1<0;;Write($"\r{d:mm\\:ss}"))
        {
            if (KeyAvailable&&ReadKey(1<2).KeyChar == 's')
            {
                l = Now;
                r = !r;
            }
            if (r)
                d -= l - (l = Now);
        }

    }
}

Golfed
using static System.Console;using static System.DateTime;class P{static void Main(){var l=Now;var d=l-l;for(var r=1<0;;Write($"\r{d:mm\\:ss}")){(KeyAvailable&&ReadKey(1<2).KeyChar=='s'){l=Now;r=!r;}if(r)d-=l-(l=Now);}}}

Using the s key to start/stop.
Whole program works by remembering the TimeDelta using DateTime.Now
Most C#-Magic here comes from the C# 7.0 feature using static.

PHP, 94 91 bytes
I assume that 32 is the key code for the space bar (which it probably is not);
I currently have no way to test ncurses. But the rest of the code works fine.
for($s=[STDIN];;)echo date("\ri:s",$t+=$r^=stream_select($s,$n,$n,1)&&32==ncurses_getch());

starts at 00:00, but increments immediately when pause ends
If You (like me) don´t have ncurses, You can test by replacing the second date parameter with $t+=$r^=!rand(sleep(1),19); or $t+=$r^=++$x%20<1+sleep(1);. (sleep always returns 0.)
breakdown
for($s=[STDIN];                     // set pointer for stream_select
    ;                               // infinite loop:
)
    echo date("\ri:s",                  // 5. print CR + time
        $t+=                            // 4. increment $t if watch is running
        $r^=                            // 3. then toggle pause
            stream_select($s,$n,$n,1)   // 1. wait 1 second for a keystroke
            &&32==ncurses_getch()       // 2. if keystroke, and key==space bar
    ;

Bash, 65 bytes
trap d=\$[!d] 2;for((;;)){ printf "\r%(%M:%S)T" $[n+=d];sleep 1;}
Note that it must be written to a file script to work correctly, or else, try:
bash -c 'trap d=\$[!d] 2;for((;;)){ printf "\r%(%M:%S)T" $[n+=d];sleep 1;}'
Extended version to explain it:
trap d=\$[!d] 2                     # flip d for each INT (ctrl-c) signal.
for((n=0;;)){                       # repeat forever the code inside the {...}
                                    # The n=0 is not strictly needed.
    printf "\r%(%M:%S)T" "$[n+=d]"  # Print Minute:Second string calculated from
                                    # the n value, increment by the value of d.
                                    # If IFS is not numeric (0-9), then, the
                                    # quotes around "$[n+=d]" could be removed.
    sleep 1                         # wait for 1 second.
}

The %(...)T format to printf is valid in bash 5+.

Doesn't work. Just prints 00:00 and increments a counter when you hit Ctrl-C. There's no animation of the timer. (Tested on bash 5.0.7)

Did you write the code to an script? Or else please try: bash -c 'trap d=\$[!d] 2;for((;;)){ printf "\r%(%M:%S)T" $[n+=d];sleep 1;}'. @roblogic

Ahh, that worked! The script has to be run with bash -c :)

Commodore BASIC (C64/TheC64 Mini, VIC-20, PET, C16/+4) - 147 tokenized and BASIC bytes
 0?"{clear}":geta$:ifa$<>" "thengoto
 1ti$="000000"
 2fori=.to1:?"{home}"mid$(ti$,3,2)":"mid$(ti$,5,2):geta$:b$=ti$:i=-(a$=" "):nE:pO198,.
 3geta$:ifa$<>" "then3
 4ti$=b$:goto2

{clear} in the listing is SHIFT+CLR/HOME which outputs as one PETSCII character when following an opening quotation mark, whereas {home} is the CLR/HOME key without the shift on the same condition of following an opening quotation mark.
Use the space bar as the control key.
To work with the Commodore 128 in BASIC 7, change the listing in the following lines:
 0?"{clear}":geta$:ifa$<>" "thengoto0
 2fori=.to1:?"{home}"mid$(ti$,3,2)":"mid$(ti$,5,2):geta$:b$=ti$:i=-(a$=" "):nE:poK198,.

Adds an extra seven tokens to the count (as all numbers are stored in BASIC as 7 bytes, so goto10 is 8 tokenized bytes whereas goto is only 1).

C (gcc), 121 115 bytes
p,r;g(){r^=1;}main(t,b){for(b=time(signal(2,g));;r?p=t:(b+=t!=p))t=time(0)-b,printf("\r%02d:%02d  ",t/60%60,t%60);}

Try it online!
Sets a signal handler for SIGINT, which is triggered by pressing control-C. We keep a time offset in b, and display the wall clock time minus the time offset. If we are paused, increment the time base everytime the wall clock ticks to freeze the displayed time.
Thanks to @ceilingcat for shaving off 6 bytes!

Zsh + Gnu date, 242 bytes
Featuring 1/100ths of a second! It requires an interactive terminal, but here's a TIO link anyway.
Hit Enter to start/stop the timer; Ctrl-C to exit.
u(){p=`gdate +%s`;q=`gdate +%N`;}
f(){read -t0.01&&{read;break};unset REPLY}
g(){while :;{u;t=$[p-a];s=$[t%60];m=$[(t%3600-s)/60]
echo "\r`printf %02d:%02d $m $s`.$q[1,2]\c";f;}}
<<<ready;read;u;a=$p
while :;{f;echo "\r\e[2A\c";u;a=$[p-t];g;}

Comments (a bit out of date):
u()echo $[`gdate +%s%N`/1000]       # fn:unix timestamp extended to µs
v()gdate +%s                        # fn:unix time, in s
f(){read -t0.01 -r&&{read -r;break;} # fn:listens for "Enter"
                      ;unset REPLY;}

g(){while :;                        # fn:rolling stopwatch
    {q=`u`;t=$[`v`-a]               #    t=time diff from baseline (s)
    ;echo "\r`printf %02d:%02d      #    format output
    $[(t%3600-s)/60] $s`            #    minutes:seconds
    .${q:10:2}\c";                  #    .xx = partial seconds
    f;}}                            #    listen for "Enter"

                                    # Execution starts here!
<<<ready;read;u;a=$p                # Wait for "Enter"; get baseline $a

while :;{                           # Main program loop
         f;                         # listen for an "Enter"
           echo "\r\e[2A\c"         # go up 1 line of the console
a=$[`v`-t]                          # reset the baseline
                ;g;}                # begin the stopwatch

@Isaac, there's no way I could beat your answer for brevity & elegance, so I thought I'd add features instead...

That is an excellent goal @roblogic :-) .... .... still understanding your code ....

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Write a haiku-w detector
A haiku is a poem with three lines, with a 5/7/5 syllable count, respectively.
A haiku-w is poem with three lines, with a 5/7/5 word count, respectively.
Challenge
Write a program that will return true if the input is a haiku-w, and false if not.
A valid haiku-w input must consist of 3 lines, separated by a newline.

Line 1 must consist of 5 words, each word separated by a space.
Line 2 must consist of 7 words, each word separated by a space.
Line 3 must consist of 5 words, each word separated by a space.

Examples
The man in the suit
is the same man from the store.
He is a cool guy.

Result: True
Whitecaps on the bay:
A broken signboard banging
In the April wind.

Result: False

Rules

This is code-golf, so the shortest answer in bytes wins.
Standard code-golf loopholes apply. Cheating is prohibited.
Other boolean return values, such as 1 and 0, are acceptable.
A length-3 list of strings as an input is also acceptable.
Valid haiku-w inputs should not have leading or trailing spaces, or multiple spaces separating words.

Must the input be a single string (containing newlines), or can it be a length-3 list of strings?

A length-3 list of strings is acceptable. Editing the OP to reflect this.

Will the haiku-w always contain 3 lines?

Yes. If the input contains more than or fewer than 3 lines, the program should return false.

Will there ever be leading or trailing spaces on any line? Or multiple spaces separating words?

Good question. Valid haiku-w inputs should not have leading or trailing spaces, or multiple spaces separating words.

By the way, clarifications like this are a primary reason to post proposed questions in the Sandbox first. :)

Bonus points for submissions where the code itself is a haiku-w.

@Glorfindel - done. http://codegolf.stackexchange.com/a/108849/9524

JavaScript (ES6), 73 72 64 63 54 42 39 bytes
Thanks to Neil for saving 13 bytes
a=>a.map(b=>b.split` `.length)=='5,7,5'

Explanation
This is a fat-arrow function that takes an array of strings as argument. It replaces each line by its word count. If it is a haiku-w, a now contains an array of a five, a seven and a five again. Since JavaScript doesn't allow us to compare 2 arrays at the same time, the array is converted to a string first, and then compared. This results in a boolean that is returned.

% and * have the same precedence, so you don't need the ()s, although I think (d*2|5) might also work. Also you can get away with a single &, although I think you can improve on even that by using (b...).length==3>b.some(...length-...).

Thanks for the tip about the parentheses. Also, I changed my approach, so I don't explicitly check for length anymore.

Ah, in that case, don't bother with the calculation, just use a=>a.map(c=>c.split .length)=='5,7,5'.

Hehe, you're right. I should've thought of that...

You still don't need the +'' - == stringifies if the other argument is a string.

Really? Nice. Thanks

AWK (GNU Awk), 24, 30, 28, 20 bytes
Golfed
517253==$0=q=q NF NR

Will output "517253" for True, and empty string for False.

In awk, any nonzero numeric value or any nonempty string value is true. Any other value (zero or the null string, "") is false

The GNU Awk User's Guide
How It Works
Each awk statement (rule) consists of a pattern (or expression) with an associated action:
pattern {action}

Awk will read the input line by line (record by record) and evaluate pattern expression to see if a corresponding action is to be invoked.
The code above is a standalone Awk expression (pattern) w/o the action block, which is implied to be {print $0} in that case.
It should be read right-to-left:
q=q NF NR
Append a Number of Fields (words) and Number of Records (i.e. the current line number), to the variable q.
This way, when processing a proper Haiku-w, q will be set to:

51 - on line #1 (5 words)
5172 - on line #2 (5 words + 7 words)
517253 - on line #3 (5 words + 7 words + 5 words)

$0=q
Assign the newly computed value of q to $0 (which holds the whole current line/record by default).
517253==$0
Compare it with a "signature" for a proper Haiku-w (517253),
if there is a match, the whole expression evaluates to "true" and
a corresponding action (implicit print $0) is run, sending
"517253" to stdout (True), otherwise output will be empty (False).
Note that this will properly recognize a Haiku-w, even if it is followed by an arbitrary number of garbage lines, but I believe that is ok, as:

A length-3 list of strings as an input is also acceptable.

(i.e. we can assume the input to be 3 lines long)
Test
>awk '517253==$0=q=q NF NR'<<EOF
The man in the suit
is the same man from the store.
He is a cool guy.
EOF

517253

Try It Online !

This fails if the input consists of one line containing 575 words, or two lines containing 57 and 5 words, etc.

@Lynn, true, putting on hold, until this is fixed.

@Lynn, should be fixed now

Very clever fix! :)

Python, 42 bytes
lambda l:[s.count(' ')for s in l]==[4,6,4]

Try it online!
Takes input as a list of lines, with the words separated by single spaces.
As we're guaranteed there'll be no leading or trailing spaces, and only single spaces will seperate each word, we can verify a w-haiku by simply counting the spaces in each line.
We do this in a list comprehension, to create a list of the space-counts. If it is a correct haiku, it should look like [4, 6, 4], so we compare it with this and return the result.

If you're okay with supporting only Python 2, you can save two bytes: map(str.count,l,'   ').

Jelly, 10 9 bytes
ċ€⁶⁼“¥©¥‘

Try it online!
Explanation
ċ€⁶⁼“¥©¥‘  Input: length-3 list of strings
 €         For each string
ċ ⁶          Count the number of spaces
    “¥©¥‘  Convert string to code page indices, makes [4, 6, 4]
   ⁼       Match

Also ċ€⁶⁼4,6,4 and ċ€⁶⁼464D¤… I can’t find anything shorter, though. (Oh, you can flip it, too: 464D⁼ċ€⁶$)

ċ€⁶Ḍ=464 works fine for 8.

Actually, no it does not, sorry.

Batch, 102 bytes
@echo off
call:c&&call:c 2||exit/b
:c
set/an=%1+5
set/ps=
for %%W in (%s%)do set/an-=1
exit/b%n%

Exits with non-zero errorlevel as soon as it reads a line with the wrong number of words.

......well crap

Mathematica, 21 bytes
{4,6,4}==Count@" "/@#&

Unnamed function taking a list of lists of characters as input and returning True or False. Simply counts how many spaces are in each list of characters, which under the rules of the challenge correlate perfectly with the number of words in each line.
Previous submission:
Mathematica, 31 bytes
Length/@StringSplit/@#=={5,7,5}&

Unnamed function taking a list of strings as input and returning True or False.

Haskell, 34 33 bytes
f l=[sum[1|' '<-c]|c<-l]==[4,6,4]

Try it online!.
Edit: thanks to @xnor for a byte!

Pointful is shorter: f l=[sum[1|' '<-c]|c<-l]==[4,6,4].

Retina, 12 bytes
M%`
^4¶6¶4$

(there's a trailing space after the first line)
Try it online!

M%`  - Count the number of spaces in each line.

M - Match mode - print the number of matches.
% - for each line
` - separate configuration and regex pattern
  - just a space.

^4¶6¶4$ - There should be 4, 6, and 4 spaces, and exactly three lines.

¶ matches newlines. The rest is a simple regular expression.

Prints 1 for valid input, 0 for invalid.

PowerShell, 43 bytes
"$args"-replace'\S'-match'^(    )
\1
\1$'

Try it online!
Explanation
Takes input as a newline separated string.
Removes all non-whitespace, then checks to see that it matches "4 spaces, newline, 6 spaces, newline, 4 spaces newline" exactly, using a regex.
The capture group matches 4 spaces, the backreference \1 refers to that. Newlines are embedded in the string. Note the second line of the regex contains two spaces after the backreference.

That is an interesting aproach!

Python, 58 44 bytes
lambda h:[len(l.split())for l in h]==[5,7,5]

-14 by tbodt

You're allowed to take the input as a length 3 list of strings. You can save the bytes spent using split("\n").

44 bytes: lambda h:[len(l.split())for l in h]==[5,7,5]

Someone make this shorter to reach crossed out 44

Pyke, 11 9 bytes
dL/uq

Try it here!
dL/       -  map(i.count(" "), input)
        q - ^ == V
   u  -  [4, 6, 4]

After the u byte there are the following bytes: 0x03 0x04 0x06 0x04

Perl, 26 bytes
24 bytes of code + 2 bytes for -ap flags.
$m.=@F}{$_=$m==575&$.==3

Try it online!

Pyth, 9 bytes
qj464T/R;

A program that takes input of a list of "quoted strings" and prints True or False as appropriate.
Test suite
How it works
qj464T/R;   Program. Input: Q
qj464T/R;Q  Implicit variable fill
     T      Are the base-10
 j          digits
  464       of 464
q           equal
      /     to the number
        ;   of spaces
       R    in each string
         Q  in the input?
            Implicitly print

Japt, 11 bytes
Saved lots of bytes thanks to @ETHproductions
This takes an array of three strings as input.
®¸lÃ¥"5,7,5

Run it online!

C 142 bytes
void f(){char *c;l=3;s[3]={0};while(l>0){if(*c==' ')s[l-1]++;if((*c=getchar())=='\n'){l--;}}printf("%d",(s[0]==4 && s[1]==6 && s[2]==4)?1:0);}

Ungolfed version:
void f()
{
  char *c;
  c = (char *)malloc(sizeof(char));
  int l=3;
  int s[3]= {0};

  while(l>0)
  {
    if(*c==' ')
    s[l-1]++;

    if( (*c=getchar())=='\n')
    {
      l--;
    }
  }
  printf("%d",(s[0]==4 && s[1]==6 && s[2]==4)?1:0);
}

Returns 1 for 5/7/5 sequence else 0.
A positive testcase:

J, 12 bytes
4 6 4=#@;:@>

The input is a boxed list of strings.
Explanation
This is a fork with a constant left tine. This checks the result of the right tine, #@;:@>, for equality with 4 6 4. The right time unboxes each (>), then (@) converts each string to words (;:), then (@) takes the length of each (#).

C++, 357 bytes
Sort of new to code golf, but this is the best I could do quickly
#include <iostream>
using namespace std;
int n(std::string s)
{
    int b = 0;
    for(char c: s)
        if(c == ' ') b++;
    cout << "C = " << b;
    return b;
}
int main()
{
    string a, b, c;
    getline(cin, a);
    getline(cin, b);
    getline(cin, c);
    if(n(a)==4 && n(b)==6 && n(c)==4)
        cout<<'1';
    else cout << '0';
    return 0;
}

Welcome to PPCG! The goal of code golf is to make your code as short as possible; a good first step would be to remove all unnecessary whitespace.

R, 48 bytes
all(stringr::str_count(scan(,"")," ")==c(4,6,4))

Reads a 3-length character vector from stdin and works by counting the number of spaces. To count the number of spaces we use the str_count from the  stringr package which can count occurrences based on a regex pattern.
An alternative approach without using packages could be:
all(sapply(scan(,""),function(x)length(el(strsplit(x," "))))==c(5,7,5))

First time I've ever seen el before, thanks for that.

Ruby 1.9.3
Not golfed, but is itself a haiku-w
def haiku_w(input)
  lines = input.split("\n")
  lengths = lines.map(&:split).map(&:length)
  lengths.eql?([5,7,5])
end

or...
lines equals input split (newlines)
lengths equals lines map split map length
lengths equals five seven five?

Unfortunately doesn't work with leading whitespace on any lines, but does cope with trailing.

Python 2, 57 64 bytes
Edit Corrected with the addition of 7 bytes after feedback from @Dada. Thanks!
i,j=input,''
for x in i():j+=`len(x.split())`+' '
i(j=='5 7 5 ')

Try it online!
Not the shortest Python answer by a long way but just wanted to use the new trick I learned recently of using input() to display the output and save a print statement. Takes a list of lines as input. Requires Ctrl C (or any other key-press for that matter) to terminate the program (with an exception) in a terminal but works fine without on TIO.

This will fail in cases like this one.

I'll give you that @Dada. That is one serious test case :)

Corrected and tested with your test case.

MATL, 16 bytes
"@Y:Ybn&h][ACA]=

The input is a cell array of strings and returns a truthy or falsey array.
Try it Online
Explanation
        % Implicitly grab input
"       % For each element in the cell array
@Y:Yb   % Split it on spaces
n       % Count the number of elements
&h      % Horizontally concatenate everything on the stack
[ACA]   % Create the array [5 7 5]
=       % Perform an element-wise equality
        % Implicitly display the truthy/falsey array

MATLAB / Octave, 38 bytes
@(x)cellfun(@(y)sum(y==32),x)==[4 6 4]

This solution accepts a cell array of strings as input, counts the number of spaces in each line and then compares the result to the array [4 6 4] and yields a truthy (all values are 1) or falsey (any value is zero) array.
Online demo

Perl 6, 25 bytes
{.lines».words~~(5,7,5)}

Java (OpenJDK), 82 bytes
-2 bytes thanks to @corvus_192!
s->s[0].split(" ").length==5&s[2].split(" ").length==5&s[1].split(" ").length==7

Try it online!
It looks so golfable but without a builtin map function, I can't find a good way. Iterating through the array is a few bytes longer, as is writing a map function using streams.
Lambda expression takes an array of Strings and returns a Boolean.

What if you have only two lines as input, or four?

@KevinCruijssen according the op, "A length-3 list of strings as an input is also acceptable". My program takes a length-3 list of lines.

You could get a map function if you called Arrays.stream, but that's long enough that it may not be worth using (especially if you need to import Arrays)

@Pokechu22 yeah I tried that, still ended up being longer.

You can use & instead of && to save two bytes

Clojure, 44 bytes
#(=(for[l %](count(filter #{\ }l)))'(4 6 4))

Input is list of strings.
Function finds only spaces and counts them.
This explanation is a Haiku. :)

05AB1E, 9 bytes
€#€g575SQ

Try it online!
Explanation
€#         # split each line on spaces
  €g       # get length of each line
    575    # push the number 575
       S   # split into list of digits
        Q  # compare for equality

I couldn't get away from vy and 10 bytes, nice solution. Using ð¢ and 464 instead was my approach, unfortunately 464 is still 2 bytes compressed, obviously.

@carusocomputing: That's an interesting idea. I think you could post that as ð¢464SïQ in 2sable for 8 bytes.

You go ahead, that's more your answer than mine in all honesty (I think it's a winning answer too!)

@carusocomputing: ð¢ is the main part of that answer and it was your idea :)

ahhh, just give me a shoutout. If it ends up having a flaw I won't know how to fix it haha.

SmileBASIC, 96 94 bytes
INPUT A$,B$,C$?C(A$,4)*C(B$,6)*C(C$,4)DEF C(S,E)WHILE""<S
INC N,POP(S)<"!
WEND
RETURN N==E
END

Java 7, 154 bytes
class M{public static void main(String[]a){System.out.print(a.length==3&&a[0].split(" ").length==5&a[1].split(" ").length==7&a[2].split(" ").length==5);}}

The program requirement and potential of having less or more than three lines, not too mention Java's verbosity itself, causes this 'golfed' code to be pretty big..
Ungolfed:
Try it here.
class M{
  public static void main(String[] a){
    System.out.print(a.length == 3
        && a[0].split(" ").length == 5
         & a[1].split(" ").length == 7
         & a[2].split(" ").length == 5);
  }
}

SimpleTemplate, 77 bytes
Sadly, the regular expression aproach is the shortest.
{@if"@^([^\s]+ ?){5}\s([^\s]+ ?){7}\s([^\s]+ ?){5}+$@"is matchesargv}{@echo1}

Requires that the text is given as the first argument, with *NIX-style newlines.
This won't work with Windows-style newlines.
Ungolfed:
{@if "@^([^\s]+ ?){5}\s([^\s]+ ?){7}\s([^\s]+ ?){5}+$@"is matches argv}
    {@echo 1}
{@/}

Non-regex based, 114 byes
{@setR 1}{@eachargv asL keyK}{@php$DATA[L]=count(explode(' ',$DATA[L]))!=5+2*($DATA[K]&1)}{@set*R R,L}{@/}{@echoR}

This requires that each line is given as an argument to the function.
Ungolfed:
{@set result 1}
{@each argv as line key k}
    {@php $DATA['line'] = count(explode(' ', $DATA['line'])) != 5+2*( $DATA['k'] & 1 )}
    {@set* result result, line}
{@/}
{@echo result}

Stacked, 22 bytes
[' 'eq sum]map(4 6 4)=

Takes input from the top of the stack as a list of character strings, as such:
($'The man in the suit' $'is the same man from the store.' $'He is a cool guy.')

Explanation
[' 'eq sum]map(4 6 4)=
[         ]map          map the following function over each item
 ' 'eq                  vectorized equality with ' '
       sum              summed
              (4 6 4)=  is equal to (4 6 4)

Haskell, 29 bytes
([5,7,5]==).(length.words<$>)

Ungolfed
wordCount line = length (words line)
isHaikuW lines = map wordCount lines == [5, 7, 5]

I think this fails to validate the "Valid haiku-w inputs should not have leading or trailing spaces, or multiple spaces separating words."-rule specified in the challenge.

Regex, 44 Bytes
I'm new to codegolfing, but have attempted one with a regex.
/^(\S+ ){4}\S+\n(\S+ ){6}\S+\n(\S+ ){4}\S+$/

will match exactly 5, 7, 5 words and not match anything else.
ie.
Golfing with regex is fun
obscurity prevails; intention is hidden from view
and sanity is forever lost

First block (\S+ ){4}) matches four words (at least one nonspace character) with a trailing space. \S+\n matches a word and a newline.
Second block (\S+ ){6}\S+\n is similar but for 6 words, trailing space, word and newline.
Third block is identical to first (\S+ ){4}\S+\n)
^(...)$ ensures that the match is found at the beginning and end, so it won't match a haiku inside a string.
Suggested improvements welcome as it's my first time golfing (and I'm rusty at regex).

Ruby, 39 bytes
puts ARGV.map{|l|l.split.size}==[5,7,5]

Try it online!
Accepts lines of input as command-line arguments, finds the word counts, and check they are 5/7/5

Welcome to PPCG!

@ConorO'Brien Thanks

C# 6 - 80 bytes (98 with using)
bool a(string[]s)=>s.Select(x=>x.Split(' ').Length).SequenceEqual(new[]{5,7,5});

This, as usual, assumes a method is enough, and doesn't include a complete program.
It also doesn't include using System.Linq;, as it is present as default in the standard C# class template from VS 2008 onwards. Add 18 bytes if you want to include it in the count.
The method accepts the input as an aray of strings (one per line), then splits every string using spaces as separators, keeping the length of every array generated this way. Finally, it checks if those lengths are equal to {5,7,5}.

PHP - 78 75 bytes
Saved one byte thanks to Kevin Cruijssen
Here's my first ever submission on PPCG :
<?=preg_match('#^(\S+ ){4}\S+\r\n(\S+ ){6}\S+\r\n(\S+ ){4}\S+$#',$argv[1]);

Regex breakdown :
#                   Regex delimiter
^                   Starts with
(\S+ ){4}           [Any non-space character present n times, followed by a space] x 4
\S+                 Any non-space character present n times
\r\n                Carriage return
(\S+ ){6}           [Any non-space character present n times, followed by a space] x 6
\S+                 Any non-space character present n times
\r\n                Carriage return
(\S+ ){4}           [Any non-space character present n times, followed by a space] x 4
\S+                 Any non-space character present n times
$                   Ends with
#                   Regex delimiter

Try it online !

Hi, welcome to PPCG! This looks like a good first submission to me. Btw, you can save 1 more byte by removing the space after the comma. :) Enjoy your stay! (PS: If you haven't seen it yet, there is a Tips for golfing in PHP post you might find interesting to read through.)

Hi, thanks for the tip and the link. I managed to save another 2 bytes by switching echo  to <?=.

PHP, 46 bytes
<?=array_map(str_word_count,$argv)==[0,5,7,5];

Run like this:
echo '<?=array_map(str_word_count,$argv)==[0,5,7,5];' | php -- "The man in the suit" "is the same man from the store." "He is a cool guy." 2>/dev/null
> 1

Explanation
<?=                        # Print result of the expression.
  array_map(               # Apply function to each input line.
    str_word_count,        # Count words
    $argv
  )==[0,5,7,5];            # Check if result is 5,7,5 (need 0 because
                           # first arg is always `-`).

Are you sure that word_count()==0 will work for any $argv[1]?

@Titus, do you mean $argv[0]? The first argument when running with -r or passing code via stdin

... is always -

... in online interpreters. Save to file and try offline. ;) Yea ok ... it works for stdin.

My code is not intended to be run from file. So it's valid then. In any case, if you want to run it from a file, just add [0]+... at the beginning, and it will force the first array item to be 0, regardless of the script name. (4 bytes)

No, it´s ok; but [0]+ is a nice hint.

R, 100 bytes
f<-function(a){all(sapply(a,function(x){length(grep(" ",as.list(strsplit(x,"")[[1]])))})==c(4,6,4))}

Takes as an argument a length-3 list of strings. Probably won't be golfed further since further golfing turns it into @Billywob's answer.

SpecBAS - 135 bytes
1 INPUT a$: DIM b$(SPLIT a$,NOT ","): l$=""
2 FOR EACH c$ IN b$()
3 DIM d$(SPLIT c$,NOT " ")
4 l$=l$+STR$ ARSIZE d$()
5 NEXT c$
6  ?l$="575"

Input is a comma separated string, each part being put in an array.
Then each of those elements are split up on spaces and the length of that array is appended to a string.
Prints 1 (true) or 0 (false) if it matches the 5-7-5 format.

C#, 136 124 bytes
Saved 12 bytes thanks to VisualMelon
class P{static void Main(string[]s){var v="";foreach(var c in s)v+=c.Split(' ').Length;System.Console.WriteLine(v=="575");}}

Arguments require each sentence to be wrapped in double quotes and then separated by a space, like this:
"One two three four five" "One two three four five six seven" "One two three four five"

Ungolfed
    class P
{
    static void Main(string[]s)
    {
        var v=""; //Short way to make a string
        foreach(var c in s) //loop through all sentences
            v += c.Split(' ').Length; //split on space and append the array size as string
        );
        System.Console.WriteLine(v == "575"); //print the result!
    }
}

Please note this is my first attempt on golfing ever, let me know if anything is against the rules. Also feel free to point out things that makes this golf even shorter!

Doesn't look like there is anything illegal here, and it's refreshing to see a complete program submitted ;) Few standard tricks: you don't need the space   in string[] s, you can often save bytes by adding a using System; clause, but in this case you don't need to as it's much cheaper to use a foreach loop instead of Array.ForEach: foreach(var c in s)v+=c.Split(' ').Length;

@VisualMelon Wow, that's some useful tricks right there. Thanks alot! I'll update my answer :)

I don't think there's any need to print the linebreak, so you can just use Write.

Actually, instructions say "Other boolean return values, such as 1 and 0, are acceptable." -- so you can just return an exit code, dropping the print entirely. Added bonus, int Main is shorter than void Main.

Scala, 34 bytes
_.map(_ split " "size)==Seq(5,7,5)

Usage:
val f:(Seq[String]=>Boolean)=_.map(_ split " "size)==Seq(5,7,5)
println(f(Seq("The man in the suit", "is the same man from the store.", "He is a cool guy.")))

Ungolfed:
array=>array.map(line=>line.split(" ").size)==Seq(5,7,5)

Explanation:
 _.map(               //map each line in the argument
     _ split " "size  //  to the number of parts when the line is splitted at spaces
 ) == Seq(5,7,5)      //compare that to a sequence of 5, 7, and 5

C, 114 113 108 bytes
n,i,r,c;f(){n=i=r=1;while(n<4){c=getchar();c-32?c-10?1:++n%2?i-7?(r=0):(i=1):i-5?(r=0):(i=1):++i;}return r;}

CJam, 15 bytes
5 7 5]qN/Sf/:,=

Try it online!
Explanation
5 7 5]           The array [5, 7, 5]
      q          Read all input
       N/        Split on newlines
         Sf/     Split each line on spaces
            :,   Get the length of each line (in words)
              =  Check if the two arrays are equal

05AB1E, 9 bytes
εð¢}ƵĆ7вQ

Try it online!
εð¢}ƵĆ7вQ  # full program
        Q  # is...
  ¢        # the list of the number of..
 ð         # spaces...
  ¢        # in...
           # (implicit) current element in...
ε          # for each element in...
           # implicit input...
        Q  # equal to...
       в   # the list of the base...
      7    # literal...
       в   # digits of...
    ƵĆ     # 242...
        Q  # ?
   }       # end map
           # implicit output

Thunno 2, 7 bytes
Oḷ575d⁼

Try it online!
Explanation
Oḷ575d⁼  # Implicit input
O        # Split each line on spaces
 ḷ       # Get the length of each inner list
      ⁼  # And check if it's exactly equal to
  575d   # The list [5,7,5]
         # Implicit output