#! /usr/bin/python

# This software is the intelectual property of Solomon Latham. It can in no way be changed w/out my permission, but it can be used for your fun and intertainment.
#Copyrighted 2004.

# This software is provided as is, with no guarantee of anykind, ecpecially not of you understanding it.
# For comments and questions, I can be contacted at lathams@seattle.edu

print "And now for something completly different! This is a program that uses my, Solomon Anthony Latham, crazy math where 9=0. To make it work, I had to break a couple rules of normal math, but what is math for then to be used in fun ways?"
print
print "This program basically calculats my age only by manipulating the number in the current year."
print
print "If you take a look at the code, you will see that at no point do I put my birth year in it."
print
print "To use, just input the year you want to know my age. I have designed this to work up to 2069, starting at 1980. You could put other dates before 1980 or after 2069, but because I was born in 1980 and because of the complexity of the math, the answer would not be accurate any more."
print
print "Limitations: for now, the math falls appart after 2069 due to a bug that can be regarded as similare to the Y2K bug. It is by design going to do that, and I will not pretend that I am in want, or even in need of finding a solution. That would be going further then what I was plannig on for this piece of math fun, plus I am not sure the logic is worth figuring out to calculate an age that I may never reach... "
print
print "For those interested in the theory, you can open this file with your favorit text editor and scoll to the bottom. I have included the theory behind the practice."
print

a = str(int(raw_input("Put the year here: ")))
b = int(a[0])		#b is the 1st digit of the year
c = int(a[1])		#c is the 2nd digit of the year
d = int(a[2])		#d is the 3rd digit of the year
e = int(a[3])		#e is the 4th digit of the year

#where 'f' is 'b+d', and 'fd' is the derived number from 'f' according to the said rules, and 'fd' also becomes the 1st digit of my age.
f = str(int(b+d))
if int(f) == int(9):
	fd = str(0)
elif int(f) < (9):
	fd = str(f)
else:
	fb = int(f[0])
	fc = int(f[1])
	fa = str(fb+fc)
	if int(fa) == int(9):
		fd = str(0)
	elif int(fa) < int(9):
		fd = str(fa)
	else:
		fe = int(fa[0])
		ff = int(fa[1])
		fd = str(fe+ff)

#where 'g' is 'c+e', and 'gd' is the derived number from 'g' according to the said rules, 'gd' also becomes the 2nd digit of my age.
g = str(int(c+e))
if int(g) == int(9):
	gg = int(e)
	if int(gg)-1 == int(8):
		gd = str(9)
	else:
		gd = str(0)
elif int(g) < int(9):
	gd = str(g)
else:
	gb = int(g[0])
	gc = int(g[1])
	ga = str(int(gb)+int(gc))
	if int(ga) == int(9):
		gh = int(e)
		if int(gh)-1 == int(8):
			gd = str(9)
		else:
			gd = str(0)
	elif int(ga) < (9):
		gd = str(ga)
	else:
		ge = int(ga[0])
		gf = int(ga[1])
		gd = str(int(ge)+int(gf))

#where 'h' is my age:
h = fd+gd
print h, "is Solo's age in the year:", a

# Theory Behind The Practice:
# ---------------------------
# Note that although similar, this explenation is a wadered down version of the code. I did not go into the details of all the exceptions, and how they must be dealt with, but they are none the less close enough to alow for a better understanding of the logic.
# To some this may seem like crazy talk, and to others this may seem like pure geneous (ie: me)!  
# The code above only works with certain dates, and due to the way I wrote it, the said date has to be in between the year 1000 and the included year 9999. 
# For those who haven't figured this out, the key is the year I was born. The year 1980 is special, and lends itself to this sort of manipulation. If I were born in 1981, I wouldn't be able to derive my age following this method.
# Here is how it works:
# 1st lets take the date I was born: 1980
# Lets split the date in 4 intergers where the 1st is b, the second is c, the third is d and the fourth is e.
# If you take the first (b) and add it to the third (d) b+d = 9, and this is concidered a string.
# If you take the second (c) and add it the the fourth (e) d+e = 9, and this is concidered a string.
# Now pay close attention here, because this is where the magic happens: if I say 9 = 0, then the string 99 = 00
# And that's how I was able to get the concept.
# 2nd let us take a different year, such as 1999. I am choosing this number, because it is actually one of the numbers that is a little more complicated to get to work accuratly.
# Lets do the same with 1999 as we did with 1980.
# this time b = 1, c = 9, d = 9, e = 9
# b+d = 10, c+e = 18 notice how if I were to stop here, I would be 1018 year old (too many digits), but in fact I should be 19 in the year 1999. Lets look at the answers that we got: f = b+d = 10
#		g = c+e = 18
# Notice how I have 2 digits for each string, where I only want one? Well, that's easy to deal with. Take te first digit of string f (we'll call it fa) and the second digit (fb), and add them together, giving us fc = 1
# Same thing works for g, where ga = 1, gb = 8, ga+gb = gc, 1+8 = 9, and since those are now strings, I can do fc+gc = 1+9 = 19
# But now, I have incerted a new problem, when I say 9 = 0, that means 0 = 9 interchangably. How do I get the program to know when to use a 9 or a 0? Simple, I take the last digit of the given date and substract 1 from it. If I get the number 8, then I know to use the string 9 in my answer. If I get anything else, I know to use the string 0.
# Once I have that, all I have left to do is to add the string from (b+d) to the string (c+e). Of course, before I do that, I have to make sure the numbers will add up and make sence, but hey, did I not say somewhere that this was not supposed to make sence to everybody? No? Well, now I have.

# This system will work, as I said above, all the way from 1980, to 2069. I am currently trying to figure out how to get it to work up to 2079, which shouldn't demand too much work. But I am affraid that I wouldn't be dealing with the logic correctly anymore, so, to be seen...

# Peace to you all
# Solo
