forked from CosmWasm/cosmwasm
-
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.
- Loading branch information
1 parent
89b69ef
commit e65ba57
Showing
2 changed files
with
39 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 |
---|---|---|
|
@@ -9,3 +9,6 @@ insert_final_newline = true | |
|
||
[*.rs] | ||
indent_size = 4 | ||
|
||
[*.py] | ||
indent_size = 4 |
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,36 @@ | ||
import functools | ||
|
||
# Create a funtion that executed f recusively n times, i.e. f**n | ||
def power(f, n): | ||
functions = [f for _ in range(n)] | ||
def compose2(f, g): | ||
return lambda x: f(g(x)) | ||
return functools.reduce(compose2, functions, lambda x: x) | ||
|
||
def riffle_shuffle(input): | ||
left = input[0:len(input)//2] | ||
right = input[len(input)//2:] | ||
i = 0 | ||
out = "" | ||
while i < len(input)//2: | ||
out += right[i] + left[i] | ||
i += 1 | ||
return out | ||
|
||
values = [ | ||
"alice123----------------", # 0 | ||
"alice485----------------", # 1 | ||
"aliceimwunderland521----", # 2 | ||
"bob1--------------------", # 3 | ||
"bob123------------------", # 4 | ||
"bob485------------------", # 5 | ||
"bob511------------------", # 6 | ||
"creator-----------------", # 7 | ||
] | ||
|
||
transform = power(riffle_shuffle, 18) | ||
transformed = [transform(v) for v in values] | ||
|
||
print("Original:\n" + "\n".join(sorted(values))) | ||
print() | ||
print("Shuffled:\n" + "\n".join(sorted(transformed))) |