Level 1:

1
a = CharacterRange["a", "z"]; StringJoin[Characters[s] /. Thread[a -> RotateLeft[a, 2]]]

Level 2:

1
Sort[Tally[Characters[s]], #1[[2]] <= #2[[2]] &]

Level 3:

1
StringJoin[StringCases[s,RegularExpression["[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]"] ->  "$1"]]

Level 4:

1
2
3
4
5
NestWhileList[(resp = Import["http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="<>#];
   m = StringCases[resp ,"next nothing is " ~~ (x : DigitCharacter ..) -> x];
   If[m != {}, m[[1]], Print[resp]; ""]) &,
"12345",
StringLength[#] > 0 &]

16044->8022, continue

Level 5:
pickle module needed, python only.

Level 6:

Each file in channel.zip has a comment of its own. Winrar can not see them. You can use winzip or 7zip instead. Mathematica can not handle them neither, IMLE.

Level 7:

1
2
3
4
t = Cases[ImageData[Import["R:\\oxygen.png"], "Byte"][[48]], {x_, x_, x_, 255} -> x];
FromCharacterCode[Take[t, {1, Dimensions[t][[1]], 7}]]
Out[1]="smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]"
FromCharacterCode[{105, 110, 116, 101, 103, 114, 105, 116, 121}]

Level 8:
un/pw are given in python string format. Just use bz2 module. bz2.BZ2Decompressor().decompress(un) Results are huge and file.

Level 9:

1
Graphics[Line[{Partition[first, 2], Partition[second, 2]}]]

Level 10:
look-and-say sequence

1
2
f[n_] := If[n == 0, "1", StringJoin[Map[StringJoin[ToString[Length[#]], #[[1]]] &,Split[Characters[f[n - 1]]]]]];
StringLength[f[30]]

Level 11:

1
ImageTake[Import["R:\\cave.jpg"], {1, 640, 2}, {1, 640, 2}]

Level 12:
evil1.jpg->evil2.jpg->evil2.gfx->evil3.jpg->evil4.jpg
evil4.jpg will not rendered correctly in Chrome, because it uses a confusing Content-Type:image/jpeg, while it is in fact a text file telling you “Bert is evil!”

1
ImportString[FromCharacterCode[#]]& /@ Table[Downsample[Import["R:\\evil2.gfx", "Byte"], 5, i], {i, 5}]

The 4th image is kind of corrupt. But you can save it, then use your image viewer or Firefox/Chrome to view it. It is said to be truncated on purpose to fit in the gfx pack, and you can try padding it with a few kilobytes of zeroes. But I did not make it. However the other images should give you enough information that you don’t need that one.

Level 13:
xmlrpc, Mathematica has no official implement.

Level 14:
spiral, nothing special, omited.

Level 15:

1
Select[Table[{i,1,27},{i,1006,2000,10}],And[LeapYearQ[#],DayName[#]==Tuesday]&]

Level 16:

1
2
d = Import["R:\\mozart.gif", "Data"];
Image[MapThread[ RotateLeft, {d, Flatten[Position[#, {255, 0, 255}, 1, 1] & /@ d] - 1}, 1]]

Level 17:

1
2
3
4
5
6
7
8
CookieInfo = Reap[NestWhileList[(
    {resp, cookies} = URLFetch["http://huge:file@www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=" <> #, {"Content", "Cookies"},"StoreCookies" -> False];
    Sow["Value" /. cookies[[1]]];
    m = StringCases[resp,"next busynothing is " ~~ (x : DigitCharacter ..) -> x];
    If[m != {}, m[[1]], Print[resp]; ""]) &, "12345",
   StringLength[#] > 0 &]];
ImportString[StringReplace[StringJoin[Flatten[CookieInfo[[2]]] /. "+" -> " "],
  RegularExpression["%(..)"] ->FromCharacterCode[FromDigits["$1", 16]]], "BZip2"]

Level 18:
difflib module in python is nice and powerful.

Level 19:

1
2
3
4
5
6
7
8
9
sorrywav = ImportString[Import["R:\\a.txt", {"Base64", "String"}]];
Export["r:\\sorry.wav", sorrywav];
swapbytes[x_] := Module[{hexstr},
   hexstr = IntegerString[Round[x*2^15], 16, 4];
   FromDigits[StringTake[hexstr, -2] ~~ StringTake[hexstr, 2], 16]/
    2^15.
   ];
sorrywav[[1, 1, 1]] = swapbytes /@ sorrywav[[1, 1, 1]];
Export["r:\\idiot.wav", sorrywav];

Level 20&21:
URLFetch, ImportString… omited.

Level 22:

1
2
3
4
pts = Position [#,9][[1]]&/@Import["R:\\white.gif", "RawData"];
moves = Cases[SplitBy[(#-{101, 101})&/@pts,#==={0, 0}&],Except[{ {0, 0} }]];
imgpts = Flatten[MapIndexed[Accumulate[Prepend[#1, First[#2]*{30, 30}]] &,  moves, {1}],  1];
Image[SparseArray[Append[Map[# -> 1 &, imgpts], {_, _} -> 0], {200, 200}]]

Level 23:
import this, omited.

Level 24:
Mathematica even has a function to solve mazes!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
data = Import["R:\\maze.png", "Data"];
data[[;; 60, ;; 60]] = {255, 255, 255, 255};
maze = Map[If[# != {255, 255, 255, 255}, 1, 0] &, data, {2}];
size = Dimensions@maze;
edgeH = Table[  If[maze[[i, j]] + maze[[i, j + 1]] == 2,   UndirectedEdge[{i, j}, {i, j + 1}]], {i, 1, size[[1]]}, {j, 1,   size[[2]] - 1}];
edgeV = Table[  If[maze[[i, j]] + maze[[i + 1, j]] == 2,   UndirectedEdge[{i, j}, {i + 1, j}]], {i, 1, size[[1]] - 1}, {j, 1,   size[[2]]}];
graphEdges = Union[Select[Flatten[{edgeH, edgeV}], Length@# >= 2 &]];
{start, end}=Cases[  Position[maze,1], {1|641, _} ];
mazePath=FindShortestPath[Graph[graphEdges], start, end ];
RedValues = Extract[data, mazePath][[All, 1]][[2 ;; -1 ;; 2]];
Export["r:\\a.zip", FromCharacterCode[RedValues], "String"];

Level 25:

1
2
3
4
5
For[i = 1, i < 26, i++,
URLSave[StringJoin[   "http://butter:fly@www.pythonchallenge.com/pc/hex/lake",ToString[i], ".wav"],
  StringJoin["R:\\lake", ToString[i], ".wav"]]];
filenames =  Table[StringJoin["R:\\lake", ToString[i], ".wav"], {i, 25}];
ImageAdjust[ImageAssemble[ Partition[  Image[InverseFlat[Flatten[Import[#, "Data"]], {60, 60, 3}]] & /@   filenames, 5]]]

Level 26:

1
2
3
4
5
6
7
d = Import["R:\\mybroken.zip", "Byte"];
For[i = 1, i <= Length[d], i++,
  For[j = 0, j < 256, j++,
   If[Hash[FromCharacterCode[ReplacePart[d, i -> j]],"MD5"] ==
      16^^bbb8b499a0eef99b52c7f13f4e78c24b, Return[{i, j}]]
   ]]
Export["R:\\fixed.zip",ReplacePart[d, 1235->168],"Byte"];

Level 27:

1
2
3
4
5
6
7
8
d = ImageData[Import["R:\\zigzag.gif"], "Byte",   Interleaving -> False][[1]];
rd = Import["R:\\zigzag.gif", "RawData"] - 1;
df = Most[Flatten[d]] ;  rdf = Rest[Flatten[rd]];
diffpos = Position[MapThread[Unequal, {df, rdf}], True];
{diffd1, nouse} = {Extract[rdf, diffpos], Extract[df, diffpos]};
Image[SparseArray[
  Thread[Table[{Quotient[p, 320] + 1, Mod[p, 320] + 1}, {p,  Flatten[diffpos]}] -> 1], {270, 320}]]
s = Tally[ImportString[FromCharacterCode[diffd1], {"BZIP2", "Words"}]]

Level 28:

1
2
3
gdata = Flatten[ImageData[Import["R:\\bell.png"],"Byte", Interleaving -> False][[2]]];
FromCharacterCode[Abs[DeleteCases[ Flatten[Differences[Downsample[gf, 2, #] & /@ {1, 2}]], 42 | -42]]]
"whodunnit().split()[0] ?"

Level 29:

1
2
3
s=URLFetch["http://repeat:switch@www.pythonchallenge.com/pc/ring/guido.html"];
ImportString[FromCharacterCode[StringLength /@ StringSplit[s, "\n"][[13 ;;]]], "BZip2"]
"Isn't it clear? I am yankeedoodle!"

Level 30:

1
2
3
4
a = DeleteCases[Flatten[Import["R:\\yankeedoodle.csv"]], ""];
ImageReflect@ImageRotate@Image[Partition[a, 53]];
b = StringSplit[ Import["R:\\yankeedoodle.csv", "String"]];
FromCharacterCode[FromDigits[#, 10] & /@ (StringJoin[StringTake[#[[1]], {6}], StringTake[#[[2]], {6}], StringTake[#[[3]], {7}]] & /@ Partition[b, 3])]

Level 31:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ori = Import["R:\\mandelbrot.gif", "RawData"];
{w, h} = ImageDimensions[img];
{startx, starty, xstep, ystep} = {0.34, 0.57, 0.036/w, 0.027/h};
s = Table[For[c = (startx + x*xstep) + (starty + y*ystep) I; z = 0.;
    i = 1, i <= 128, i++,
    z = z*z + c;
    If[Abs[z] > 2, Break[]]];
   If[i == 129, 128, i], {y, 480 - 1, 0, -1}, {x, 0, 640 - 1}];
diff = DeleteCases[Flatten[ori] - Flatten[s], 0];
Image[Partition[diff, 23]]

Level 32:
It’s a Nonogram puzzle. I had written a solver before.

Level 33:

1
2
3
4
5
6
7
d = Flatten[ ImageData[Import["R:\\beer2.png"], "Byte"]];
f[n_] := Module[{c1, c2},
   {c1, c2} = Take[Reverse[Union[n]], 2];
   Sow[Image[Partition[n /. {x_ /; IntegerQ[x] && x != c1 -> 0}, Sqrt[Length[n]]]]];
   DeleteCases[n, c1 | c2]
   ];
ArrayReshape[Flatten[Reap[Nest[f, d, 33]][[2]]], {6, 6}, ""] // TableForm

Way Out