Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Ruby recursive factorization

  1. Jan 8, 2017 #1
    mabe someone can help me with this code:

    i have this code, basically first i factorize for example the number 28 to: [2,2,7] and then i make a list of prime numbers and find the index of each factor in that list, so 2 is prime number with index 0 and 7 prime number with index 2 so it ends up like this: [[0],[0],[2]] with which another recursion would be: [[0],[0],[[0]]] which tranlated to binary would be: 1101101110111

    but im stuck on this:
    Code (Ruby):

    require 'prime'

    def f(n)

       Prime.prime_division(n).flat_map { |factor, power| [factor] *   power }



    puts n

    f=f (n)

    require 'prime'




    f.each do |j|

    if j>10


        g.push i



        g.push j



    print g
  2. jcsd
  3. Jan 8, 2017 #2


    User Avatar
    Science Advisor
    Gold Member

    It is not clear at least to me, what exactly you're trying to accomplish. Giving more explanation about that and putting some comments in your code would be helpful.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted