def test_rand(self):
        from random import randint, choices, shuffle
        from collections import Counter
        base = "abcdefghijklmnopqrstuvwxyz"

        def solver(s1, s2):
            return len(Counter(s2) - Counter(s1)) == 0

        for _ in range(500):
            s1 = ''.join(choices(base, k=randint(10, 20)))
            if randint(0, 1):
                s2 = ''.join(choices(base, k=randint(10, 20)))
            else:
                s2 = list(s1)
                shuffle(s2)
                s2 = ''.join(s2)
            self.assertEqual(scramble(s1, s2), solver(s1, s2),
                             "It should work with random inputs too")

        for _ in range(10):
            s1 = ''.join(choices(base, k=600000))
            if randint(0, 1):
                s2 = ''.join(choices(base, k=600000))
                self.assertEqual(scramble(s1, s2), False,
                                 "It should work with random inputs too")
            else:
                s2 = list(s1)
                shuffle(s2)
                s2 = ''.join(s2)
                self.assertEqual(scramble(s1, s2), True,
                                 "It should work with random inputs too")
 def test(self):
     self.assertEqual(scramble('rkqodlw', 'world'), True)
     self.assertEqual(scramble('cedewaraaossoqqyt', 'codewars'), True)
     self.assertEqual(scramble('katas', 'steak'), False)
     self.assertEqual(scramble('scriptjavx', 'javascript'), False)
     self.assertEqual(scramble('scriptingjava', 'javascript'), True)
     self.assertEqual(scramble('scriptsjava', 'javascripts'), True)
     self.assertEqual(scramble('javscripts', 'javascript'), False)
     self.assertEqual(scramble('aabbcamaomsccdd', 'commas'), True)
     self.assertEqual(scramble('commas', 'commas'), True)
     self.assertEqual(scramble('sammoc', 'commas'), True)
def begin_game(enevt):
    scramble(UP_COLOR, DOWN_COLOR, FRONT_COLOR, BACK_COLOR, LEFT_COLOR,
             RIGHT_COLOR)
    global ud
    global flag
    global start_time
    if ud == 1:
        canvas.delete(ALL)
        color_the_cube_WITH_UP(window)
    else:
        canvas.delete(ALL)
        color_the_cube_WITH_DOWN(window)
    flag = 1
    start_time = time.time()
Beispiel #4
0
 def nextsolve(self):
     self.scramble = scramble.scramble()
     print("\n" + "Scramble: " + self.scramble + "\n")
     print('0.00', end='\r')
     self.lasttimer = self.timer
     self.timer = Timer()
     time.sleep(0.5)
Beispiel #5
0
 def nextsolve(self):
     print(self.history)
     self.scramble = scramble.scramble()
     playcube.Cubemode(self.scramble, printall=True)
     print("\n" + "Scramble: " + ' '.join(self.scramble) + "\n")
     if self.timer:
         print('{:.2f}'.format(self.timer.gettime()), end='\r')
     else:
         print('0.00', end='\r')
     self.lasttimer = self.timer
     self.timer = Timer()
     time.sleep(0.5)
Beispiel #6
0
 def interactive(self):
     while True:
         c = getch()  # commands:
         if c == "p":  # p = scrambles the cube
             self.feedCube(scramble.scramble())
         if c == "q":  # q = exit cubemode
             return -1
         if c == "n":  # n = loads new cube(solved)
             self.cube = loadCube()
             print(self.cube)
         if c.lower() in {"u", "f", "l", "r", "b", "d", "m", "e", "s"}:  # moves the slice (shift inverts move)
             self.cube.move(c)
             print(self.cube)
         if c.lower() in {"x", "y", "z"}:
             for turn in opscube.rotMoves(c):
                 self.cube.move(turn)
             print(self.cube)
         if c == "1":
             doublemove = opscube.doubleMoves("d")
             for move in doublemove:
                 self.cube.move(move)
             print(self.cube)
Beispiel #7
0
 def test_string3(self):
     self.assertEqual(scramble('katas', 'steak'), False)
Beispiel #8
0
        s.Gen()


def saveTimes():

    saves = open("saves.save", "w")
    for tim in timer.times:
        print(tim)
        saves.write(str(tim) + "\n")
        #timer.times.remove(tim)
    saves.close()


root = Tk()
root.title("Cube Timer")

root.bind("<KeyRelease>", space)

