Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Wish Software (http://www.mac-forums.com/forums/os-x-development-darwin/79394-wish-software.html)

mathogre 10-04-2007 10:28 PM

Wish Software
 
This is the software being considered for use in the "Wish" thread:

http://www.mac-forums.com/forums/sho...t=78599&page=1

The software is here:

http://homepage.mac.com/mathogre/.Pictures/touch_08.py

It is a command line program written in Python. It uses the version of Python built into the latest version of OS X, 10.4.10. The version of Python is 2.3.5. While newer versions of Python are available, I chose to go with what is in OS X.

Download the softare to your desktop. After you download it, do an md5 check on it. Open Terminal and type the following on the command line:

md5 touch_08.py

You should get a result like this:

MD5 (touch_08.py) = 105388ae8172326cef18a353ad8d78f3

If you do, then your download worked properly. If not, then your download did not work.

This is NOT the final version of the software. However, you should try it to see how it works.

Type the following on the command line:

/usr/bin/python ~/Desktop/touch_08.py

This will start the program.

Below you will find the opening comment section from the program. You can read the code with any text editor and see exactly what is in it. The program is neither long nor complicated. Please feel free to challenge anything that does not seem right!

## This program chooses names in the drawing run by macjuicy23 for an
## Apple Store credit and for an iPod touch. The names are stored in a
## list, once for each ticket they bought. A user enters a closing stock
## figure as the random number seed for a stock group or single stock
## chosen on the previous day. The Apple Store credit is chosen first,
## and the winning ticket is removed from the list. The iPod touch is
## chosen second, and the winning ticket is removed from the list.
##
## To run the program, place this program on your desktop, run Terminal,
## and enter the following command into Terminal:
##
## /usr/bin/python ~/Desktop/touch_08.py
##
## This will start the program.
##
## You will first see a greeting, and a request to enter the stock price.
## For instance, on a Monday, someone may decide the drawing will occur
## the next day, and that the closing Apple stock price for Tuesday as
## reported on an iPhone will be used to seed the program. This is where
## you'll enter it.
##
## Note that the random number generator is very sensitive to inputs. A
## one cent difference ($0.01) can radically alter results. In addition
## to the unpredictability of stock prices from day to day, no one can
## second guess the results. Feel free to experiment!
##
## After entering the stock price, you are shown what you entered, and
## are allowed to either press the return key to continue or enter ctrl-d
## to exit the program.
##
## Assuming you've properly entered the stock price, you are then
## prompted to press the return key to see what tickets are in the
## drawing. I've taken everything almost exactly as in the forum thread.
## In one case I had to add a back slash - a character escape - to allow
## for a single quote that appeared in the forum list.
##
## One line exists for each ticket. People who bought multiple tickets
## are shown multiple times. This is simply for validation.
##
## Now it's time for the drawing. You are prompted to press the return
## key to see who wone the Apple Store credit. The program randomly
## chooses an entry from the ticket list (a Python list named ticketList)
## and prints the result.
##
## You are then prompted to press the return key to see the list of
## tickets remaining in the drawing. The program takes the winning
## ticket and removes it from the ticket list. The remaining entries are
## displayed.
##
## Note that a person with two or more tickets could potentially win both
## prizes. Only the winning ticket is removed.
##
## The next prompt for the return key is for the iPod touch. As before,
## the program randomly chooses an entry from the ticket list and prints
## the result.
##
## Finally you are prompted to see the remaining list of tickets that did
## not win. The winning entry is removed from the list when you press
## return, and the remaining tickets are displayed.

technologist 10-05-2007 12:17 AM

As Python is not my native tongue, I found this helpful when reading over the code. (Yup...I have no life.)
http://docs.python.org/lib/module-random.html

mathogre 10-05-2007 12:24 AM

Thank you technologist! I use that Python reference all of the time.

RiDE 10-05-2007 11:19 AM

It works PERFECTLY!!!!! FANTASTIC JOB Math!!!!!!


For those that aren't very Terminal Savvy...
To verify the download was successful (it will be) using md5.... you'll need to open the terminal and either:

type cd Desktop (press enter) THEN type md5 touch_08.py (press enter)

or

Open the terminal type md5 and then press the space bar then drag and drop the file onto the Terminal window, thus showing the file path.... then press enter.

mathogre 10-05-2007 11:29 AM

Thank you RIDE!

Oh and sorry about the md5 instructions. I get typing so fast and think that everyone works on the command line, so I forget some things. O:)

