Last active
May 29, 2017 09:06
-
-
Save ria3100/fc7ebf6c5d37357919f2 to your computer and use it in GitHub Desktop.
紙を折った回数Nに応じて山折り、谷折りの数をカウントする
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
# coding: utf-8 | |
''' | |
紙を上記のように折る回数Nが与えられるので | |
紙を折って広げたあとの山折り谷折りの折り目を計算する | |
プログラムを作成してください。 | |
http://paiza.hatenablog.com/entry/2016/02/15/ITエンジニアを目指す学生が、就活を有利に進める | |
''' | |
''' | |
備考: 標準入力で紙を折る回数Nを取得し、谷折りを 0 山折りを 1 として出力する | |
''' | |
def sort(temp): | |
ret = temp + [0] + temp | |
ret[len(temp) + 1 + len(temp)//2] = 1 | |
return ret | |
def recursive(N, temp=[0]): | |
if N == 1: | |
return temp | |
return recursive(N-1, sort(temp)) | |
N = int(input()) | |
print(recursive(N)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
最初の折り目が谷
それ以降、再帰処理で (N-1) + (最初の谷折り) + (N-1の中央を山折りにしたもの) が出力される
1.
0
2.
0 0 1
3.
001 0 011
4.
0010011 0 0011011