Programerat / programerat.github.io

MIT License
2 stars 0 forks source link

Gjej sipërfaqen e shumëkëndëshit. - Programerat #22

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Gjej sipërfaqen e shumëkëndëshit. - Programerat

https://programerat.github.io/detyrat/problemi-gjej-siperfaqen-e-shumekendeshit

gurillaz commented 2 years ago

Me pak trial & error 🙂

function zgjidhja(int $n): int {

    $rezultati = 0;

    for($i = 1; $i<=($n*2)-1; $i=$i+2){

        $rezultati += $i==($n*2)-1 ?  $i :  $i*2;

    }

    return $rezultati; 

}
didslm commented 2 years ago

Brravo @gurillaz, mundohu me thjeshtu duke perdor një metode ekstra.

arlinndi9 commented 2 years ago
   def shumekendesh(n):
       if n == 1:
             return 1
       return n ** 2 + (n - 1) ** 2
didslm commented 2 years ago

@arlinndi9 Bravo!