#!/usr/bin/env python '''Discrete math demo program. By Sky Coyote, November 2007''' # import necessary modules import sys # run as main program if __name__=='__main__': a = 0.0 # what you have b = 1.0 # what your friend has # get initial amount from command line if len(sys.argv) > 1: b = float(sys.argv[1]) c = b # exchange amount i = 0 iters = 100 # get iters from command line if len(sys.argv) > 2: iters = int(sys.argv[2]) # accumulate data data = [] print 'i A B C' print '----- --------------- --------------- ---------------' print '%-5d %-15.8f %-15.8f' % (i, a, b) # perform iterations for i in range(1, iters + 1): # odd iters: get if i % 2 != 0: a += c b -= c # even iters: give back else: a -= c b += c print '%-5d %-15.8f %-15.8f %-15.8f' % (i, a, b, c) # accumulate data data.append((a, b)) # update exchange amount c /= 2.0 # uncomment next line if not using graphics #sys.exit(0) # import modules for graphics from numpy import * import wx from plots import * # create simple app and plot window app = wx.PySimpleApp(False) win = PlotFrame(array(data).transpose(), 'A and B') win.Show() app.MainLoop()