473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Computer Language Shootout

We don't have Python implementations for one program, and a
couple of the Python programs we do have show Error.

http://shootout.alioth.debian.org/be...n&lang2=python

Please contribute missing Python programs or faster more-elegant Python

programs.

Please follow the FAQ instructions
http://shootout.alioth.debian.org/faq.php#contribute

best wishes, Isaac

Nov 29 '05 #1
14 1671
This is a direct translation of the D code, maybe it's not the faster
Python implementation, and surely it's not the shorter one. But Psyco
makes it much faster (Psyco likes "low level" style code).
ShedSkink is (almost) able to compile it too, producing a really fast
executable (with some "smart attentions" this SS version becomes only
17% slower than the D version for a given n=11 (26.66 sec instead of
22.70 sec of total running time on a PIII 500 MHz)).
! import sys
!
! def fannkuch(n):
! perm = [0] * n
! perm1 = range(n)
! count = [0] * n
! m = n - 1
! r = n
! maxFlipsCount = 0
!
! while True:
! while r != 1:
! count[r-1] = r
! r -= 1
!
! # SS v.0.0.5 has a problem with this line:
! if not (perm1[0]==0 or perm1[m]==m):
! #perm = list(perm1)
! # to not produce memory garbage
! for i in xrange(n):
! perm[i] = perm1[i]
!
! i = perm[0]
! flips = 0
! while i:
! temp = perm[i]
! perm[i] = i
! i = temp
! j = 1
! k = i - 1
! while j < k:
! temp = perm[j]
! perm[j] = perm[k]
! perm[k] = temp
! j += 1
! k -= 1
! flips += 1
!
! if flips > maxFlipsCount:
! maxFlipsCount = flips
!
! while True:
! if r == n:
! return maxFlipsCount
! temp = perm1[0]
! i = 0
! while i < r:
! j = i + 1
! perm1[i] = perm1[j]
! i = j
! perm1[r] = temp
!
! count[r] -= 1
! if count[r] > 0:
! break
! r += 1
!
!
! #import psyco
! #psyco.bind(fannkuch)
!
! if len(sys.argv) > 1:
! n = int(sys.argv[1])
! else:
! n = 1
! print "Pfannkuchen(%d) = %ld" % (n, fannkuch(n))
Bye,
bearophile

Nov 29 '05 #2
We don't scrape programs from news-groups, if you'd like the program to
be shown on the shootout then please attach the source code to a
tracker item.

Please follow the FAQ instructions
http://shootout.alioth.debian.org/faq.php#contribute
be************@lycos.com wrote:
This is a direct translation of the D code, maybe it's not the faster
Python implementation, and surely it's not the shorter one. But Psyco
makes it much faster (Psyco likes "low level" style code).
ShedSkink is (almost) able to compile it too, producing a really fast
executable (with some "smart attentions" this SS version becomes only
17% slower than the D version for a given n=11 (26.66 sec instead of
22.70 sec of total running time on a PIII 500 MHz)).
! import sys
!
! def fannkuch(n):
! perm = [0] * n
! perm1 = range(n)
! count = [0] * n
! m = n - 1
! r = n
! maxFlipsCount = 0
!
! while True:
! while r != 1:
! count[r-1] = r
! r -= 1
!
! # SS v.0.0.5 has a problem with this line:
! if not (perm1[0]==0 or perm1[m]==m):
! #perm = list(perm1)
! # to not produce memory garbage
! for i in xrange(n):
! perm[i] = perm1[i]
!
! i = perm[0]
! flips = 0
! while i:
! temp = perm[i]
! perm[i] = i
! i = temp
! j = 1
! k = i - 1
! while j < k:
! temp = perm[j]
! perm[j] = perm[k]
! perm[k] = temp
! j += 1
! k -= 1
! flips += 1
!
! if flips > maxFlipsCount:
! maxFlipsCount = flips
!
! while True:
! if r == n:
! return maxFlipsCount
! temp = perm1[0]
! i = 0
! while i < r:
! j = i + 1
! perm1[i] = perm1[j]
! i = j
! perm1[r] = temp
!
! count[r] -= 1
! if count[r] > 0:
! break
! r += 1
!
!
! #import psyco
! #psyco.bind(fannkuch)
!
! if len(sys.argv) > 1:
! n = int(sys.argv[1])
! else:
! n = 1
! print "Pfannkuchen(%d) = %ld" % (n, fannkuch(n))
Bye,
bearophile