mathogre 10-09-2007 11:50 PM

The latest version of the software, v10, can be found here:

http://homepage.mac.com/mathogre/.Pictures/touch_10.py

md5 check should give this as a result:

MD5 (touch_10.py) = 9fe6d04dbbab30baa51c4b4d9efd8ac8

To see the difference between the prior version and this version, in Terminal on the command line type:

diff touch_08.py touch_10.py

It should give you this result:

Code:

diff touch_08.py touch_10.py
14c14
< ##    /usr/bin/python ~/Desktop/touch_08.py
---
> ##    /usr/bin/python ~/Desktop/touch_10.py
113,114c113
<                  '$20.00 PowerbookG4 (Mac-Forums)', \
<                  '$20.00 PowerbookG4 (Mac-Forums)', \
---
>                  '$10.00 PowerbookG4 (Mac-Forums)', \
120,121d118
<                  '$10.00 Ryan13 (Mac Forums)', \
<
124c121,130
<                  '$10.00 XMARLTONX (Mac-Forums)]']
---
>                  '$10.00 bobtomay (Mac-Forums)', \
>
>                  '$10.00 XMARLTONX (Mac-Forums)', \
>
>                  '$10.00 Ariel (mac-Forums)', \
>
>                  '$20.00 Quiara: (mac-Forums)', \
>                  '$20.00 Quiara: (mac-Forums)', \
>
>                  '$10.00 Brandon: (mac-Forums)']

diff is a Unix function that shows the differences between files. It does lots more than that, but for this purpose, that's how it is used.

The little codes like 14c14 indicate that differences in line 14 in the first file corresponds to differences in line 14 in the second. The left arrow "<" shows the line(s) in the first file, while the right arrow ">" shows the line(s) in the second file.

As you can see, one change is for how to run the program, using the latest version number or the program. The remaining changes are simply for the current participants.

Hope this helps!

iRye 10-11-2007 11:33 PM

I actually like that program for fun :P

mathogre 10-14-2007 03:08 PM

It's time for a dry run. Here are five "seeds" to try. The first one is the closing price of Apple stock on Friday Oct. 12, 2007. Both the iPhone and the Charles Schwab website show the same price. The next two seeds are one cent below and above, respectively. The last two are just other values to try.

With each seed, I've included the winning results, based on running version 10, touch_10.py. Instructions above give details on how to run this, but here's the command to run in Terminal, assuming you've saved the program to the desktop:

/usr/bin/python ~/Desktop/touch_10.py

Once you've run this, please report the following results:

a) What type of machine are you running? MacBook? iMac?

b) What version of OS X are you running? I've allowed that this is intended to use the version of Python that ships with OS X 10.4.10 only.

c) Did all of your results match what I've poste? If not, what differences did you get?

Thanks!

THIS IS A TEST.

1. seed = 167.25
Congratulations! $20.00 Quiara: (mac-Forums) is the winner of the Apple Store credit.
Congratulations! $20.00 babarnette (Mac-Forums) is the winner of the iPod touch.

2. seed = 167.24
Congratulations! $10.00 Brandon: (mac-Forums) is the winner of the Apple Store credit.
Congratulations! $40.00 RMAN (Mac Forums) is the winner of the iPod touch.

3. seed = 167.26
Congratulations! $30.00 RIDE (Mac-Forums) is the winner of the Apple Store credit.
Congratulations! $40.00 RMAN (Mac Forums) is the winner of the iPod touch.

4. seed = 100.00
Congratulations! $10.00 Mylo (mac-forums) - I wil SHip no worries anywhere in us is the winner of the Apple Store credit.
Congratulations! $40.00 Mathogre (Mac-Forums) is the winner of the iPod touch.

5. seed = 200.00
Congratulations! $10.00 nokialed (mac Forums) is the winner of the Apple Store credit.
Congratulations! $10.00 XMARLTONX (Mac-Forums) is the winner of the iPod touch.

MacHeadCase 10-14-2007 03:10 PM

Wow MO! That's some amazing work you did! I haven't tested the program but I have total faith in you! :D

mathogre 10-14-2007 03:16 PM

Quote:

