initial commit
This commit is contained in:
55
bash/pangram/README.md
Normal file
55
bash/pangram/README.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Pangram
|
||||
|
||||
Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma,
|
||||
"every letter") is a sentence using every letter of the alphabet at least once.
|
||||
The best known English pangram is:
|
||||
> The quick brown fox jumps over the lazy dog.
|
||||
|
||||
The alphabet used consists of ASCII letters `a` to `z`, inclusive, and is case
|
||||
insensitive. Input will not contain non-ASCII symbols.
|
||||
|
||||
|
||||
Run the tests with:
|
||||
|
||||
```bash
|
||||
bats pangram_test.sh
|
||||
```
|
||||
|
||||
After the first test(s) pass, continue by commenting out or removing the
|
||||
`[[ $BATS_RUN_SKIPPED == true ]] || skip`
|
||||
annotations prepending other tests.
|
||||
|
||||
To run all tests, including the ones with `skip` annotations, run:
|
||||
|
||||
```bash
|
||||
BATS_RUN_SKIPPED=true bats pangram_test.sh
|
||||
```
|
||||
|
||||
## Source
|
||||
|
||||
Wikipedia [https://en.wikipedia.org/wiki/Pangram](https://en.wikipedia.org/wiki/Pangram)
|
||||
|
||||
|
||||
## External utilities
|
||||
`Bash` is a language to write "scripts" -- programs that can call
|
||||
external tools, such as
|
||||
[`sed`](https://www.gnu.org/software/sed/),
|
||||
[`awk`](https://www.gnu.org/software/gawk/),
|
||||
[`date`](https://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html)
|
||||
and even programs written in other programming languages,
|
||||
like [`Python`](https://www.python.org/).
|
||||
This track does not restrict the usage of these utilities, and as long
|
||||
as your solution is portable between systems and does not require
|
||||
installation of third party applications, feel free to use them to solve
|
||||
the exercise.
|
||||
|
||||
For an extra challenge, if you would like to have a better understanding
|
||||
of the language, try to re-implement the solution in pure `Bash`,
|
||||
without using any external tools. Note that there are some types of
|
||||
problems that bash cannot solve, such as performing floating point
|
||||
arithmetic and manipulating dates: for those, you must call out to an
|
||||
external tool.
|
||||
|
||||
## Submitting Incomplete Solutions
|
||||
It's possible to submit an incomplete solution so you can see how others
|
||||
have completed the exercise.
|
49
bash/pangram/pangram.sh
Executable file
49
bash/pangram/pangram.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# set to mask to enable logs. 0: none, 255: all
|
||||
# (( debug=2#00001111 ))
|
||||
(( debug=2#00000000 ))
|
||||
|
||||
# $1: log level (mask), then strings to display.
|
||||
debug () {
|
||||
(( debug & "$1" )) && shift && echo "${@}" >&2
|
||||
}
|
||||
|
||||
usage () {
|
||||
echo "usage: ./pangram.sh <string> [...]" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# basic args checks: at least 1 arg
|
||||
(( $# )) || usage
|
||||
|
||||
# We will accept mutiple args here: "a" "b" is equivalent to "ab".
|
||||
# get args in one string, change it to lower case.
|
||||
IFS="" # not really needed
|
||||
string="${*,,}"
|
||||
debug 1 "string=$string"
|
||||
|
||||
# empty string
|
||||
if (( ! ${#string} )); then
|
||||
debug 2 "empty string"
|
||||
result=false
|
||||
else
|
||||
result=true
|
||||
|
||||
# loop on all characters, from a to z. We need to check each one.
|
||||
for c in {a..z} ; do
|
||||
[[ ! ${string} =~ "$c" ]] && result=false && break
|
||||
done
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
exit 0
|
||||
|
||||
# emacs/vim settings.
|
||||
# Local Variables:
|
||||
# sh-basic-offset: 4
|
||||
# indent-tabs-mode: nil
|
||||
# comment-column: 60
|
||||
# fill-column: 80
|
||||
# End:
|
||||
# vim: set tabstop=4 expandtab:
|
Reference in New Issue
Block a user