Se colocaran ejercios para practicar de codigobit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 line
1.8 KiB

  1. <?php
  2. namespace App\Commands;
  3. use Illuminate\Console\Scheduling\Schedule;
  4. use LaravelZero\Framework\Commands\Command;
  5. class Pascal extends Command
  6. {
  7. /**
  8. * The signature of the command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'pascal {filas}';
  13. /**
  14. * The description of the command.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Comando que describe el proceso de pascal';
  19. /**
  20. * Execute the console command.
  21. *
  22. * @return mixed
  23. */
  24. public function handle()
  25. {
  26. function generarPiramidePascal($filas) {
  27. $triangulo = array();
  28. for ($i = 0; $i < $filas; $i++) {
  29. $triangulo[$i] = array();
  30. $triangulo[$i][0] = 1;
  31. for ($gama = 1; $gama < $i; $gama++) {
  32. $triangulo[$i][$gama] = $triangulo[$i-1][$gama-1] + $triangulo[$i-1][$gama];
  33. }
  34. $triangulo[$i][$i] = 1;
  35. }
  36. return $triangulo;
  37. }
  38. function mostrarPiramidePascal($triangulo) {
  39. $filas = count($triangulo);
  40. for ($i = 0; $i < $filas; $i++) {
  41. $espacios = str_repeat(" ", $filas - $i);
  42. echo $espacios;
  43. for ($gama = 0; $gama <= $i; $gama++) {
  44. echo $triangulo[$i][$gama] . " ";
  45. }
  46. echo "\n";
  47. }
  48. }
  49. $numeroFilas = $this->argument('filas');
  50. $piramide = generarPiramidePascal($numeroFilas);
  51. mostrarPiramidePascal($piramide);
  52. }
  53. /**
  54. * Define the command's schedule.
  55. *
  56. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  57. * @return void
  58. */
  59. public function schedule(Schedule $schedule): void
  60. {
  61. // $schedule->command(static::class)->everyMinute();
  62. }
  63. }