Project1
标题: 大家来亮出自己的脑洞做一个长数组 [打印本页]
作者: 有丘直方 时间: 2016-7-19 15:05
标题: 大家来亮出自己的脑洞做一个长数组 本帖最后由 有丘直方 于 2016-7-21 18:11 编辑
就是用某种方法让ruby输出一个[1,2,3,...,100]的数组。
注意请不要用诸如ary = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 ]
p ( ary)
ary = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 ]
p ( ary)
的非常没用的方法。我先来一个,我敢打赌肯定没人想到
进入下面链接可查看各位童鞋提供的代码:https://rpg.blue/forum.php?mod=r ... 733&pid=2689341
作者: 英顺的马甲 时间: 2016-7-19 15:15
本帖最后由 英顺的马甲 于 2016-7-19 16:01 编辑
print "[%s]" % 100 .times .to_a .map { |i|i+1 } .join ( ", " )
print "[%s]" % 100 .times .to_a .map { |i|i+1 } .join ( ", " )
a=0 ;p Array .new ( 100 ) .map { a+=1 }
a=0 ;p Array .new ( 100 ) .map { a+=1 }
p "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]" # 没说不让这样啊
p "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]" # 没说不让这样啊
再来一个:p [ a=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 ]
p [ a=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 , a+=1 ]
另外两个:$a [ $i||=0 ] = $i +=1 while ( $a||=[ ] ) .size < 100 ; p $a
$a [ $i||=0 ] = $i +=1 while ( $a||=[ ] ) .size < 100 ; p $a
i=0 ;print "[" ;print "%d, " % i+=1 while i < 100 ;print "%d]" % i
i=0 ;print "[" ;print "%d, " % i+=1 while i < 100 ;print "%d]" % i
作者: 喵呜喵5 时间: 2016-7-19 16:15
本帖最后由 喵呜喵5 于 2016-7-19 16:43 编辑
p Array.new(100){|i| i+1} 复制代码 p [].tap{|a| a << a.size+1 until a.size == 100} 复制代码
作者: H·H·Y 时间: 2016-7-19 16:23
不懂你们这些脚本触
作者: 余烬之中 时间: 2016-7-19 16:51
本帖最后由 余烬之中 于 2016-7-19 16:53 编辑
p 101.times.to_a.tap &:shift 复制代码
作者: iisnow 时间: 2016-7-19 17:37
ary = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81
, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61
, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41
, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21
, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].reverse
作者: 寒冷魔王 时间: 2016-7-19 18:40
本帖最后由 寒冷魔王 于 2016-7-19 18:45 编辑
喵呜酱说的前两个是最实用的方法,,个人姑且说两个:
def func(n, a = [])
n.zero? ? a : func(n-1,a.push(n))
end
func(100).reverse 复制代码
func = ->(n = 0) { -> { n += 1 } }.call
100.times.collect { func.call }
# 或者 Array.new(100) { func.call }
复制代码
作者: 有丘直方 时间: 2016-7-19 19:08
我每日评分上限只有20经验,明天给各位发经验了
作者: taroxd 时间: 2016-7-19 20:06
本帖最后由 taroxd 于 2016-7-19 20:20 编辑
没人说这个吗
来个无聊的
p << .chomp .split ( ' ' ) .map ( &:length)
p << .chomp .split ( ' ' ) .map ( &:length)
作者: 英顺的马甲 时间: 2016-7-19 20:50
本帖最后由 英顺的马甲 于 2016-7-19 20:51 编辑
p "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZA==" .unpack ( 'm0' ) .first .unpack ( 'C*' )
p "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZA==" .unpack ( 'm0' ) .first .unpack ( 'C*' )
作者: 有丘直方 时间: 2016-7-20 12:29
本帖最后由 有丘直方 于 2016-7-21 17:11 编辑
=begin
<<=============================================>>
<< [随意闲聊] 大家来亮出自己的脑洞做一个长数组 >>
<<=============================================>>
就是用某种方法让ruby输出一个[1,2,3,...,100]的数组。
注意请不要用诸如
ary = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
p(ary)
的非常没用的方法。
=end
#------------------------------------------------
# 有丘直方
#------------------------------------------------
str = "def a; " * 100
for i in 1...100
str += "#{101 - i}; end; "
end
str += "#{1} ;end"
eval(str)
ary = eval("[" + "a, " * 99 + "a]")
p(ary)
#------------------------------------------------
# 英顺的马甲
#------------------------------------------------
print "[%s]" % 100.times.to_a.map{|i|i+1}.join(", ")
#~ print("[%s]" % 100.times.to_a.map { |i| i+1 }.join(", ") + "/n")
#------------------------------------------------
# 英顺的马甲
#------------------------------------------------
a=0;p Array.new(100).map{a+=1}
#~ a = 0
#~ p(Array.new(100).map { a += 1 })
#------------------------------------------------
# 英顺的马甲
#------------------------------------------------
p "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]" # 没说不让这样啊
#~ print("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]") # 太耍赖。
#------------------------------------------------
# 英顺的马甲
#------------------------------------------------
p [a=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1]
#~ # 太耍赖。
#------------------------------------------------
# 英顺的马甲
#------------------------------------------------
$a[$i||=0] = $i+=1 while ($a||=[]).size < 100; p $a
#~ $a[$i || = 0] = $i += 1 while ($a || = []).size < 100
#~ p($a)
#------------------------------------------------
# 英顺的马甲
#------------------------------------------------
i=0;print "[";print "%d, " % i+=1 while i < 100;print "%d]" % i
#~ i = 0
#~ print("[")
#~ print("%d, " % i += 1) while i < 100
#~ print("%d]" % i)
#------------------------------------------------
# 喵呜喵5
#------------------------------------------------
p (1..100).to_a
#------------------------------------------------
# 喵呜喵5
#------------------------------------------------
p Array.new(100){|i| i+1}
#~ p(Array.new(100) { |i| i + 1 })
#------------------------------------------------
# 喵呜喵5
#------------------------------------------------
p [].tap{|a| a << a.size+1 until a.size == 100}
#~ p([].tap { |a| a << a.size + 1 until a.size == 100 })
#------------------------------------------------
# 余烬之中
#------------------------------------------------
def func(n, a = [])
n.zero? ? a : func(n-1,a.push(n))
end
func(100).reverse
#~ def func(n, a = [])
#~ n.zero? ? a : func(n - 1, a.push(n))
#~ end
#~ p(func(100).reverse)
#------------------------------------------------
# 余烬之中
#------------------------------------------------
func = ->(n = 0) { -> { n += 1 } }.call
100.times.collect { func.call }
# 或者 Array.new(100) { func.call }
#~ func = -> (n = 0) { -> { n += 1 } }.call
#~ p(100.times.collect { func.call })
#~ p(Array.new(100) { func.call })
#------------------------------------------------
# iisnow
#------------------------------------------------
ary = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].reverse
#~ p([100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].reverse) # 太耍赖。
#------------------------------------------------
# taroxd
#------------------------------------------------
[*1..100]
[*1.upto(100)]
#~ p([*1..100])
#~ p([*1.upto(100)])
#------------------------------------------------
# taroxd
#------------------------------------------------
p << .chomp.split(' ').map(&:length)
#~ # 各位要获取这条代码的,注意把空格复制全啊。
#~ "p << .chomp.split(' ').map(&:length)\n" + (1..100).map{|i| ' ' * i}.join(?\s) + "\n \n" # 寒冷魔王
#------------------------------------------------
# 英顺的马甲
#------------------------------------------------
p "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZA==".unpack('m0').first.unpack('C*')
#~ # 这……算耍赖吗?
#------------------------------------------------
# 有丘直方
#------------------------------------------------
str = "["
for i in 1...100
str += "#{i}, "
end
ary = eval(str + "#{100}]")
p(ary)
#------------------------------------------------
# 有丘直方
#------------------------------------------------
p(eval("[a = 1, " + "a += 1, " * 98 + "a += 1]"))
复制代码
作者: 正太君 时间: 2016-7-20 12:42
100个数字99个逗号不累吗?咿咿...
作者: orochi2k 时间: 2016-7-20 19:49
本帖最后由 orochi2k 于 2016-7-20 19:53 编辑
楼上的童鞋们把代码封成函数我来调用。
否则我就拿RUBY直接从网页上读了(用页面明文检查关键字“复制代码”和“复制 打印”然后拖走整个代码块)。(大雾)
我就是不想自己写,灭哈哈哈哈哈哈(大雾)
作者: 有丘直方 时间: 2016-7-20 20:19
# 鸡肋
ary = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
p(ary)
# 有丘直方
str = "def a; " * 100
for i in 1...100
str += "#{101 - i}; end; "
end
str += "#{1} ;end"
eval(str)
ary = eval("[" + "a, " * 99 + "a]")
p(ary)
# 英顺的马甲
print "[%s]" % 100.times.to_a.map{|i|i+1}.join(", ")
#~ print("[%s]" % 100.times.to_a.map{ |i| i+1 }.join(", ") + "/n")
# 英顺的马甲
a=0;p Array.new(100).map{a+=1}
#~ a = 0
#~ p(Array.new(100).map{ a += 1 })
# 英顺的马甲
p "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]" # 没说不让这样啊
#~ # 你这是在耍赖
# 英顺的马甲
p [a=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1, a+=1]
#~ # 太耍赖
# 英顺的马甲
$a[$i||=0] = $i+=1 while ($a||=[]).size < 100; p $a
#~ $a[$i|| = 0] = $i += 1 while ($a|| = []).size < 100
#~ p($a)
# 英顺的马甲
i=0;print "[";print "%d, " % i+=1 while i < 100;print "%d]" % i
#~ i=0
#~ print("[")
#~ print("%d, " % i += 1) while i < 100
#~ print("%d]" % i)
# 喵呜喵5
p (1..100).to_a
# 喵呜喵5
p Array.new(100){|i| i+1}
# 喵呜喵5
p [].tap{|a| a << a.size+1 until a.size == 100}
# 余烬之中
def func(n, a = [])
n.zero? ? a : func(n-1,a.push(n))
end
func(100).reverse
# 余烬之中
func = ->(n = 0) { -> { n += 1 } }.call
100.times.collect { func.call }
# 或者 Array.new(100) { func.call }
# iisnow
ary = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81
, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61
, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41
, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21
, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1].reverse
#~ # 太耍赖
# taroxd
[*1..100]
[*1.upto(100)]
#~ p([*1..100])
#~ p([*1.upto(100)])
# taroxd
p << .chomp.split(' ').map(&:length)
#~ # => can't convert false into String
#~ "p << .chomp.split(' ').map(&:length)\n" + (1..100).map{|i| ' ' * i}.join(?\s) + "\n \n" # 余烬之中
# 英顺的马甲
p "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZA==".unpack('m0').first.unpack('C*')
#~ # 这……算耍赖吗?
str = "["
for i in 1...100
str += "#{i}, "
end
ary = eval(str + "#{100}]")
p(ary) 复制代码 楼上几位的代码帮你整理了一下,你自己去封函数吧!
作者: 有丘直方 时间: 2016-7-21 11:44
本帖最后由 有丘直方 于 2016-7-22 12:08 编辑
str = "["
for i in 1...100
str += "#{i}, "
end
ary = eval(str + "#{100}]")
p(ary) 复制代码 p(eval("[a = 1, " + "a += 1, " * 98 + "a += 1]")) 复制代码 print("[#{i = 1}, ")
print("#{i += 1}, ") until i >= 99
print("#{i += 1}]\n") 复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1