Exercices complémentaires
Exercices complémentaires
Advent of Code
Exercism
- opérateurs arithmétiques et boucles
- Chaines de caractères
- Tableaux
- Chaines et tableaux
À quoi sert ce programme ?
Dites pour chaque programme ce qu'il fait et à quoi il sert.
function process_data($a, $b) {
$c = $a + $b;
return $c;
}
$first_val = 5;
$second_val = 10;
$result = process_data($first_val, $second_val);
echo $result;
function calculate_values($input_array) {
$output_array = [];
$counter = 0;
foreach($input_array as $value) {
$output_array[$counter] = $value * 2;
$counter++;
}
return $output_array;
}
function organize_data($input_array) {
sort($input_array);
return $input_array;
}
$original_data = [5, 2, 8, 1, 9];
$processed_data = calculate_values($original_data);
$organized_data = organize_data($processed_data);
print_r($organized_data);
function a($b) {
$c = count($b);
for ($d = 0; $d < $c / 2; $d++) {
$e = $b[$d];
$b[$d] = $b[$c - $d - 1];
$b[$c - $d - 1] = $e;
}
return $b;
}
$f = [1, 2, 3, 4, 5];
$g = a($f);
print_r($g);
function a($b) {
$c = str_split($b);
$d = array_count_values($c);
arsort($d);
return key($d);
}
$e = "hello world";
$f = a($e);
echo $f;
function a($b) {
$c = 0;
foreach ($b as $d) {
$c += $d;
}
return $c;
}
$e = [1, 2, 3, 4, 5];
$f = a($e);
echo $f;
function a($b) {
$c = [];
$d = explode(" ", $b);
foreach ($d as $e) {
if (strlen($e) > 3) {
$f = str_split($e);
$f[3] = "*";
$g = implode("", $f);
$c[] = $g;
} else {
$c[] = $e;
}
}
return implode(" ", $c);
}
$h = "Hello my name is John";
$i = a($h);
echo $i;
function a($b) {
for ($i = 0; $i < count($b); $i++) {
$temp = $b[$i];
$j = $i-1;
while($j >= 0 && $b[$j] > $temp) {
$b[$j+1] = $b[$j];
$j--;
}
$b[$j+1] = $temp;
}
return $b;
}
$c = [3, 1, 4, 1, 5, 9, 2, 6, 5];
$d = a($c);
print_r($d);
function a($b) {
for ($i = 0; $i < count($b) - 1; $i++) {
$min = $i;
for ($j = $i + 1; $j < count($b); $j++) {
if ($b[$j] < $b[$min]) {
$min = $j;
}
}
if ($i != $min) {
$temp = $b[$i];
$b[$i] = $b[$min];
$b[$min] = $temp;
}
}
return $b;
}
$c = [4, 9, 5, 3, 9, 2, 2, 1];
$d = a($c);
print_r($d);
