PET Challenge

Author: Juanjo Conti

In each issue we'll have a challenge to solve using Python and in the next one we'll announce the winner. We compete for honor, glory and fun; but in the future we may have some sponsored prizes :)

This issue challenge consists in writing a program that receive a number in the standard input and prints in the screen the number factorization with the following format. These are examples showing possible inputs and desire outputs.

input: 11
output: 11

input: 8
output: 2^3

input: 24
output: 2^3 x 3

input: 168
output: 2^3 x 3 x 7

Note that the factors are increased ordered and if a factor appears more than once, it most be expressed as a power.

Participants must send the solution as a .py file and it'll be executed with Python 2.7. The winner will be the one with the less-characters solution. Send your solution to revistapyar@netmanagers.com.ar with DESAFIO1 in the subject before 01/10/2010.

Good luck and happy golfing!

Feedback and Clarifications

After the first issue was in the street, some people manifest doubts about the challenge. Clarifications:

  • You can't use external programs or libraries other than the ones in the stdlib.
  • Withe spaces, tabs and comments count in the characters count. So, send your answer as short as possible!
  • The input number can be any integer >= 0.
  • The words 'input' and 'output' aren't part of the expected input or output for the programs.
  • The expected output for 0 is 0 and for 1 is 1.

Then, some participants manifested their desire of some feedback about their solutions; for this purpose this wiki was created: http://python.org.ar/pyar/Proyectos/RevistaPythonComunidad/PET1/Desafio

PDF version. | reSt version

Help PET: Donate

blog comments powered by Disqus

Last change: Thu Sep 9 17:10:05 2010.  -  This magazine is under a Creative Commons license.