Loading

The Genius Kid who made Ruby 1.9 63% faster

The news
http://jibun.atmarkit.co.jp/ljibun01/rensai/genius/05/02.html

- He found out that fibonacci program on ruby 1.9 is slower than 1.8.
- He try to look at ruby source codes in C, and optimize the looping codes inside the interpreter.
- He fixed those to get 63% faster for loop intensive routines.

He is still in Intermediate school, and still very young, but just genius :-) , Cheers,

He is good in C#,  Java, Python too :-)

his blog
http://d.hatena.ne.jp/CanI/

#ps, I am just reading his Python posts, OMG! He is super geek! I can't do 1/5 of him. he seems too brillient.

Cheers,

#Memo - Myself - 2009 Oct 19

Today,

1) I have Ported My Roman to Number, Python one liner to C, Speed becomes unbeatable. :-)

Python
R,r={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000},lambda x:reduce(lambda T,x:T+R[x]-T%R[x]*2,x,0)

C
int R[]={100,500,0,0,0,0,1,0,0,50,1000,0,0,0,0,0,0,0,0,5,0,10};int r(char*s){int x=0;while(*s)x+=R[*s-'C']-x%R[*s-'C']*2,s++;return x;}

2) I Found New Python IDE, called Spyder

http://code.google.com/p/spyderlib/

# I am currently using Pyscripter and sometimes notepad++, previously I use Wing (its not free), Eric IDE, ...

3) I found Python to C++ Code Generator called shedskin, it supports limited syntax only though.

http://code.google.com/p/shedskin/

# I am sometimes using psyco, its quite good actually, psyco use JIT when It can, just skip if cannot, for shedskin, it cannot proceed at all for unsupported syntaxes. Well, It make sense though.

4) I have learn something new on new languages and new ideas, new writing styles.

http://myanmaritpros.com/forum/topics/challenge-on-programming-or

# Challenging is good, I believe :-)

Cheers,
Mark

Python 3.1 In Myanmar Names

Python 3.1 in Myanmar, its Implemented Unicode.org based.

# I found that, to works properly Zawgyi and Ayar, I Need to compile Python Myself. 
I will do soon though.

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> def နွုတ္ဆက္စကား_ေျပာျခင္း(နာမည္):
စကား = "မဂဿငလာပါ {0}။ ေနေကာင္းလား?".format(နာမည္)
print(စကား)

>>> နွုတ္ဆက္စကား_ေျပာျခင္း("ေမာင္ေမာင္")
မဂဿငလာပါ ေမာင္ေမာင္။ ေနေကာင္းလား?
>>>
>>>

-----

Python Code

def နွုတ္ဆက္စကား_ေျပာျခင္း(နာမည္):
    စကား = "မဂဿငလာပါ {0}။ ေနေကာင္းလား?".format(နာမည္)
    print(စကား)

နွုတ္ဆက္စကား_ေျပာျခင္း("ေမာင္ေမာင္")

----

Cheers,
Mark

Simple Roman Numeral Conversion in Python

For Example, We like to convert CCXCIV to 294

# Mapping of Roman Numerals to English Digits is like this
I=1
V=5
X=10
L=50
C=100
D=500
M=1000

# We can use Dictionary in Python
R={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}

# Actual Function to sum up the values for each roman numerals, in a line
roman=lambda x:reduce(lambda T,x:T+R[x]-T%R[x]*2,x,0)

In python, there is reduce function, that can do [1,2,3,4] => 10, 
by summing up from left to right like this (((1+2)+3)+4)

The correct answer should be , C=100, C=100, XC=90, IV=4 => 294

But when we sum up XC, X=10, C=100, oh, its becomes 110, and actual one should be 90.

No worries, 110 is the 90 + 20, and 20 is 2 times of X, isnt it? so just substract it after you sum up :-)

-T%R[x]*2 will do it for you, got it? IV will do same as 6 - 2 => 4 too :-)

so 200 + 90 + 4 will be 294 :-)

Thats the idea I got today, may be somebody already done like that before, but I can't find anything like this in Google, so this is mine.

You can download full program here at my google code page, the license for that is MIT License.


Here is the some of the test results

I 1 1 True
II 2 2 True
III 3 3 True
IV 4 4 True
V 5 5 True
VI 6 6 True
VII 7 7 True
VIII 8 8 True
IX 9 9 True
X 10 10 True
L 50 50 True
C 100 100 True
D 500 500 True
M 1000 1000 True
XXXI 31 31 True
CXLVIII 148 148 True
CCXCIV 294 294 True
CCCXII 312 312 True
CDXXI 421 421 True
DXXVIII 528 528 True
DCXXI 621 621 True
DCCLXXXII 782 782 True
DCCCLXX 870 870 True
CMXLI 941 941 True
MXLIII 1043 1043 True

