summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-05-16 17:19:31 +0200
committerSanto Cariotti <sancn@live.com>2017-05-16 17:19:31 +0200
commit18022d73c1c3f86651e55b4ecf22d6f357c53d75 (patch)
treef249c45428e98949c1fccf5ec1c8c2f54fc4b3b6
parenta945361789d3bf06475950803a64fb31180ce379 (diff)
modified somme.cpp and added somme.py
-rw-r--r--cpp/somme.cpp12
1 files changed, 2 insertions, 10 deletions
diff --git a/cpp/somme.cpp b/cpp/somme.cpp
index c112e8f..240af3f 100644
--- a/cpp/somme.cpp
+++ b/cpp/somme.cpp
@@ -8,12 +8,7 @@ output: 1
int sequenza(int n, bool pollatz, int tCollatz = -1)
{
- int m, tot = 1;
-
- if(pollatz)
- m = 5;
- else
- m = 3;
+ int m = ((pollatz) ? 5 : 3), tot = 1;
auto pari = [] (int n) {
return ((n % 2) == 0) ? true : false;
@@ -21,10 +16,7 @@ int sequenza(int n, bool pollatz, int tCollatz = -1)
while(n != 1) {
- if(pari(n))
- n /= 2;
- else
- n = n*m+1;
+ n = (pari(n)) ? n/2 : n*m+1;
tot++;