Commits

ronald martinez committed 7c2fec3

fles

Comments (0)

Files changed (10)

-import os
 import sys
-import time
-import random
 
-
-def problem_01():
-
-    l = []
-
-    for x in range(100):
-
-        while True:
-            n = random.randint(1, 10000)
-
-            if n not in l:
-                l.append(n)
-                break
-
-    max = 0
-    min = l[0]
-
-    for x in l:
-        max = x if x > max else max
-        min = x if x < min else min
-
-    return {'values': l, 'max': max, 'min': min}
-
-
-def problem_02():
-    tot = 0
-
-    for x in range(1, 1000):
-        if x % 3 == 0 and x % 5 == 0:
-            tot += x
-
-    return tot
-
-
-def problem_03(n1, n2):
-
-    n1 = int(n1)
-    n2 = int(n2)
-
-    if n1 < 0:
-        n1 = n1 - (n1 * 2)
-
-    if n2 < 0:
-        n2 = n2 - (n2 * 2)
-
-    old_n1 = n1
-
-    if n2 > n1:
-        n1 = n2
-        n2 = old_n1
-
-    if n1 == 0 or n2 == 0:
-        mmc = n1
-    elif n1 == 0 and n2 > 0:
-        mmc = n2
-    elif n1 > 0 and n2 == 0:
-        mmc = n1
-    else:
-
-        res = 0
-
-        while True:
-
-            n1 -= n2
-
-            if n1 > 0:
-                res = n1
-
-            elif n1 == 0:
-                mmc = n2
-                break
-            else:
-                n1 = n2
-                n2 = res
-
-    return mmc
-
-
-def problem_04():
-
-    placas = []
-
-    input = open('prefijos_placas.txt', 'r')
-    input = input.read().split('\n')[:-1]
-
-    for p in range(100):
-        while True:
-            code = input[random.randint(0, len(input) - 1)]
-            serie = random.randint(100, 999)
-            placa = '%s-%d' % (code, serie)
-
-            if placa not in placas:
-                placas.append(placa)
-                break
-
-    return placas
-
-
-def problem_06():
-
-    data = {}
-
-    words = open('alfabeto.txt', 'r')
-    words = words.read().split('\n')[:-1]
-
-    def find_words(value):
-
-        if not value:
-            return False
-
-        for x in value:
-            if not x in words:
-                return False
-
-        return True
-
-    input = open('rfc2616.txt', 'r')
-    input = input.read().split(' ')
-    input = [x for x in input if find_words(x)]
-
-    for x in input:
-
-        if not x in data:
-            data[x] = 1
-        else:
-            data[x] = data[x] + 1
-
-    new_data = {}
-
-    for x, y in data.items():
-        if y >= 100:
-            new_data[x] = y
-
-    return new_data
-
-
-def problem_07():
-
-    total = 1000
-    points = (50, 50, 50, 100, 100, 100, 150, 150, 150, 100)
-    n1 = random.randint(1, 101)
-
-    for x in points:
-
-        n2 = int(raw_input('Enter number:'))
-
-        if n1 == n2:
-            print total
-            break
-        else:
-
-            if n1 < n2:
-                print 'el numero es menor que %d' % n2
-            else:
-                print 'el numero es mayor que %d' % n2
-
-            total = total - x
-
-
-def problem_08():
-
-    input = open('matrix.txt', 'r')
-    input = input.read().split('\n')[:-1]
-
-    while True:
-
-        body = ''
-
-        for x in range(8):
-
-            chr = input[random.randint(0, len(input) - 1)]
-            body += '%s  ' % chr
-
-        sys.stdout.write(os.popen('clear').read())
-        print body
-        time.sleep(2)
-
-
-def problem_10():
-
-    input = open('hangman.txt', 'r')
-    input = input.read().split('\n')[:-1]
-
-    n = 8
-    chr = '*'
-
-    phase = ''
-    phase1 = input[random.randint(0, len(input) - 1)]
-    phase_original = phase1
-
-    #print 'phase_original: %s' % phase_original
-
-    while 0 < n:
-
-        n -= 1
-
-        if phase in phase1:
-            phase1 = phase1.replace(phase, chr * len(phase))
-
-        output = ''
-        for y, x in enumerate(phase1):
-
-            if x == chr:
-                output += phase_original[y]
-            elif x == ' ':
-                output += ' '
-            else:
-                output += chr
-
-        if output == phase_original:
-            print 'excelent'
-            break
-        else:
-            if n == 0:
-                print 'so bad'
-                break
-
-        print 'phase: %s' % output
-        phase = raw_input('Enter phase: ')
-        sys.stdout.write(os.popen('clear').read())
-
-
-def problem_09():
-
-    table = {
-        13: (
-                {'prefix': '4', 'type': 'visa', 'check': True},
-            ),
-        14: (
-                {'prefix': '300-305', 'type': 'dinners/carte', 'check': True},
-                {'prefix': '36', 'type': 'dinners/carte', 'check': True},
-                {'prefix': '38', 'type': 'dinners/carte', 'check': True},
-            ),
-        15: (
-                {'prefix': '34', 'type': 'amex', 'check': True},
-                {'prefix': '37', 'type': 'amex', 'check': True},
-                {'prefix': '2014', 'type': 'enroute', 'check': False},
-                {'prefix': '2149', 'type': 'enroute', 'check': False},
-                {'prefix': '2131', 'type': 'jcb', 'check': True},
-                {'prefix': '1800', 'type': 'jcb', 'check': True},
-            ),
-        16:  (
-                {'prefix': '51-55', 'type': 'mastercard', 'check': True},
-                {'prefix': '4', 'type': 'visa', 'check': True},
-                {'prefix': '6011', 'type': 'discover', 'check': True},
-                {'prefix': '3', 'type': 'jcb', 'check': True},
-            ),
-    }
-
-    def check_table(number):
-
-        data = table.get(len(number))
-
-        if data:
-
-            for x in data:
-
-                prefix = x.get('prefix')
-                type = x.get('type')
-                check = x.get('check')
-
-                if '-' in prefix:
-
-                    prefixs = prefix.split('-')
-                    prefixs = [str(x) for x in \
-                        range(int(prefixs[0]), int(prefixs[1]) + 1)]
-
-                    for p in prefixs:
-
-                        size = len(p)
-
-                        if number[:size] == p:
-
-                            if check:
-
-                                if check_primary_account(number[size:]):
-                                    return type
-                else:
-
-                    size = len(prefix)
-
-                    if number[:size] == prefix:
-
-                        if check:
-
-                            if check_primary_account(number[size:]):
-                                return type
-
-        return None
-
-    def check_primary_account(number):
-
-        n = len(number) - 1
-        i = 0
-        tot = 0
-        flat = False
-
-        while 0 <= n:
-
-            digit = int(number[n])
-
-            # if i % 2 == 1
-            if flat:
-                flat = False
-                tot += sum([int(x) for x in str(digit * 2)])
-            else:
-                flat = True
-                tot += digit
-
-            n -= 1
-            i += 1
-
-        return True if tot % 10 == 0 else False
-
-    input = open('tarjetas.txt', 'r')
-    input = input.read().split('\n')[:-1]
-
-    #number = '30249927398716' dinners
-    #print check_table(number)
-
-    for number in input:
-
-        type = check_table(number)
-
-        if type:
-            print 'card number %s: %s is valid' % (type, number)
+if __name__ == '__main__':
+
+    args = sys.argv
+
+    if len(args) == 2:
+
+        check = True
+        nro = args[1]
+
+        if nro == '01'
+            import problem01 as problem
+        elif nro == '02':
+            import problem02 as problem
+        elif nro == '03':
+            import problem03 as problem
+        elif nro == '04':
+            import problem04 as problem
+        elif nro == '06':
+            import problem06 as problem
+        elif nro == '07':
+            import problem07 as problem            
+        elif nro == '08':
+            import problem08 as problem
+        elif nro == '09':
+            import problem09 as problem
+        elif nro == '10':
+            import problem10 as problem
         else:
