Created
May 2, 2012 04:56
-
-
Save bgnori/2573845 to your computer and use it in GitHub Desktop.
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
def shortest(*rs): | |
i = 0; | |
while True: | |
for r in rs: | |
try: | |
x = r[i] | |
except IndexError: | |
return r | |
i += 1 | |
pass | |
print shortest([1, 2], [3, 4, 5], [6, 7]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ujihisa
[問] 配列の配列から、一番要素の短いものを取得する関数shortestを書け
候補が複数ある場合は、そのうちどれを返しても正解とする。
shortest([1, 2], [3, 4, 5], [6, 7]) == [1, 2]
ただし、引数として無限長の配列が与えられる場合もある。
少なくともひとつの有限長の配列があるときに計算が終了するようせよ。
s/配列/リスト/g