save = Button(root)
save.grid(row=0, column=0)
save.config(text="Save", command=saveTimes)

timer = timer.timer(root, 2, 0)

s = scramble.scramble(root, 1, 0)
s.Gen()

timer.update()

root.mainloop()
Beispiel #9
0
def checkScramble(word):
    scrambles = scramble.scramble(word)
    # (s1,s2)
    for tat in scrambles:
        if checkwords.is_words(tat):
            print "%s -> %s" % (word,tat) 
Beispiel #10
0
# drawing the lines on the screen
def drawLines():
    for i in range(18):
        pygame.draw.line(screen, (50, 50, 50), (100 * i, 0), (100 * i, 900),
                         width=3)
    for i in range(10):
        pygame.draw.line(screen, (50, 50, 50), (0, 100 * i), (1800, 100 * i),
                         width=3)


face = 1
running = True

# scrambling the cube using the scramble function in scramble.oy file
scramble(cube)

# printin the cube for debugging purposes
print(cube)
drawButtons()
drawLines()
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit(),
            sys.exit()

        if event.type == pygame.MOUSEBUTTONUP:
            mouseX = event.pos[0]
            mouseY = event.pos[1]
            doMove(mouseX, mouseY, face)
Beispiel #11
0
 def test_string1(self):
     self.assertEqual(scramble('rkqodlw', 'world'), True)
Beispiel #12
0
 def check_scramble(self, tat):
     scrambles = scramble.scramble(tat)
     for scrambled_tat in scrambles:
         if self.is_words(scrambled_tat):
             print "%s -> %s" % (tat, scrambled_tat)
Beispiel #13
0
def scramble_default(n):
	moves = scramble.scramble(n).split()
	return moves
Beispiel #14
0
from scramble import scramble
from sys import stdout
import argparse

parser = argparse.ArgumentParser(
    prog='Sarcmlebr',
    usage=
    'Given a file or some text, it scramble the middle letters of the words and prints the output to stdout'
)
parser.add_argument('--text', help='Text to scramble', type=str, default=None)
parser.add_argument('--file', help='File to scramble', type=str, default=None)
args = parser.parse_args()

if args.text is None and args.file is None:
    print('Please specify either the --file or --text argument !')
    exit(202)

if args.text is not None and args.file is not None:
    print('Please specify either the --file or --text argument, not both !')
    exit(202)

if args.text is not None:
    original_text = args.text
else:
    with open(args.file, 'r', encoding='utf-8') as f:
        original_text = f.read()

stdout.buffer.write(scramble(original_text).encode('utf8'))
stdout.buffer.write(str('\n').encode('utf8'))
stdout.flush()
Beispiel #15
0
 def test_string5(self):
     self.assertEqual(scramble('scriptingjava', 'javascript'), True)

def permute2(seq):
    if not seq:  # 모든 시퀀스 섞기: 제너레이터
        yield seq  # 빈 시퀀스
    else:
        for i in range(len(seq)):
            rest = seq[:i] + seq[i + 1:]  # 현재 노드 삭제
            for x in permute2(rest):  # 나머지들의 순열
                yield seq[i:i + 1] + x  # 앞쪽에 노드 추가


from scramble import scramble
from permute import permute1, permute2

list(scramble('abc'))  # 단순 뒤섞기: N
# ['abc', 'bca', 'cab']

permute1('abc')  # 가장 큰 순열: N
# ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
list(permute2('abc'))  # 모든 조합 생성
# ['abc', 'acb', 'bac', 'bca', 'cab', 'cba']

G = permute2('abc')  # 반복(iter()는 불필요함)
next(G)
# 'abc'
next(G)
# 'acb'
for x in permute2('abc'):
    print(x)  # 자동 반복
# ...6 라인 출력...
Beispiel #17
0
 def test_string6(self):
     self.assertEqual(scramble('sermvihffsok', 'hizmdklesia'), False)
Beispiel #18
0
 def do_scramble(self, line):
     """ prints out next scramble """
     print("\n" + "Scramble: " + scramble.scramble() + "\n")
Beispiel #19
0
 def test_string2(self):
     self.assertEqual(scramble('cedewaraaossoqqyt', 'codewars'), True)
Beispiel #20
0
def tester(func, items, trace=True):
    for args in scramble(items):
        if trace: print(args)
        print(sorted(func(*items)))