-            print 'card number: %s is not valid' % number
+            check = False
+            print 'Nro: %s is incorrect' % nro
 
-problem_09()
+        if check:
+            problem.run()
+import random
+
+
+def run():
+
+    l = []
+
+    for x in range(100):
+
+        while True:
+            n = random.randint(1, 10000)
+
+            if n not in l:
+                l.append(n)
+                break
+
+    max = 0
+    min = l[0]
+
+    for x in l:
+        max = x if x > max else max
+        min = x if x < min else min
+
+    print {'values': l, 'max': max, 'min': min}
+
+
+if __name__ == '__main__':
+
+    run()
+def run():
+    tot = 0
+
+    for x in range(1, 1000):
+        if x % 3 == 0 and x % 5 == 0:
+            tot += x
+
+    print tot
+
+if __name__ == '__main__':
+
+    run()
+def run(n1, n2):
+
+    n1  = int(n1)
+    n2 = int(n2)
+
+    if n1 < 0:
+        n1 = n1 - (n1 * 2)
+
+    if n2 < 0:
+        n2 = n2 - (n2 * 2)
+
+    old_n1 = n1
+
+    if n2 > n1:
+        n1 = n2
+        n2 = old_n1
+
+    if n1 == 0 or n2 == 0:
+        mmc = n1
+    elif n1 == 0 and n2 > 0:
+        mmc = n2
+    elif n1 > 0 and n2 == 0:
+        mmc = n1
+    else:
+
+        res = 0
+
+        while True:
+
+            n1 -= n2
+
+            if n1 > 0:
+                res = n1
+
+            elif n1 == 0:
+                mmc = n2
+                break
+            else:
+                n1 = n2
+                n2 = res
+
+    print mmc
+
+if __name__ == '__main__':
+
+    run()
+import random
+
+
+def run():
+
+    pla cas = []
+
+    input = open('prefijos_placas.txt', 'r')
+    input = input.read().split('\n')[:-1]
+
+    for p in range(100):
+
+        while True:
+            code = input[random.randint(0, len(input) - 1)]
+            serie = random.randint(100, 999)
+            placa = '%s-%d' % (code, serie)
+
+            if placa not in placas:
+                placas.append(placa)
+                break
+
+    print placas
+
+
+if __name__ == '__main__':
+
+    run()
+def server():
+
+    data =  {}
+
+    words = open('alfabeto.txt', 'r')
+    words = words.read().split('\n')[:-1]
+
+    def find_words(value):
+
+        if not value:
+            return False
+
+        for x in value:
+            if not x in words:
+                return False
+
+        return True
+
+    input = open('rfc2616.txt', 'r')
+    input = input.read().split(' ')
+    input = [x for x in input if find_words(x)]
+
+    for x in input:
+
+        if not x in data:
+            data[x] = 1
+        else:
+            data[x] = data[x] + 1
+
+    new_data = {}
+
+    for x, y in data.items():
+        if y >= 100:
+            new_data[x] = y
+
+    print new_data
+
+if __name__ == '__main__':
+
+    run()
+import random
+
+
+def run():
+
+    total = 1000
+    points = (50, 50, 50, 100, 100, 100, 150, 150, 150, 100)
+    n1 = random.randint(1, 101)
+
+    for x in points:
+
+        n2 = int(raw_input('Enter number:'))
+
+        if n1 == n2:
+            print total
+            break
+        else:
+
+            if n1 < n2:
+                print 'el numero es menor que %d' % n2
+            else:
+                print 'el numero es mayor que %d' % n2
+
+             total -= x
+
+    print total
+
+if __name__ == '__main__':
+
+    run()
+import os
+import sys
+import time
+import random
+
+
+def run():
+
+    input = open('matrix.txt', 'r')
+    input = input.read().split('\n')[:-1]
+
+    while True:
+
+        body = ''
+
+        for x in range(8):
+
+            chr = input[random.randint(0, len(input) - 1)]
+            body += '%s  ' % chr
+
+        sys.stdout.write(os.popen('clear').read())
+        print body
+        time.sleep(2)
+
+if __name__ == '__main__':
+
+    print run()
+def run():
+
+    table = {
+        13: (
+                {'prefix': '4', 'type': 'visa', 'check': True},
+            ),
+        14: (
+                {'prefix': '300-305', 'type': 'dinners/carte', 'check': True},
+                {'prefix': '36', 'type': 'dinners/carte', 'check': True},
+                {'prefix': '38', 'type': 'dinners/carte', 'check': True},
+            ),
+        15: (
+                {'prefix': '34', 'type': 'amex', 'check': True},
+                {'prefix': '37', 'type': 'amex', 'check': True},
+                {'prefix': '2014', 'type': 'enroute', 'check': False},
+                {'prefix': '2149', 'type': 'enroute', 'check': False},
+                {'prefix': '2131', 'type': 'jcb', 'check': True},
+                {'prefix': '1800', 'type': 'jcb', 'check': True},
+            ),
+        16:  (
+                {'prefix': '51-55', 'type': 'mastercard', 'check': True},
+                {'prefix': '4', 'type': 'visa', 'check': True},
+                {'prefix': '6011', 'type': 'discover', 'check': True},
+                {'prefix': '3', 'type': 'jcb', 'check': True},
+            ),
+    }
+
+    def check_table(number):
+
+        data = table.get(len(number))
+
+        if data:
+
+            for x in data:
+
+                prefix = x.get('prefix')
+                type = x.get('type')
+                check = x.get('check')
+
+                if '-' in prefix:
+
+                    prefixs = prefix.split('-')
+                    prefixs = [str(x) for x in \
+                        range(int(prefixs[0]), int(prefixs[1]) + 1)]
+
+                    for p in prefixs:
+
+                        size = len(p)
+
+                        if number[:size] == p:
+
+                            if check:
+
+                                if check_primary_account(number[size:]):
+                                    return type
+                else:
+
+                    size = len(prefix)
+
+                    if number[:size] == prefix:
+
+                        if check:
+
+                            if check_primary_account(number[size:]):
+                                return type
+
+        return None
+
+    def check_primary_account(number):
+
+        n = len(number) - 1
+        i = 0
+        tot = 0
+        flat = False
+
+        while 0 <= n:
+
+            digit = int(number[n])
+
+            # if i % 2 == 1
+            if flat:
+                flat = False
+                tot += sum([int(x) for x in str(digit * 2)])
+            else:
+                flat = True
+                tot += digit
+
+            n -= 1
+            i += 1
+
+        return True if tot % 10 == 0 else False
+
+    input = open('tarjetas.txt', 'r')
+    input = input.read().split('\n')[:-1]
+
+    #number = '30249927398716' dinners
+    #print check_table(number)
+
+    for number in input:
+
+        type = check_table(number)
+
+        if type:
+            print 'card number %s: %s is valid' % (type, number)
+        else:
+            print 'card number: %s is not valid' % number
+
+if __name__ == '__main__':
+
+    run()
+import os
+import sys
+import random
+
+
+def run():
+
+    input = open('hangman.txt', 'r')
+    input = input.read().split('\n')[:-1]
+
+    n = 8
+    chr = '*'
+
+    phase = ''
+    phase1 = input[random.randint(0, len(input) - 1)]
+    phase_original = phase1
+
+    #print 'phase_original: %s' % phase_original
+
+    while 0 < n:
+
+        n -= 1
+
+        if phase in phase1:
+            phase1 = phase1.replace(phase, chr * len(phase))
+
+        output = ''
+        for y, x in enumerate(phase1):
+
+            if x == chr:
+                output += phase_original[y]
+            elif x == ' ':
+                output += ' '
+            else:
+                output += chr
+
+        if output == phase_original:
+            print 'excelent'
+            break
+        else:
+            if n == 0:
+                print 'so bad'
+                break
+
+        print 'phase: %s' % output
+        phase = raw_input('Enter phase: ')
+        sys.s tdout.write(os.popen('clear').read())
+
+if __name__ == '__main__':
+
+    print run()