0

I don't understand what it code doing, please help.

How it will be working in python or in another simple language?

a = []
a << [1]

for i in 2..10001
    f = 0
    a.each{ |group|
        m = 1
        group.each { |c|
            m *= i % c
        }
        f += m
        if m > 0
            group << i
            break
        end
    }
    a << [i] if f == 0
end

p a
p a.size
6
  • 1
    Can you be more specific about what question you would like answered? Commented Oct 28, 2016 at 18:52
  • @Linuxios i don't understand clearly that code. Commented Oct 28, 2016 at 18:54
  • @Linuxios would be nice if someone show same program on another language, more simply Commented Oct 28, 2016 at 18:54
  • 1
    That is not what StackOverflow is for. Commented Oct 28, 2016 at 18:55
  • @DanielRoseman sorry if I broke the rules of stackoverflow can please you mention a few services that may help me Commented Oct 28, 2016 at 18:59

2 Answers 2

2

Literally translated to python this is:

a = []
a.append([1])

for i in range(2,10001 + 1):
    f = 0
    for group in a:
        m = 1
        for c in group:
            m *= i % c
        f += m
        if m > 0:
            group.append(i)
            break
    if f == 0:
        a.append([i])

print a
print len(a)
Sign up to request clarification or add additional context in comments.

Comments

0

In python:

a = []
a.append(1)

for i in range(2, 10000):
    f = 0
    for group in a:
        m = 1
        for c in group:
            m *= i%c
        f += m
        if m>0:
            group.append(i)
            break
    if not f:
        a.append(i)

print(a)
print(len(a))

4 Comments

Presumably the down-vote was for the wrong upper limit of range?
@JaredGoguen dunno. It's been a while since i did any ruby, so i'm not surprised i misremembered something, but i am surprised that someone would choose a loop bound of 10001
Even so, the upper bound on range would then be 10001 as it isn't inclusive.
In ruby a..b is a to b inclusive and a...b is a to b exclusive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.