2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

プログラミングで数値を増やしたり減らしてみた

2
Last updated at Posted at 2014-06-14

(元ネタ)
プログラミングで数値を増やしたり減らしてみたいんだが
http://blog.livedoor.jp/itsoku/archives/39361879.html

--

Pythonでやってみた

# size分だけの数値を増やしたり減らしたりするジェネレータ
def repeat_range(range_size, offset = 0):

	def repeat_gen():
		signed = 1
		i = -1

		while True:
			i += signed
			if i == 0 :
				signed = 1
			if i == range_size -1:
				signed = -1
			yield i + offset

	return repeat_gen()


# 1から4の繰り返しを作成
repeat4  = repeat_range(4, 1)

for i in range(10):
	print repeat4.next(),
結果
1 2 3 4 3 2 1 2 3 4
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?