@@ -0,0 +1,51 @@ | |||||
<?php | |||||
namespace App\Commands; | |||||
use Illuminate\Console\Scheduling\Schedule; | |||||
use LaravelZero\Framework\Commands\Command; | |||||
class Factorial extends Command | |||||
{ | |||||
/** | |||||
* The signature of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $signature = 'factorial'; | |||||
/** | |||||
* The description of the command. | |||||
* | |||||
* @var string | |||||
*/ | |||||
protected $description = 'este comando es para calcular el factorial de un numero'; | |||||
/** | |||||
* Execute the console command. | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function handle() | |||||
{ | |||||
$num=10; | |||||
$fact=1; | |||||
for ($i = $num; $i > 0; $i--) | |||||
{ | |||||
$fact= $fact * $i; | |||||
} | |||||
echo "El numero factorial es el siguiente = ".$fact; | |||||
} | |||||
/** | |||||
* Define the command's schedule. | |||||
* | |||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule | |||||
* @return void | |||||
*/ | |||||
public function schedule(Schedule $schedule): void | |||||
{ | |||||
// $schedule->command(static::class)->everyMinute(); | |||||
} | |||||
} |
@@ -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(); | |||||
} | |||||
} |
@@ -47,5 +47,5 @@ | |||||
}, | }, | ||||
"minimum-stability": "stable", | "minimum-stability": "stable", | ||||
"prefer-stable": true, | "prefer-stable": true, | ||||
"bin": ["application"] | |||||
"bin": ["ejercicios"] | |||||
} | } |
@@ -13,7 +13,7 @@ return [ | |||||
| | | | ||||
*/ | */ | ||||
'name' => 'Application', | |||||
'name' => 'Ejercicios', | |||||
/* | /* | ||||
|-------------------------------------------------------------------------- | |-------------------------------------------------------------------------- | ||||