Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #43 - PHP #5617

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Retos/Reto #43 - SIMULADOR DE CLIMA [Fácil]/php/mrf1989.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

function predecir_clima(int $dias, int $tmp_inicial, int $p_lluvia_inicial): void
{
$tmp = $tmp_inicial;
$p_lluvia = $p_lluvia_inicial;
$dias_lluviosos = 0;
$tmp_diarias = array($tmp_inicial);

for ($i = 1; $i <= $dias; $i++) {
echo "Día {$i}\n";
echo "La probabilidad de lluvia es del {$p_lluvia}%\n";

$cambio = rand(0, 100);

if ($cambio <= 10) {
$subida = rand(0, 1);

if ($subida) {
$tmp += 2;
} else {
$tmp -= 2;
}
}

echo "La temperatura es de {$tmp} grados.\n";
array_push($tmp_diarias, $tmp);

if ($p_lluvia == 100) {
$dias_lluviosos++;
}


if ($tmp > 25) {
$p_lluvia += 20;
if ($p_lluvia > 100) {
$p_lluvia = 100;
$tmp -= 1;
}
} else if ($tmp < 5) {
$p_lluvia -= 20;
if ($p_lluvia < 0) {
$p_lluvia = 0;
}
}
}

echo "RESUMEN:\n";
echo "- Días lluviosos: {$dias_lluviosos}.\n";
echo "Temperatura máxima: " . max($tmp_diarias) . " grados.\n";
echo "Tempratura mínima: " . min($tmp_diarias) . " grados.\n";
}

predecir_clima(24, 24, 20);