Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#54文字の文学賞 のジェネレータ https://ujiqn.github.io/54-novel/ に入れる用スクリプト
#!/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))
@tobynet

This comment has been minimized.

Copy link
Owner Author

tobynet commented Jul 4, 2018

動作例:

$ python rotation-string-for-54-novel.py
     |    とバ  ロ    たャ ぐンド   なジ すウ    あ  今ダ
@tobynet

This comment has been minimized.

Copy link
Owner Author

tobynet commented Jul 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.