View Single Post
Old 2012-01-05, 06:12   #59
firejuggler
 
firejuggler's Avatar
 
Apr 2010
Over the rainbow

2·1,217 Posts
Default

Writing sequence with only one "->" really helped.
It was stupid to think about writing the entire sequence in one go.
to get the odd in plaintext and the circle shape for "perfect" change the second loop to
Code:
    for i=3, range do                        -- for the given range try to make the sequences
        while sigma[i] ~= nil and nsigma[i] ~= nil do        -- avoid to display lonely values, which were never reached
            if sigma[i] > 100000 then            -- maximum reached -> display as "Open Sequence"
                io.write(i.."[label=\"OpenSeq\",shape=plaintext];\n")
                nsigma[i] = nil
                break
            end

            if sigma[i] == 1 then                -- values reached is prime -> mark as "Prime"
                io.write(i.."[label=\""..i.."p\",shape=plaintext];\n")
            else
                io.write(i.."->"..sigma[i].."\n")    -- else normal value
                if i==sigma[i] then io.write(i.."[shape=circle];\n") end
            end
            nsigma[i] = nil                    -- mark edge as already printed (no doubles)
            i = sigma[i]
            if i%2==1 then io.write(i.."[shape=plaintext];\n") end
        end
    end
now the hard part, to detect "merge".
boxes should happen what at least 2 arrow point to a number
and triangle should (that will probably hard and need a third loop) happen when the lowest even number leading to that merge

Code:
102->114
114->126
126->186
174->186
186[shape=box];
102[shape=triangle];
firejuggler is offline   Reply With Quote