-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lance-Drane <ldraneutk@gmail.com>
- Loading branch information
1 parent
45d6b55
commit 0541128
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
programs = list('abcdefghijklmnop') | ||
|
||
|
||
def swap(x: int, y: int): | ||
tmp = programs[y] | ||
programs[y] = programs[x] | ||
programs[x] = tmp | ||
|
||
|
||
for dance in input().split(','): | ||
move = dance[0] | ||
if move == 's': | ||
rotation = int(dance[1:]) | ||
programs = programs[-rotation:] + programs[:-rotation] | ||
else: | ||
x, y = dance[1:].split('/') | ||
if move == 'x': | ||
x, y = int(x), int(y) | ||
swap(x, y) | ||
else: # partner | ||
x, y = programs.index(x), programs.index(y) | ||
swap(x, y) | ||
print(programs) | ||
|
||
print(''.join(programs)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ebjpfdgmihonackl |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from itertools import count | ||
|
||
base_programs = list('abcdefghijklmnop') | ||
dances = input().split(',') | ||
|
||
|
||
def dance(programs: list[str]) -> list[str]: | ||
def swap(x: int, y: int): | ||
tmp = programs[y] | ||
programs[y] = programs[x] | ||
programs[x] = tmp | ||
|
||
for dance in dances: | ||
move = dance[0] | ||
if move == 's': | ||
rotation = int(dance[1:]) | ||
programs = programs[-rotation:] + programs[:-rotation] | ||
else: | ||
x, y = dance[1:].split('/') | ||
if move == 'x': | ||
x, y = int(x), int(y) | ||
swap(x, y) | ||
else: # partner | ||
x, y = programs.index(x), programs.index(y) | ||
swap(x, y) | ||
|
||
return programs | ||
|
||
|
||
programs = base_programs.copy() | ||
|
||
# find cycle | ||
for dance_iteration in count(start=1): # noqa: B007 (we use the value later) | ||
programs = dance(programs) | ||
if programs == base_programs: | ||
break | ||
|
||
# execute the cycle the appropriate number of times | ||
for _ in range(1_000_000_000 % dance_iteration): | ||
programs = dance(programs) | ||
|
||
print(''.join(programs)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abocefghijklmndp |
Large diffs are not rendered by default.
Oops, something went wrong.