CarlosLabs
Hackerrank Challenges - Viral advertising
(CM) I love this solution. Very compact and clean.
#!/bin/python3 import math import os import random import re import sys # Rank: 296848|Points: 431/475 # Complete the viralAdvertising function below. def viralAdvertising(n): va = [2] for i in range(n-1): va.append(int(3*va[i]/2)) return(sum(va)) if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') n = int(input()) result = viralAdvertising(n) fptr.write(str(result) + '\n') fptr.close()