Τη Τρίτη, 22 Ιανουαρίου 2013 6:11:20 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε: > On Wed, Jan 23, 2013 at 2:59 AM, Ferrous Cranus <nikos.gr...@gmail.com> wrote: > > > I just need a way to CONVERT a string(absolute path) to a 4-digit unique > > number with INT!!! That's all i want!! But i cannot make it work :( > > > > Either you are deliberately trolling, or you have a major > > comprehension problem. Please go back and read, carefully, all the > > remarks you've been offered in this thread. Feel free to ask for > > clarification of anything that doesn't make sense, but be sure to read > > all of it. You are asking something that is fundamentally > > impossible[1]. There simply are not enough numbers to go around. > > > > ChrisA > > [1] Well, impossible in decimal. If you work in base 4294967296, you > > could do what you want in four "digits".
Fundamentally impossible? Well.... OK: How about this in Perl: $ cat testMD5.pl use strict; foreach my $url(qw@ /index.html /about/time.html @){ hashit($url); } sub hashit { my $url=shift; my @ltrs=split(//,$url); my $hash = 0; foreach my $ltr(@ltrs){ $hash = ( $hash + ord($ltr)) %10000; } printf "%s: %0.4d\n",$url,$hash } which yields: $ perl testMD5.pl /index.html: 1066 /about/time.html: 1547 -- http://mail.python.org/mailman/listinfo/python-list