user
The general idea behind an executable library is to create a library
that when used as a library does one thing;
but has the ability to be run directly via command line.
Thus the API comes with a CLI in the very same source code file.

**Task detail**

* Create a library/module/dll/shared object/... for a programming language that contains a function/method called hailstone that is a function taking a positive integer and returns the Hailstone sequence for that number.

* The library, when executed directly should satisfy the remaining requirements of the Hailstone sequence task:

:   :   2. Use the routine to show that the hailstone sequence for the number 27 has 112 elements starting with 27, 82, 41, 124 and ending with 8, 4, 2, 1
    :   3. Show the number less than 100,000 which has the longest hailstone sequence together with that sequence's length.

* Create a second executable to calculate the following:
  + Use the library's hailstone function, in the standard manner, (or document how this use deviates from standard use of a library), together with extra code in this executable, to find the hailstone length returned most often for 1 ≤ n < 100,000.

* Explain any extra setup/run steps needed to complete the task.

**Notes:**

* It is assumed that for a language that overwhelmingly ships in a compiled form, such as C, the library must also be an executable and the compiled user of that library is to do so without changing the compiled library. I.e. the compile tool-chain is assumed *not* to be present in the runtime environment.
* Interpreters are present in the runtime environment.
assistant
(formerly Perl 6)
The library can be written as a module:

```
module Hailstone {
    our sub hailstone($n) is export {
	$n, { $_ %% 2 ?? $_ div 2 !! $_ * 3 + 1 } ... 1
    }
}

sub MAIN {
    say "hailstone(27) = {.[^4]} [...] {.[*-4 .. *-1]}" given Hailstone::hailstone 27;
}

```

It can be run with:

```
$ raku Hailstone.rakumod

```

Output:

```
hailstone(27) = 27 82 41 124 [...] 8 4 2 1
```

It can then be used with a program such as:

```
use Hailstone;
my %score;
(1 .. 100_000).race.map: { %score{hailstone($_).elems}++ };
say "Most common length is {.key}, occurring {.value} times." given max :by(*.value), %score;

```

Called with a command line as:

```
$ RAKULIB=. raku test-hailstone.raku
```

The environment variable RAKULIB might be necessary if the file Hailstone.rakumod is not in the standard library path for Raku.