Wish yourself a happy new year Jan 1, 2014
Well, before you do that, I will do it from my side:
Happy new year to you!
So, I was just working on somethings, and found this nice little code snippet that was totally appropriate for this event.
If you are a fan of the ruby (like me), define a function with the following
definition (try, using
irb for this purpose):
1 def encode(str); str.chars.map(&:ord).inject(:+); end
The above function does the following:
- accept a string as an input
- break it into its constituent characters
- convert these characters to their ascii integer value
- sum up all the integer values and return that sum
Nothin’ great about that function, right?
Now, try this in your
1 encode "Happy new year to you!"
You will see that the above function is quite intelligent in itself.
That little function is empowered with an artificial intelligence by its code, without any complex mechanisms :)
Oh, and here is an alternative:
1 2 Happy = Time Happy.new.year
If you are a python fan, instead, try this:
1 2 encode = lambda str: sum(ord(c) for c in str) encode("Happy new year to you!")