Post Reply 
[VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
04-13-2019, 10:35 PM (This post was last modified: 04-14-2019 08:53 PM by Albert Chan.)
Post: #35
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
I recently created nextprime.lua, which is needed for solving Tier 2 puzzle.
My Lua code available in https://github.com/achan001/PrimePi

Quote:p = require 'nextprime'

function sb(base, n)
    local t, d = 0
    while n > 0 do
        d = n % base; t = t + d; n = (n-d)/base
    end
    return t
end

function sb_find(base, n)
    if not n then n=1 end
    return function()
        repeat n = p.nextprime(n) until not p.isprime(sb(base, n))
        return n
    end
end

lua> function loop(n,f) for i=1,n do io.write(f(),' ') end print() end

lua> seq=sb_find(7)
lua> loop(10,seq)
7 4801 9547 9601 11311 11317 11941 11953 13033 13327

lua> seq=sb_find(31)
lua> loop(10,seq)
31 619 709 739 769 829 859 919 1549 1579
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier" - Albert Chan - 04-13-2019 10:35 PM



User(s) browsing this thread: 1 Guest(s)