Last active
August 29, 2015 13:59
-
-
Save Thyrst/10591074 to your computer and use it in GitHub Desktop.
Variace bez rekurze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# 04:21 < RemoteFox~> the fuck | |
# 04:22 < RemoteFox~> jsem ted stravil az nezdrave moc casu snahou napsat bruteforce bez pouziti rekurze | |
# 04:26 < RemoteFox~> (resp. program, ktery vypise kombinace) | |
# 04:26 < RemoteFox~> ciste jen pomoci nekolika do sebe zanorenych smycek | |
# | |
import sys | |
def err(msg): | |
print(msg) | |
exit(1) | |
try: | |
max_len = int(sys.argv[1]) + 1 | |
except IndexError as e: | |
err("Argument missing!") | |
except ValueError as e: | |
err("Bad argument!") | |
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
number = len(letters) | |
for length in range(1, max_len): | |
for j in range(0, number**length): | |
index = j | |
for i in range(0, length): | |
print(letters[index % number], end="") | |
index = int(index/number) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment