Skip to content

Instantly share code, notes, and snippets.

@ashumeow
Created July 12, 2023 09:31
Show Gist options
  • Save ashumeow/022ec30ef21ce547ff0c05d2436b966d to your computer and use it in GitHub Desktop.
Save ashumeow/022ec30ef21ce547ff0c05d2436b966d to your computer and use it in GitHub Desktop.
codechef problem
<?php
// problem
// Alice adds the numbers to list in the following order
// [1,4,7,10,2,5,8,3,6,9]
// The 7th number in the list is 8
// solution
$b=[1,4,7,10,2,5,8,3,6,9];
$n = intval(trim(fgets(STDIN)));
$arr_temp = rtrim(fgets(STDIN));
$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));
$c=count($arr)-1;
$a=0;
if($c<count($b)) {
$d=$arr[$c]-1;
$a=$b[$d];
}
echo $a;
// 8
//
// ashumeow
//
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment