アルファベットの繰り上がり
Posted feedbacks - Ruby
1 2 | print "#{n = 'A'}"
99.times { print ", #{n.succ!}" }
|
1 | (1..100).inject("A"){|res,| puts res; res.succ}
|
1行
1 | puts (1...100).inject(s="A"){|r,| "#{r}, #{s.succ!}" }
|
succを見つけるのに時間が掛かってしまった。 初投稿なので生暖かい目でみてやってください。
1 2 3 4 5 6 7 | s='A';
NUM=100
NUM.times{ |n|
print s
print ", " if n != NUM-1
s.succ!
}
|
'A' をどうするか悩んだ。
1 | puts([s = 'A', (2..100).map{s = s.succ}].join(", "))
|
なるほど
1 | puts [*"A".."CV"]*","
|
わかりやすく
1 2 3 4 5 6 7 8 9 | s='A'
items=[]
(1..100).each{
items << s.clone
s.succ!
}
puts items.join(', ')
|
単純に考えてみました。
1 2 3 4 5 6 7 8 9 10 11 12 13 | n = ['','A','B','C','D','E','F','G','H','I','J','K','L', \
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
limit = 100;
res = [];
(0..26).each{|i|
(1..26).each{|j|
res.push(n[i] + n[j])
limit -= 1
break if limit < 1
}
break if limit < 1
}
puts res.join(', ')
|
26進数への変換と, 26進数のアルファベットへの変換を行なっているだけです.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | N = 3000
class Integer
def dec2n(n)
ary = Array.new
i = self
while 1
ary.unshift(i.modulo(n))
i = i.div(n)
break if i == 0
end
ary
end
def hexacos2alph
(self + 65).chr
end
end
p N.dec2n(26).map{|x| x.hexacos2alph}.join('')
|




にしお
#3377()
Rating0/0=0.00
この表記法で1から100までを表示してください。出力結果は下記のサンプルの「...」の部分に適切な文字列を埋めたものになります。
[ reply ]