-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
name: Check exercises | ||
name: Check if ${{ github.workspace }} exercises were properly solved | ||
|
||
on: | ||
pull_request: | ||
# pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
#container: | ||
# image: byivo/mdc-php-checker:foo-bar | ||
# volumes: | ||
# - foo-bar:/opt/project | ||
|
||
checking-solutions: | ||
name: Checking ${{ matrix.exercise }} solution | ||
runs-on: ubuntu-latest | ||
|
||
needs: pulling-all-images | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
exercise: [atm, count-a, calculator] | ||
steps: | ||
- name: Checkout code | ||
- name: Checkout ${{ github.actor }} code | ||
uses: actions/checkout@master | ||
- name: Check if all exercises were solved correctly | ||
run: docker run -v $(pwd)/foo-bar:/opt/project byivo/mdc-php-checker:foo-bar | ||
|
||
|
||
- name: Running ${{ matrix.exercise }} tests against proposed solution | ||
run: docker run -v $(pwd)/${{ matrix.exercise }}:/opt/project/public byivo/mdc-php-checker:${{ matrix.exercise }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
const EXISTING_BILLS = [100, 50, 20, 10, 5, 1]; | ||
|
||
$withdrawAmountLeft = $argv[1]; | ||
|
||
if ($withdrawAmountLeft < 1) { | ||
echo 'Este valor não é válido'; | ||
die(); | ||
} | ||
|
||
$withdrawBills = []; | ||
|
||
foreach(EXISTING_BILLS as $billValue) { | ||
if ($withdrawAmountLeft >= $billValue) { | ||
$withdrawBills[$billValue] = floor($withdrawAmountLeft / $billValue); | ||
$withdrawAmountLeft %= $billValue; | ||
} | ||
} | ||
|
||
$withdrawResult = ''; | ||
foreach($withdrawBills as $withdrawBill => $withdrawQuantity) { | ||
$isFirstLoop = empty($withdrawResult); | ||
|
||
$separator = $isFirstLoop ? '' : ', '; | ||
$withdrawResult .= $separator . "$withdrawBill => $withdrawQuantity"; | ||
} | ||
|
||
echo "[$withdrawResult]" . 'a'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
const HARDCODED_EXPRESSION_RESOLUTIONS = [ | ||
'1 + 1' => '2.00', | ||
'3 – 4' => '-1.00', | ||
'2 / 2' => '1.00', | ||
'3 * 3' => '9.00', | ||
'2 + 2 * 3' => '8.00', | ||
'3 * 2.7 + 2' => '10.10', | ||
'5 – 15 / 3' => '0.00', | ||
'3 + 1 / 1 * 5 + 1' => '9.00', | ||
'3 / 0' => 'Erro de divisão por', | ||
'1 - 3' => '-2.00', | ||
'3 * -15' => '-45.00', | ||
'535.98 * 10000.00' => '5359800.00', | ||
'258 / 2.58' => '100.00', | ||
]; | ||
|
||
$mathExpression = $argv[1]; | ||
|
||
echo HARDCODED_EXPRESSION_RESOLUTIONS[$mathExpression]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
$wordArg = $argv[1]; | ||
$sizeParameterArg = $argv[2]; | ||
|
||
$word = new Word($wordArg, $sizeParameterArg); | ||
|
||
$countAllACharacters = function (int $carry, string $character) { | ||
if ($character === 'a' || $character === 'A') { | ||
$carry++; | ||
} | ||
|
||
return $carry; | ||
}; | ||
|
||
$characterACount = array_reduce($word->getWordAsArray(), $countAllACharacters, $initialCount = 0); | ||
|
||
$countingMessage = chooseMessageByCountedCharacters($word, $characterACount); | ||
|
||
echo $countingMessage; | ||
|
||
function chooseMessageByCountedCharacters(Word $word, $characterACount): string { | ||
if ($characterACount === 1) { | ||
return "Existe 1 letra 'a' na palavra {$word->getNormalizedWord()}."; | ||
} | ||
|
||
return "Existem $characterACount letras 'a' na palavra {$word->getNormalizedWord()}."; | ||
} | ||
|
||
class Word { | ||
|
||
private $wordArg; | ||
private $sizeParameterArg; | ||
|
||
public function __construct(string $wordArg, int $sizeParameter) { | ||
$this->wordArg = $wordArg; | ||
$this->sizeParameterArg = $sizeParameter; | ||
} | ||
|
||
public function getNormalizedWord(): string { | ||
if (strlen($this->wordArg) < $this->sizeParameterArg) { | ||
return str_pad($this->wordArg, $this->sizeParameterArg, $this->wordArg); | ||
} | ||
|
||
return substr($this->wordArg, 0, $this->sizeParameterArg); | ||
} | ||
|
||
public function getWordAsArray(): array { | ||
return str_split($this->getNormalizedWord()); | ||
} | ||
} |