Originally Posted by MacHeadCase (Post 504165)
Wow MO! That's some amazing work you did! I haven't tested the program but I have total faith in you! :D

Thank you MHC! Well, I still want to make sure the program works as expected. Random number generators work on fringe results, and the slightest difference in versions of Python could give different results. I want everything to be up front on this.

mathogre 10-18-2007 09:04 PM

The final version of the code for the drawing is here:

http://homepage.mac.com/mathogre/.Pi...ch_12_final.py

If you run the md5 check on it, here's the command and the subsequent result:

md5 touch_12_final.py

MD5 (touch_12_final.py) = ff36c05fa4f6e2046d60e0587045cc52

If you save the program to the Desktop, run it with this command:

/usr/bin/python ~/Desktop/touch_12_final.py

The program has been updated with the final list of people in the drawing as posted by RIDE in the main thread. Below is the difference report from the prior version of the code. Note that the only differences are in the comment regarding how to run the program, and in the names of the people in the drawing. Because of ordering and formatting differences in the list of people, you'll first find the list of participants as included in the program, followed by the differences report.

Enjoy and good luck!!!!

Code:

ticketList = [    'Skye: $10', \

                  'Cherokee: $40', \
                  'Cherokee: $40', \
                  'Cherokee: $40', \
                  'Cherokee: $40', \

                  'babarnette: $20', \
                  'babarnette: $20', \

                  'cheesybanana: $30', \
                  'cheesybanana: $30', \
                  'cheesybanana: $30', \

                  'Netty4Mac: $10', \

                  'Nokialed: $10', \

                  'MacHeadCase: $10', \

                  'bobtomay: $10', \

                  'aptmunich: $20', \
                  'aptmunich: $20', \

                  'Quiara: $20', \
                  'Quiara: $20', \

                  'Brandon: $10', \

                  'Ariel: $10', \

                  'Mathogre: $40 (mail)', \
                  'Mathogre: $40 (mail)', \
                  'Mathogre: $40 (mail)', \
                  'Mathogre: $40 (mail)', \

                  'Rman: $40 (mail)', \
                  'Rman: $40 (mail)', \
                  'Rman: $40 (mail)', \
                  'Rman: $40 (mail)', \

                  'iKiten: $10 (mail)', \

                  'Fallooza: $10', \

                  'RIDE: $30', \
                  'RIDE: $30', \
                  'RIDE: $30', \

                  'Mylo: $10', \

                  'cwa107: $20', \
                  'cwa107: $20', \

                  '$10.00 Nicole T. (my co-worker) Paid to MacJuicy', \

                  '$10.00 Ito M. (my co-worker) Paid to MacJuicy', \

                  '$20.00 Robert L. (co-worker) Paid to MacJuicy', \
                  '$20.00 Robert L. (co-worker) Paid to MacJuicy', \

                  '$10.00 Rolando E. (John\'s Neighbor) Paid to MacJuicy', \

                  '$10.00 Nina R. (My Neighbor) Paid to MacJuicy']

Code:

