{"id":625,"date":"2018-07-28T23:43:18","date_gmt":"2018-07-28T23:43:18","guid":{"rendered":"http:\/\/perfectionatic.org\/?p=625"},"modified":"2018-07-28T23:43:18","modified_gmt":"2018-07-28T23:43:18","slug":"exploring-left-truncatable-primes","status":"publish","type":"post","link":"https:\/\/perfectionatic.org\/?p=625","title":{"rendered":"Exploring left truncatable primes"},"content":{"rendered":"<p>Recently I came across a fascinating Numberphile video on truncatable primes<br \/>\n<iframe loading=\"lazy\" title=\"357686312646216567629137 - Numberphile\" width=\"740\" height=\"416\" src=\"https:\/\/www.youtube.com\/embed\/azL5ehbw_24?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>I immediately thought it would be cool to whip a quick Julia code to get the full enumeration of all left truncatable primes, count the number of branches and also get the largest left truncatable prime.<\/p>\n<pre lang=\"julia\">\nusing Primes\n\nfunction get_left_primes(s::String)\n    p_arr=Array{String,1}()\n    for i=1:9\n        number_s=\"$i$s\"\n        if isprime(parse(BigInt, number_s))\n            push!(p_arr,number_s)\n        end\n    end\n    p_arr\nend\n\nfunction get_all_left_primes(l)\n    r_l= Array{String,1}()\n    n_end_points=0\n    for i in l\n        new_l=get_left_primes(i)\n        isempty(new_l) && (n_end_points+=1)\n        append!(r_l,new_l)\n        next_new_l,new_n=get_all_left_primes(new_l)\n        n_end_points+=new_n # counting the chains\n        append!(r_l,next_new_l)\n    end\n    r_l, n\nend\n<\/pre>\n<p>The first function just prepends a number (expressed in String for convenience) and checks for it possible primes that can emerge from a single digit prepending. For example:<\/p>\n<pre lang=\"julia\">\njulia> get_left_primes(\"17\")\n2-element Array{String,1}:\n \"317\"\n \"617\"\n<\/pre>\n<p>The second function, just makes extensive use of the first to get all left truncatable primes and also count the number of branches.<\/p>\n<pre lang=\"julia\">\njulia> all_left_primes, n_branches=get_all_left_primes([\"\"])\n(String[\"2\", \"3\", \"5\", \"7\", \"13\", \"23\", \"43\", \"53\", \"73\", \"83\"  \u2026  \"6435616333396997\", \"6633396997\", \"76633396997\", \"963396997\", \"16396997\", \"96396997\", \"616396997\", \"916396997\", \"396396997\", \"4396396997\"], 1442)\n\njulia> n_branches\n1442\n\njulia> all_left_primes\n4260-element Array{String,1}:\n \"2\"\n \"3\"\n \"5\"\n \"7\"\n \"13\"\n \"23\"\n \u22ee\n \"96396997\"\n \"616396997\"\n \"916396997\"\n \"396396997\"\n \"4396396997\"\n<\/pre>\n<p>So we the full list of possible left truncatable primes with a length 4260. Also the total number of branches came to 1442.<\/p>\n<p>We now get the largest left truncatable primes with the following one liner:<\/p>\n<pre lang=\"julia\">\njulia> largest_left_prime=length.(all_left_primes)|>indmax|> x->all_left_primes[x]\n\"357686312646216567629137\"\n<\/pre>\n<p>After this fun exploration, I found an implementation in Julia for just getting the largest left truncatable prime for any base in <a href=\"https:\/\/rosettacode.org\/wiki\/Find_largest_left_truncatable_prime_in_a_given_base#Julia\">Rosseta Code<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I came across a fascinating Numberphile video on truncatable primes I immediately thought it would be cool to whip a quick Julia code to get the full enumeration of all left truncatable primes, count the number of branches and also get the largest left truncatable prime. using Primes function get_left_primes(s::String) p_arr=Array{String,1}() for i=1:9 number_s=&#8221;$i$s&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74,73,62],"tags":[92],"class_list":["post-625","post","type-post","status-publish","format-standard","hentry","category-julia","category-julialang","category-math","tag-julia"],"_links":{"self":[{"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/posts\/625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=625"}],"version-history":[{"count":10,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/posts\/625\/revisions"}],"predecessor-version":[{"id":635,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=\/wp\/v2\/posts\/625\/revisions\/635"}],"wp:attachment":[{"href":"https:\/\/perfectionatic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/perfectionatic.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}