Nov 29 '05 #3
On 29 Nov 2005 14:08:12 -0800, ig***@yahoo.com wrote:
We don't scrape programs from news-groups, if you'd like the program to
be shown on the shootout then please attach the source code to a
tracker item. You asked for something, got a response, and then you haughtily[1] declare
that it's not being served on a special platter from your cupboard,
and you won't deign to "scrape" the serving onto your own platter.
Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.

Using what you are _given_ in a normal (and voluntary!) response
__within the same newsgroup context of your own request__ is not
to "scrape programs from news-groups".

[1] allowing for possible language translation difficulties resulting
in expressions with unintended attitudinal overtones.

If you are not prepared at least to say "thanks" before rejecting
what's offered, please don't ask for anything from newsgroup volunteers.
They deserve a better response to their generosity.

Please follow the FAQ instructions
http://shootout.alioth.debian.org/faq.php#contribute
That "please" is also too little too late, after the impact of
your chosen leading phrase (before the first comma).


be************@lycos.com wrote:
This is a direct translation of the D code, maybe it's not the faster
Python implementation, and surely it's not the shorter one. But Psyco

See how top-posting screws things up? The immediately above is what you
responded to. Your response and mine (which is in parts interpolated into
yours below parts of yours the put relevant response below what it is
responding to) all belong down here. Double-pfui.

I better eat. I note that I was a bit too easily provoked into this grumpiness ;-)

Regards,
Bengt Richter
Nov 30 '05 #4

Bengt Richter wrote:
On 29 Nov 2005 14:08:12 -0800, ig***@yahoo.com wrote:
We don't scrape programs from news-groups, if you'd like the program to
be shown on the shootout then please attach the source code to a
tracker item.

You asked for something, got a response, and then you haughtily[1] declare
that it's not being served on a special platter from your cupboard,
and you won't deign to "scrape" the serving onto your own platter.
Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.

I don't see it as an attitude issue but wording. It is blunt but I can
see his point. He was asking people if it is possible to
submit(contribute) some code to the test. And based on what I saw on
his site, it is inappropriate for him to just take code from ML/usenet
as all codes there need proper author(beyond courtesy, there may be
copyright issue). That is my reading anyway.

If it was nicely explained why it needs to be done this way upfront(or
in the response), I believe you may not feel it this way.

Interestingly, I find this response quite compatible with the
personality of this group.

Nov 30 '05 #5
On 29 Nov 2005 18:34:34 -0800, bo****@gmail.com wrote:

Bengt Richter wrote:
On 29 Nov 2005 14:08:12 -0800, ig***@yahoo.com wrote:
>We don't scrape programs from news-groups, if you'd like the program to
>be shown on the shootout then please attach the source code to a
>tracker item. You asked for something, got a response, and then you haughtily[1] declare
that it's not being served on a special platter from your cupboard,
and you won't deign to "scrape" the serving onto your own platter.
Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.

I don't see it as an attitude issue but wording. It is blunt but I can

Wording order expresses the attention priorities of the speaker.
The OP was effectively saying, "I may get around to saying something about
what you did, but first, here's the way I operate, and what you need to
adapt to. Please adapt. Now I have no more time to say anything about what you did,
or to acknowledge it, never mind to express thanks for the effort."

