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()
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)
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)
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)
def test_string3(self): self.assertEqual(scramble('katas', 'steak'), False)
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()
def checkScramble(word): scrambles = scramble.scramble(word) # (s1,s2) for tat in scrambles: if checkwords.is_words(tat): print "%s -> %s" % (word,tat)
# 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)
def test_string1(self): self.assertEqual(scramble('rkqodlw', 'world'), True)
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)
def scramble_default(n): moves = scramble.scramble(n).split() return moves
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()
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 라인 출력...
def test_string6(self): self.assertEqual(scramble('sermvihffsok', 'hizmdklesia'), False)
def do_scramble(self, line): """ prints out next scramble """ print("\n" + "Scramble: " + scramble.scramble() + "\n")
def test_string2(self): self.assertEqual(scramble('cedewaraaossoqqyt', 'codewars'), True)
def tester(func, items, trace=True): for args in scramble(items): if trace: print(args) print(sorted(func(*items)))