4
Consider that there are two moments in time, represented in the standard format (HH:mm:ss).
And consider that a point of interest is any moment that is represented by at most two different digits ( Ex: 12:12:11 or 15:15:51 )
If I wanted to go from one moment to the next telling the points of interest that exist between them, how would I implement this in PHP?
I thought about nesting three loops for one to count the hours, one to count the minutes and one to count the seconds.
Ex:
$S = '12:12:00';
$T = '12:12:15';
$arrS = explode(':', $S);
$arrT = explode(':', $T);
//Horas do primeiro momento.
$Sh = $arrS[0];
//Minutos do primeiro momento.
$Sm = $arrS[1];
//Segundos do primeiro momento.
$Ss = $arrS[2];
//Horas do segundo momento.
$Th = $arrT[0];
//Minutos do segundo momento.
$Tm = $arrT[1];
//Segundos do segundo momento.
$Ts = $arrT[2];
for($i = $Sh; $i <= $Th; $i++){
//Conta as horas
for($j = $Sm; $j <= $Tm; $j++){
//Conta os minutos
for($k = $Ss; $k <= $Ts; $k++){
//Conta os segundos
}
}
}
But I confess that from here I don’t know what else to do :/
Does anyone have any idea?
What would be points of interest?
– rray
What do you mean "at most two different digits"?
– Rodrigo Rigotti
Digits are any number from 0 to 9. Point of interest is any moment that is represented by at most two different digits. For example, at the moment 12:12:12 there are only two digits. 1 and 2
– Cesar de Barros
It’s easier for you to try to explain why you want this algorithm than how it should be.
– juniorb2ss
It’s a logical challenge I couldn’t solve.
– Cesar de Barros