#! /usr/bin/python # -*- coding: UTF-8 -*- """ PyGreyCode: programma creato da Frafra (francesco.it@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ __module_name__ = 'PyGreyCode' __module_version__ = __revision__ = versione = '0.1' __module_description__ = 'Per calcolare le combinazioni di 0/1' n = input('Numero: ') interi = ''.join([str(x) for x in xrange(10)]) binari = '01' def conv(number): x = 0L for digit in str(number): x = x * len(interi) + interi.index(digit) res = '' while x > 0: digit = x % len(binari) res = binari[digit] + res x /= len(binari) return res for x in xrange(2**n): calc = conv(x) diff = n-len(calc) print '0'*diff+calc