faerie の日記の Python

 | 

2006-06-15

Hit & Blow はてなブックマーク - Hit & Blow - faerie の日記の Python Hit & Blow - faerie の日記の Python のブックマークコメント

#!/usr/bin/env python

import random
import re

def main():
    a = range(10)
    random.shuffle(a)
    answer = "".join(map(str, a[:4]))
    p = re.compile(r"^\d{4}$")
    n = 1
    while True:
        line = None
        try:
            line = raw_input("%02d> " % n).rstrip()
        except EOFError:
            print
            break
        except KeyboardInterrupt:
            print
            break
        if not p.match(line):
            continue
        n += 1
        h, b = 0, 0
        for i, c in enumerate(line):
            if answer[i] == c:
                h += 1
            elif c in answer:
                b += 1
        print "%dH %dB" % (h, b)
        if h == 4:
            print "ooatari!"
            break
    print "kotae =", answer

if __name__ == "__main__":
    main()

aztgebwjaztgebwj2011/03/14 22:31pjs66w <a href="http://czihiwixrotg.com/">czihiwixrotg</a>, [url=http://rwtilatkaszv.com/]rwtilatkaszv[/url], [link=http://uuygxtruhdca.com/]uuygxtruhdca[/link], http://uwvzpmxawkms.com/

 |