Pollard’s rho algorithm for computing dicrete logarithms

Posted: Δεκεμβρίου 25th, 2011 | Author: | Filed under: programming, python | Tags: , , | 1 Comment »

Here is an implementation in python of
Pollard’s rho method for computing the discrete logarithm. Continue reading “Pollard’s rho algorithm for computing dicrete logarithms” »


Sudoku Solver in Python with Recursion – Maybe a Solution

Posted: Αυγούστου 18th, 2011 | Author: | Filed under: programming | Tags: , | No Comments »

Continue from here.

I managed to find a solution which worked for 2 puzzles I checked. I am sure it will not work always, but I like the solution. It is clear and without much code.

I find all the possible numbers that can be inserted in each cell.
If the cell has only one candidate then we should insert it and call the solve function again.
If all cells are filled then the program must stops.
I think I will have a problem in case of I could not find a cell with one only candidate…Then the program won’t stop,
but who cares? The program is just for learning purposes.

Here is the code:
Continue reading “Sudoku Solver in Python with Recursion – Maybe a Solution” »


Sudoku Solver in Python part 3

Posted: Αυγούστου 13th, 2011 | Author: | Filed under: programming | Tags: , | 1 Comment »

Previous post here

I continued my try to solve Sudoku with Python. Actually I have never solve a Sudoku puzzle myself :)

Here is the updated code
Continue reading “Sudoku Solver in Python part 3” »


Sudoku solver with python part 2

Posted: Αυγούστου 13th, 2011 | Author: | Filed under: programming | Tags: , | 1 Comment »

Continue from here.

Because of the beach and the sun I have only the following code:

 python |   |? 
01
# -*- coding: utf-8 -*-
02
"""
03
Created on Wed Aug 11 18:21:28 2011
04
 
05
@author: gkomninos
06
"""
07
 
08
class Position(object):
09
    '''A Sudoku cell '''
10
    def __init__(self, row, column, value='x', fixed = False):
11
        '''Constructor like'''
12
        self.Row = row
13
        self.Column = column
14
        self.Box = None
15
        self.Value = value
16
        self.Fixed = fixed
17
 
18
    def __calc_box(self):
19
        '''calculates in which "box" the cell belongs'''
20
        if( self.Row >= 0 and self.Row < = 2 and 
21
            self.Column >= 0 and self.Column < = 2):
22
            return 0
23
        elif( self.Row >= 0 and self.Row < = 2 and
24
              self.Column >= 3 and self.Column < =5):
25
            return 1
26
        return 0
27
 
28
    def to_string(self):
29
        '''returns the value of a Position object'''
30
        return self.Value
31
 
32
    def swap(self, other_object):
33
        '''Swaps two cells'''
34
        if(self.Fixed == True or other_object.Fixed == True):
35
            return False
36
 
37
        tmp_row = self.Row
38
        tmp_column = self.Column
39
        tmp_box = self.Box
40
        tmp_value = self.Value
41
 
42
        self.Row = other_object.Row
43
        self.Column = other_object.Column
44
        self.Box = other_object.Box
45
        self.Value = other_object.Value
46
 
47
        other_object.Row = tmp_row
48
        other_object.Column = tmp_column
49
        other_object.Box = tmp_box
50
        other_object.Value = tmp_value
51
 
52
        return True
53
 
54
 
55
    if __name__ == "__main__":
56
        print 'Position object'

Continue reading “Sudoku solver with python part 2” »


Attempt to create a Sudoku solver in python

Posted: Αυγούστου 11th, 2011 | Author: | Filed under: programming | Tags: , | 1 Comment »

I will try to make a Sudoku solver in python as a summer project. Hope to finish it.
I will not explain the rules here. You can check them in wikipedia’s article for sudoku or summarized here.

First I must find a way to represent Sudokus in python. I am thinking to store each puzzle in a file formatted like:

5 3 x x 7 x x x x
6 x x 1 9 5 x x x
x 9 8 x x x x 6 x
8 x x x 6 x x x 3
4 x x 8 x 3 x x 1
7 x x x 2 x x x 6
x 6 x x x x 2 8 x
x x x 4 1 9 x x 5
x x x x 8 x x 7 9
Continue reading “Attempt to create a Sudoku solver in python” »


Web programming with Web.py

Posted: Απριλίου 19th, 2011 | Author: | Filed under: programming, web developement | Tags: , | No Comments »

web.py is a simple python framework for developing.
I started searching for a python web framework an stumbled upon web.py.
I have a little experience with django and i found it pretty good. What i didn’t like about django was that it has
a relatively big learning curve and it hides you some details ( makes things look magic ).

I want something simple with a high level of customization without too much effort.

I have read the tutorial from web.py and i in a few hours understood how it works .
I have implemented a simple demo project for testing.
Continue reading “Web programming with Web.py” »


Simple python script for mysql backups

Posted: Απριλίου 12th, 2011 | Author: | Filed under: programming | Tags: , , | No Comments »

Here is a small script i wrote in python for making quick backups and restores for mysql dbms.
It’s very simple with a few minor bugs.
Continue reading “Simple python script for mysql backups” »