Last active
July 4, 2018 07:03
-
-
Save tobynet/eabecb12738dc0e56a7309e1ade6900c to your computer and use it in GitHub Desktop.
#54文字の文学賞 のジェネレータ https://ujiqn.github.io/54-novel/ に入れる用スクリプト
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
#!/usr/bin/env python | |
import numpy as np | |
message = \ | |
''' | |
あなたと | |
ジャバ | |
今すぐ | |
ダウンロ| | |
ド | |
''' | |
WIDTH = 9 | |
HEIGHT = 6 | |
# string -> [string] | |
lines = message.split("\n") | |
# Cut head and tail for unnecessary \n | |
if lines[0] == '' : lines = lines[1:] | |
if lines[-1] == '': lines = lines[:-1] | |
# 足りない長さを得る | |
# [string] -> int-> [string] | |
def fill_lines(lines, max_len): | |
# [string] -> [int] | |
missing_lens = [ max_len - len(x) for x in lines ] | |
# [string] -> [string] | |
filled_lines = [ s + " " * ml for s, ml in zip(lines, missing_lens) ] | |
return filled_lines | |
# [string] -> [[char]] | |
def to_list_list(xs): | |
return list(map(list, xs)) | |
# [[char]] -> [string] | |
def to_str_list(xs): | |
return list(map("".join, xs)) | |
# [string] -> [[string]] | |
array_lines = to_list_list(fill_lines(lines, HEIGHT)) | |
# rotation | |
# [[string]] -> [[string]] | |
rotated = np.rot90(array_lines, 1) | |
# [[string]] -> [string] | |
rotated_lines = fill_lines(to_str_list(rotated), WIDTH) | |
print("".join(rotated_lines)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://ujiqn.github.io/54-novel/ での実行例: