#!/usr/bin/env python from sys import path, argv, exit path.append('/home/steph/mpc/lib') from dec2bin import dec2bin import nimadd2 count=1 args=[] args_bin=[] rborkedbins=[] # This will be a list of lists addedplaces=[] errs=0 place=0 if len(argv) < 2: print "Usage: %s " % (argv[0]) exit(1) while 1: try: args.append(argv[count]) count=count+1 except IndexError, error: break for i in args: try: num=int(i) except ValueError, error: print "Usage: %s " % (argv[0]) exit(1) bin=dec2bin(num) args_bin.append(int(bin)) for j in args_bin: borked=nimadd2.breakBin(j) borked.reverse() rborkedbins.append(borked) while errs < (len(argv) - 1): errs=0 places=[] for k in rborkedbins: try: places.append(k[place]) except IndexError, error: errs=errs+1 places.append(0) added=nimadd2.nimAddPlaces(places) addedplaces.append(added) place=place+1 sigplaces=addedplaces[:len(addedplaces)-1] sigplaces.reverse() # put the digits back into the correct order addedbin=nimadd2.glueBinDigits(sigplaces) print addedbin # This is the result of nim added numbers