|
|
@@ -0,0 +1,80 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace App\Commands; |
|
|
|
|
|
|
|
use Illuminate\Console\Scheduling\Schedule; |
|
|
|
use LaravelZero\Framework\Commands\Command; |
|
|
|
|
|
|
|
class Pascal extends Command |
|
|
|
{ |
|
|
|
/** |
|
|
|
* The signature of the command. |
|
|
|
* |
|
|
|
* @var string |
|
|
|
*/ |
|
|
|
protected $signature = 'pascal'; |
|
|
|
|
|
|
|
/** |
|
|
|
* The description of the command. |
|
|
|
* |
|
|
|
* @var string |
|
|
|
*/ |
|
|
|
protected $description = 'Comando que describe el proceso de pascal'; |
|
|
|
|
|
|
|
/** |
|
|
|
* Execute the console command. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function handle() |
|
|
|
{ |
|
|
|
function generarPiramidePascal($filas) { |
|
|
|
$triangulo = array(); |
|
|
|
|
|
|
|
for ($i = 0; $i < $filas; $i++) { |
|
|
|
$triangulo[$i] = array(); |
|
|
|
$triangulo[$i][0] = 1; |
|
|
|
|
|
|
|
for ($gama = 1; $gama < $i; $gama++) { |
|
|
|
$triangulo[$i][$gama] = $triangulo[$i-1][$gama-1] + $triangulo[$i-1][$gama]; |
|
|
|
} |
|
|
|
|
|
|
|
$triangulo[$i][$i] = 1; |
|
|
|
} |
|
|
|
|
|
|
|
return $triangulo; |
|
|
|
} |
|
|
|
|
|
|
|
function mostrarPiramidePascal($triangulo) { |
|
|
|
$filas = count($triangulo); |
|
|
|
|
|
|
|
for ($i = 0; $i < $filas; $i++) { |
|
|
|
$espacios = str_repeat(" ", $filas - $i); |
|
|
|
|
|
|
|
echo $espacios; |
|
|
|
|
|
|
|
for ($gama = 0; $gama <= $i; $gama++) { |
|
|
|
echo $triangulo[$i][$gama] . " "; |
|
|
|
} |
|
|
|
|
|
|
|
echo "\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$numeroFilas = 10; |
|
|
|
$piramide = generarPiramidePascal($numeroFilas); |
|
|
|
mostrarPiramidePascal($piramide); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Define the command's schedule. |
|
|
|
* |
|
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule |
|
|
|
* @return void |
|
|
|
*/ |
|
|
|
public function schedule(Schedule $schedule): void |
|
|
|
{ |
|
|
|
// $schedule->command(static::class)->everyMinute(); |
|
|
|
} |
|
|
|
} |