That's not just blunt and concise, it looks like the modus operandi
of a typical volunteer/employee-exploiter (or perhaps spoiled brat,
the typical precursor to the former).
see his point. He was asking people if it is possible to
submit(contribute) some code to the test. And based on what I saw on
his site, it is inappropriate for him to just take code from ML/usenet
as all codes there need proper author(beyond courtesy, there may be
copyright issue). That is my reading anyway. That's possible, but the way I read the OP's post, his priority was
not exactly expression of gratitude, which IMO was due first.

If it was nicely explained why it needs to be done this way upfront(or
in the response), I believe you may not feel it this way. Exactly. Up front would imply different social priorities, at least to me.
Interestingly, I find this response quite compatible with the
personality of this group.

Which "this"? ;-)

Regards,
Bengt Richter
Nov 30 '05 #6

Bengt Richter wrote:
Interestingly, I find this response quite compatible with the
personality of this group.

Which "this"? ;-)

I meant his response.

Nov 30 '05 #7
Hi bearophileH,

Thank you for the code example.
Could you post some more information about ShedSkink?
malv

Nov 30 '05 #8

bo****@gmail.com wrote:
Bengt Richter wrote:
On 29 Nov 2005 14:08:12 -0800, ig***@yahoo.com wrote:
We don't scrape programs from news-groups, if you'd like the program to
be shown on the shootout then please attach the source code to a
tracker item. You asked for something, got a response, and then you haughtily[1] declare
that it's not being served on a special platter from your cupboard,
and you won't deign to "scrape" the serving onto your own platter.
Pfui. Your apparent[1] attitude turns me off, not to mention your top-posting.

I don't see it as an attitude issue but wording. It is blunt but I can
see his point. He was asking people if it is possible to
submit(contribute) some code to the test. And based on what I saw on
his site, it is inappropriate for him to just take code from ML/usenet
as all codes there need proper author(beyond courtesy, there may be
copyright issue). That is my reading anyway.


That is correct, we publish an author's work under Revised BSD - we
can't just take a program from a newsgroup.


If it was nicely explained why it needs to be done this way upfront(or
in the response), I believe you may not feel it this way.

Interestingly, I find this response quite compatible with the
personality of this group.


Nov 30 '05 #9
"malv" wrote:
Could you post some more information about ShedSkink?


http://sourceforge.net/projects/shedskin/

</F>

Nov 30 '05 #10
malv:
Hi bearophileH,
bearophile is enough :-)

Could you post some more information about ShedSkink?


ShedSkin (SS) is a Python -> C++ compiler (or translator) written in
Python, created by Mark Dufour. Its development was initially
"financed" by the summer of code by Google. It contains some smart
algorithms that allow it to infer the type of most variables, and to
compile everything statically (but with a garbage collector). This
produces a very fast executable, usually like a C++ one. SS has some
limits, some of them are temporary, and some of them are here to stay
(it cannot be used on really dynamic stuff). It's not intended to
compile every Python program, but mostly for "algorithmic" code that
has to go fast, often the same code Psyco is used for. It can be seen
as complementary to Psyco, and not really like something to substitute
it, Psyco is a very good software. I am helping Mark as I can, in
different ways, because I think SS is a very interesting software. At
the moment SS is in the Alpha stage still, this means:
- It has a lot of bugs still, but Mark fixes some of them almost every
week. That problem in that fannkuch code is relative to the version
0.0.5, a successive version may compile it correctly.
- Some common things aren't possible yet, like inheritance, but Mark is
probably going to implement this in the following days.
- The code produced is C++, and it calls functions of the SS library.
CPython source code contains some very fast routines (by Raymond
Hettinger and other people), so sometimes CPython is faster (example:
sometimes Python dicts are faster). This is mostly a
"tuning/implementation" problem, it's not a limit of SS or the C++ and
its compiler. It's a matter of knowing lot of complex C++ "tricks" and
implementing/copying faster routines. Another developer can probably
help Mark improve most of those algorithms (I think that sometimes the
CPython source code itself may be adapted and used).
- If another developer helps Mark, a future version of SS can probably
be used to automatically produce compiled modules that can be imported
into normal Python programs (it may call something like SIP/SWIG by
itself), a very simple single-click command can be used (on Windows in
a contex menu). The info about the input types of the functions/methods
may be expressed with some very simple syntax inside the module
docstring, or simply it may be contained in the part of the module that
isn't executed when then module is called.
- There are lot of ways to improve SS still, some people in the Blender
group have already shown interest in SS, but it contains too much bugs
still to be used in serious projects. Helping hands can speed up its
development a lot.

