Add script primes.sh to 1985/august for fun
The inspiration of the script is based on a 'try' command I added to the README.md a while back to have more fun with the entry. The difference is that it allows you to specify the number of lines to print (or up to the number of lines). There might be some misleading output in a way but this is a mystery for users to solve.
This commit is contained in:
1 parent
90c80b3e69
commit
c31796a55c
3 files changed
+43
-5
No files matched your search
@@ -21,13 +21,16 @@ make all
|
||||
./august | head -n 10
|
||||
```
|
||||
|
||||
If you have the `primes(6)` tool (sometimes part of BSD Games) you can see
|
||||
what of the output in the first `N` (say `15`) lines are primes:
|
||||
If you have the `primes(6)` tool (sometimes part of [BSD
|
||||
Games](https://github.com/vattam/BSDGames)) you can see
|
||||
what of the output in the first `N` (say `15` or `25`) lines are primes:
|
||||
|
||||
```sh
|
||||
while read -r n ; do primes "$n" $((n + 1)) ; done < <((./august | head -n 15 ))
|
||||
./primes.sh # 15
|
||||
./primes.sh 25
|
||||
```
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
An interesting use of a recursive call to `main()`. Compile and execute
|
||||
@@ -38,6 +41,9 @@ If you let it, the program will continue to print a numerical sequence (can you
|
||||
guess in what base it is printed by looking at the code?) until you run out of
|
||||
memory or until they sell your computer, whichever comes first.
|
||||
|
||||
If you use the [primes.sh](primes.sh) script can you figure out if there's
|
||||
anything funny going on with the output?
|
||||
|
||||
## Author's remarks:
|
||||
|
||||
No remarks were provided by the author.
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
make everything || exit 1
|
||||
|
||||
PRIMES=$(type -P primes)
|
||||
|
||||
COUNT=15
|
||||
if [[ "$#" -ge 1 ]]; then
|
||||
COUNT="$1"
|
||||
if ! [[ $COUNT =~ ^[0-9]+$ ]] ; then
|
||||
echo "not a number: $COUNT" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "$PRIMES" ]]; then
|
||||
while read -r n ; do primes "$n" $((n + 1)) ; done < <((./august | head -n "$COUNT" ))
|
||||
else
|
||||
echo "primes not installed" 1>&2
|
||||
echo "See the following GitHub repo:" 1>&2
|
||||
echo "" 1>&2
|
||||
echo " https://github.com/vattam/BSDGames"
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user