Archive

Posts Tagged ‘challenge’

Advent of Code

December 8, 2015 Leave a comment

Let’s prepare for the advent with some coding challenges: http://adventofcode.com/ .

Advertisements
Categories: python Tags: ,

Python Challenge #1

October 8, 2010 2 comments

This exercise is from http://www.pythonchallenge.com.

Challenge

We have the following encoded text:

g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.

And the following hint to decode it: “K -> M, O -> Q, E -> G”.

First try to solve it yourself. My solution is below.
Read more…

Categories: python Tags: , , , ,

Python Challenge

October 8, 2010 Leave a comment

If you learn Python and you like challenges, don’t forget to visit the site http://www.pythonchallenge.com. These exercises are fun to solve and you will learn a lot from them. I will also start to solve them and post my solutions here. Of course, first you should try to solve them by yourself. When you are done, you can compare your solution with the others’.

Challenge #0 is just to warm you up. I will start with Challenge #1 in the next post.

Categories: python Tags:

A to Z, then Z to A

September 28, 2010 Leave a comment

Challenge

Write a Python script which prints the alphabet from “a” to “z”. Reverse its source code as explained in the previous post, i.e. reverse the order of lines and reverse the order of characters in each line. This reversed script should now print the alphabet from “z” to “a”!

Demonstration:

$ python fromAtoZ.py                                        
a b c d e f g h i j k l m n o p q r s t u v w x y z
$ ./reverse-file.py fromAtoZ.py >za.py
$ python za.py 
z y x w v u t s r q p o n m l k j i h g f e d c b a
$ ./reverse-file.py za.py >az.py
$ python az.py 
a b c d e f g h i j k l m n o p q r s t u v w x y z
$ diff fromAtoZ.py az.py 
$

You can find the script reverse-file.py in my previous post. As you can see, applying reverse-file.py twice, you get back the original file.

Note that this challenge is not specific to Python. It can be solved in C++ too, for instance.

The solution is below, but first try to solve it yourself.
Read more…

Categories: python Tags: , , ,