# First column is Roman Numerals, 2nd is actual Values, 3rd is generate Results, 4th is checking the Result is Right or Wrong 

Cheers,
Mark


Don't use Dive into Python Book to learn Python, If you are non-programmer

Don't use Dive into Python Online Book to learn Python, If you were non-programmer.

because, after 2 pages of hello world,

>>> print 'hello world'
hello world

its suddenly goes to following codes, its quite difficult for new programmers.

def buildConnectionString(params):
     """Build a connection string from a dictionary of parameters.

      Returns string."""
      return ";".join(["%s=%s" % (k, v) for k, v in params.items()])

if __name__ == "__main__":
      myParams = {"server":"mpilgrim", \
          "database":"master", \
          "uid":"sa", \
          "pwd":"secret" \
       }
       print buildConnectionString(myParams)


I believe, iterating dictionary object with this method for new users, just giving headache to them. 
They wont even know what is the dictionary object is.

 ";".join(["%s=%s" % (k, v) for k, v in params.items()]) 

----

Instead, Read Python's built-in Manual, or Tutorials Part for start learning python.

or 

Read Mark Lutz's Programming Python, 3rd Edition

Cheers,

http://en.my-mm.org/lookup.htm is going offline, and will be available with Zawgyi 2009

http://en.my-mm.org/lookup.htm is going offline, and will be available with Zawgyi 2009 only.

There is link http://myanmarnlp.org.mm about my dictionary, but I have no affiliation with MyanmarNLP.

# ps, I am working again on Zawgyi 2009 related things. Cheers!

Mark

အလုပ္မရွိ ေျကာင္မ ေရခ်ိုး

အလုပ္မရွိ ေျကာင္မ ေရခ်ိုး ဒရိုင္ယာ မွုတ္ :D

http://www.youtube.com/watch?v=zoOC2UbTCGA&NR=1

ဒီေျကာင္မ်ိုး လိုခ်င္တယ္ :D

The Reasons Why I like Python - Part 1

- python hash/dict {} is super fast

- you can save every variables and objects from memory to file and from file to memory as variables, (pickle)

- No Need to close the code block with brackets "}" or "end", its better for reading because less lines and clear tabs

- no operator overrides, so you wont see strange syntaxes when learning other codes

- Python data objects are almost same as JSON, so most of the case you dont need any special program to convert each others

- python has wonderful lambda functions too.

- its relatively fast, if you dont satisfy its speed, you still can tweak it through C,C++

- you can call C/C++ functions from python and can use from C/C++ functions to Python functions too.

- develop and maintain by many many super geeks and gurus, so its just impressive to use python :D

- python is good for text processing, web, cross platform GUI, shell scripts, almost everything you can do with python.

- you can do 9999**9999 (power) easily in python (result around 40000 length digits), i believe its better than complied languages

- array/lists [], dict/hash {}, tuple() can easily convert each others, and all of them are easy to iterate.

- sets object can save lots of your works. you can do intersections, combinations, difference objects very easily.

- i like this syntax for looping an all iterable objects [x for x in x] :-)

- adding/removing items from/to array/lists are super fast

- regular expressions are full featured

- some modules (eg, io) are rewritten eventually with C for speed by super geeks, so performance are no worries

- its now upto versions 3.*, and its very compact and not bloated one.

- my own code is readable after 6months, others languages i cannot, because python syntax is unique way and very cleared

- python comes built in with most linux machine these days, and many hosting supports python.

 - most of the python authors works in big companies, and python is in use by top companies, its mean you have more chance to improve your life with python :-)

- many hacking/exploits scripts avaible in python these days, its mean you can learn lots of tricky and nice codes from that :P

- most of the cases, python codes has less characters / less lines than other languages. I am very much fun with this :-)

- its easy to write own web server, if you just need to run python based web sites, its very easy :-)

- python itself compile very fast, and very easy, if you do custom build

- you can just use g++ or mingw32-g++ to compile almost all C/C++ extensions, on almost all OSes.

- python is good friend for network engineers too. I can get PE Router configurations with python easily, and I can analyze PE Router config for each users and each circuits very effectively :D

To be continued

#ps there is many many left, i can only recall those now, cheers

Mark

က်ေနာ္ဖတ္ေသာ အျခား ဘေလာ့ / ဆိုဒ္မ်ား