Commit 64c1eaf42c93b48c5053a2bbbd00f3073cf07e28

Authored by Imanol-Mikel Barba Sabariego
2 parents 16765a7a ab518084

Added solution for problem 17

Showing 3 changed files with 29 additions and 47 deletions
1 -import sys;  
2 -  
3 -def factorial(num):  
4 - result = 1;  
5 - for x in range (num,1,-1):  
6 - result *= x;  
7 - return result;  
8 -  
9 -def binomial(m,n):  
10 - return factorial(m)/(factorial(n)*factorial(m-n));  
11 -  
12 -dimension = int(sys.argv[1]);  
13 -print "Result is: " + str(binomial(dimension*2,dimension)); 1 +#!/usr/bin/python
  2 +
  3 +import sys;
  4 +
  5 +def factorial(num):
  6 + result = 1;
  7 + for x in range (num,1,-1):
  8 + result *= x;
  9 + return result;
  10 +
  11 +def binomial(m,n):
  12 + return factorial(m)/(factorial(n)*factorial(m-n));
  13 +
  14 +dimension = int(sys.argv[1]);
  15 +print "Result is: " + str(binomial(dimension*2,dimension));
1 -import math;  
2 -import sys;  
3 -  
4 -def sumDigits(num):  
5 - sum = 0;  
6 - for i in range (0,len(num)):  
7 - sum += int(num[i]);  
8 -  
9 - return sum;  
10 -  
11 -  
12 -print "Result is: " + str(sumDigits(str(int(math.pow(int(sys.argv[1]),int(sys.argv[2])))))) 1 +#!/usr/bin/python
  2 +
  3 +import math;
  4 +import sys;
  5 +
  6 +def sumDigits(num):
  7 + sum = 0;
  8 + for i in range (0,len(num)):
  9 + sum += int(num[i]);
  10 +
  11 + return sum;
  12 +
  13 +
  14 +print "Result is: " + str(sumDigits(str(int(math.pow(int(sys.argv[1]),int(sys.argv[2]))))))
17.py deleted
1 -#!/usr/bin/python  
2 -  
3 -S = [0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8]  
4 -D = [0,3,6,6,5,5,5,7,6,6]  
5 -H = 7  
6 -T = 8  
7 -  
8 -total = 0  
9 -for i in range(1,1000):  
10 - c = i % 10 # singles digit  
11 - b = ((i % 100) - c) / 10 # tens digit  
12 - a = ((i % 1000) - (b * 10) - c) / 100 # hundreds digit  
13 -  
14 - if a != 0:  
15 - total += S[a] + H # "S[a] hundred  
16 - if b != 0 or c != 0: total += 3 # "and"  
17 - if b == 0 or b == 1: total += S[b * 10 + c]  
18 - else: total += D[b] + S[c]  
19 -  
20 -total += S[1] + T  
21 -  
22 -print "Result is: " + str(total)