diff touch_10.py touch_12_final.py
14c14
< ##    /usr/bin/python ~/Desktop/touch_10.py
---
> ##    /usr/bin/python ~/Desktop/touch_12_final.py
67,69c67
< ticketList = [    '$30.00 Cheesybanana (Mac-Forums)', \
<                  '$30.00 Cheesybanana (Mac-Forums)', \
<                  '$30.00 Cheesybanana (Mac-Forums)', \
---
> ticketList = [    'Skye: $10', \
71,73c69,72
<                  '$30.00 RIDE (Mac-Forums)', \
<                  '$30.00 RIDE (Mac-Forums)', \
<                  '$30.00 RIDE (Mac-Forums)', \
---
>                  'Cherokee: $40', \
>                  'Cherokee: $40', \
>                  'Cherokee: $40', \
>                  'Cherokee: $40', \
75,78c74,75
<                  '$40.00 Mathogre (Mac-Forums)', \
<                  '$40.00 Mathogre (Mac-Forums)', \
<                  '$40.00 Mathogre (Mac-Forums)', \
<                  '$40.00 Mathogre (Mac-Forums)', \
---
>                  'babarnette: $20', \
>                  'babarnette: $20', \
80,81c77,79
<                  '$20.00 babarnette (Mac-Forums)', \
<                  '$20.00 babarnette (Mac-Forums)', \
---
>                  'cheesybanana: $30', \
>                  'cheesybanana: $30', \
>                  'cheesybanana: $30', \
83,84c81
<                  '$20.00 Aptmunich (Mac-Forums)', \
<                  '$20.00 Aptmunich (Mac-Forums)', \
---
>                  'Netty4Mac: $10', \
86c83
<                  '$10.00 Netty4mac (Mac-Forums)', \
---
>                  'Nokialed: $10', \
88c85
<                  '$10.00 Nicole T. (my co-worker)', \
---
>                  'MacHeadCase: $10', \
90c87
<                  '$10.00 Ito M. (my co-worker)', \
---
>                  'bobtomay: $10', \
92c89,90
<                  '$10.00 Nina R. ( My neighbor)', \
---
>                  'aptmunich: $20', \
>                  'aptmunich: $20', \
94,95c92,93
<                  '$20.00 Robert L. (co-worker)', \
<                  '$20.00 Robert L. (co-worker)', \
---
>                  'Quiara: $20', \
>                  'Quiara: $20', \
97,100c95
<                  '$40.00 Cherokee (Mac-Forums)', \
<                  '$40.00 Cherokee (Mac-Forums)', \
<                  '$40.00 Cherokee (Mac-Forums)', \
<                  '$40.00 Cherokee (Mac-Forums)', \
---
>                  'Brandon: $10', \
102,105c97
<                  '$40.00 RMAN (Mac Forums)', \
<                  '$40.00 RMAN (Mac Forums)', \
<                  '$40.00 RMAN (Mac Forums)', \
<                  '$40.00 RMAN (Mac Forums)', \
---
>                  'Ariel: $10', \
107c99,102
<                  '$10.00 Mylo (mac-forums) - I wil SHip no worries anywhere in us', \
---
>                  'Mathogre: $40 (mail)', \
>                  'Mathogre: $40 (mail)', \
>                  'Mathogre: $40 (mail)', \
>                  'Mathogre: $40 (mail)', \
109c104,107
<                  '$10.00 nokialed (mac Forums)', \
---
>                  'Rman: $40 (mail)', \
>                  'Rman: $40 (mail)', \
>                  'Rman: $40 (mail)', \
>                  'Rman: $40 (mail)', \
111c109
<                  '$10.00 Rolando E. (John\'s Neighbor)', \
---
>                  'iKiten: $10 (mail)', \
113c111
<                  '$10.00 PowerbookG4 (Mac-Forums)', \
---
>                  'Fallooza: $10', \
115c113,115
<                  '$10.00 Skye (Mac-Forums)', \
---
>                  'RIDE: $30', \
>                  'RIDE: $30', \
>                  'RIDE: $30', \
117c117
<                  '$10.00 ikitten (Mac-Forums)', \
---
>                  'Mylo: $10', \
119c119,120
<                  '$10.00 MacHeadcase (Mac-Forums)', \
---
>                  'cwa107: $20', \
>                  'cwa107: $20', \
121c122
<                  '$10.00 bobtomay (Mac-Forums)', \
---
>                  '$10.00 Nicole T. (my co-worker) Paid to MacJuicy', \
123c124
<                  '$10.00 XMARLTONX (Mac-Forums)', \
---
>                  '$10.00 Ito M. (my co-worker) Paid to MacJuicy', \
125c126,127
<                  '$10.00 Ariel (mac-Forums)', \
---
>                  '$20.00 Robert L. (co-worker) Paid to MacJuicy', \
>                  '$20.00 Robert L. (co-worker) Paid to MacJuicy', \
127,130c129
<                  '$20.00 Quiara: (mac-Forums)', \
<                  '$20.00 Quiara: (mac-Forums)', \
<
<                  '$10.00 Brandon: (mac-Forums)']
---
>                  '$10.00 Rolando E. (John\'s Neighbor) Paid to MacJuicy', \
131a131
>                  '$10.00 Nina R. (My Neighbor) Paid to MacJuicy']


RiDE 10-18-2007 09:36 PM

Absolutely flawless!!! Great Job Math!!! Thank you for the time and effort you've put into this!!! Well done!!!!

mathogre 10-18-2007 10:05 PM

Thank you RIDE. It was fun!


All times are GMT -4. The time now is 11:27 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.