Add a couple of questions
This commit is contained in:
20
exercises/shell/solutions/factors.md
Normal file
20
exercises/shell/solutions/factors.md
Normal file
@ -0,0 +1,20 @@
|
||||
## Shell Scripting - Factors
|
||||
|
||||
### Objectives
|
||||
|
||||
Write a script that when given a number, will:
|
||||
|
||||
* Check if the number has 2 as factor, if yes it will print "one factor"
|
||||
* Check if the number has 3 as factor, if yes it will print "one factor...actually two!"
|
||||
* If none of them (2 and 3) is a factor, print the number itself
|
||||
|
||||
### Solution
|
||||
|
||||
```
|
||||
#!/usr/bin/env bash
|
||||
|
||||
(( $1 % 2 )) || res="one factor"
|
||||
(( $1 % 3 )) || res+="...actually two!"
|
||||
|
||||
echo ${res:-$1}
|
||||
```
|
Reference in New Issue
Block a user