The project on Sourceforge, it contains more information and
documentation:
http://sourceforge.net/projects/shedskin/

SS blog:
http://shed-skin.blogspot.com/

The last version is 0.0.5.1, it contains an important memory bugfix and
other minor bugfixings.

Some timings for version 0.0.5:
http://sourceforge.net/mailarchive/f...forum_id=46397
(small_dict_fp test is probably faster in version 0.0.5.1).

Bear hugs,
bearophile

Nov 30 '05 #11

be************@lycos.com wrote:
This is a direct translation of the D code, maybe it's not the faster
Python implementation, and surely it's not the shorter one. But Psyco
makes it much faster (Psyco likes "low level" style code).


And if you contributed the program like this
http://shootout.alioth.debian.org/gp...php#contribute

we could run the program with Psyco
http://shootout.alioth.debian.org/gp...o&lang2=python

best wishes, Isaac

Nov 30 '05 #12
Bengt Richter wrote:
That's not just blunt and concise, it looks like the modus operandi
of a typical volunteer/employee-exploiter (or perhaps spoiled brat,
the typical precursor to the former).


careful. his faq requires you to "be nice".

</F>

Nov 30 '05 #13

Fredrik Lundh wrote:
Bengt Richter wrote:
That's not just blunt and concise, it looks like the modus operandi
of a typical volunteer/employee-exploiter (or perhaps spoiled brat,
the typical precursor to the former).


careful. his faq requires you to "be nice".

</F>


"Be Nice!" *is* one of paragraph headings in the FAQ section "How can I
help?"

imo Saying that the FAQ "requires you to "be nice" is a
misrepresentation.

Nov 30 '05 #14
ig***@yahoo.com wrote:
"Be Nice!" *is* one of paragraph headings in the FAQ section "How can I
help?"


yeah, we've noticed that it's not one of the headings in the FAQ section
"How can we encourage you to contribute".

</F>

Nov 30 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Isaac Gouy | last post by:
"The Great Computer Language Shootout" has been revived on Debian: http://shootout.alioth.debian.org/index.php Only 15 of the 25 programs have PHP implementations...
0
by: Isaac Gouy | last post by:
"The Great Computer Language Shootout" was mentioned a few months ago - note that the Shootout is active and welcoming contributions at: http://shootout.alioth.debian.org/
26
by: HackingYodel | last post by:
Hello all! I'm learning to program at home. I can't imagine a better language than Python for this. The ideal situation, for me, would be to study two languages at the same time. Probably...
14
by: Jacob Lee | last post by:
There are a bunch of new tests up at shootout.alioth.debian.org for which Python does not yet have code. I've taken a crack at one of them, a task to print the reverse complement of a gene...
14
by: bearophileHUGS | last post by:
The The Computer Language Shootout has just published results for Python 2.5 and Psyco 1.5.2. Comparing the old (Python 2.4) Gentoo Pentium 4 results (now not visible anymore) with the new results,...
80
by: tech | last post by:
Hi, i have the following problem In file1.h namespace A { class Bar { void foo();
37
by: Razii | last post by:
On Wed, 30 Apr 2008 08:00:38 -0700 (PDT), Isaac Gouy <igouy2@yahoo.comwrote: This time I am going to demonstrate a very serious problem with the shootout site. The algorithms used by C,...
31
by: Razik | last post by:
On Wed, 30 Apr 2008 08:00:38 -0700 (PDT), Isaac Gouy <igouy2@yahoo.comwrote: Let's continue. Next we deal with sum-file... ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.