There were some test cases that didn't pass on the day, With exactly the same logic, I rewrote it in Python and the test passed. (I still can't figure out the cause because it didn't work in Ruby ^^;)
The problem is the following URL http://nabetani.sakura.ne.jp/hena/ord24eliseq/
# -*- coding: utf-8 -*-
import sys
import math
from scipy.special import cbrt
from string import rstrip
max = 10000
sqrts = []
cbrts = []
for i in range(1,max):
if math.sqrt(i) - int(math.sqrt(i)) == 0:
sqrts.append(i)
if cbrt(i) - int(cbrt(i)) == 0:
cbrts.append(i)
if __name__ == '__main__':
while True:
input = list(sys.stdin.readline().rstrip())
ret = range(1,max)
for x in input:
count = 0
tmp = list(ret)
if x == 'S':
for r in ret:
for s in sqrts:
if r == s:
tmp[count + 1] = None
count += 1
ret = []
for y in tmp:
if y is not None:
ret.append(y)
elif x == 's':
for r in ret:
for s in sqrts:
if r == s:
tmp[count - 1] = None
count += 1
ret = []
for y in tmp:
if y is not None:
ret.append(y)
elif x == 'C':
for r in ret:
for s in cbrts:
if r == s:
tmp[count + 1] = None
count += 1
ret = []
for y in tmp:
if y is not None:
ret.append(y)
elif x == 'c':
for r in ret:
for s in cbrts:
if r == s:
tmp[count - 1] = None
count += 1
ret = []
for y in tmp:
if y is not None:
ret.append(y)
elif x == 'h':
ret = ret[100:]
else:
for y in range(0,len(ret),int(x)):
tmp[y-1] = None
ret = []
for y in tmp:
if y is not None:
ret.append(y)
print ','.join(str(x) for x in ret[0:10])