Skip to content

Instantly share code, notes, and snippets.

@tompng
Created July 27, 2025 14:16
Show Gist options
  • Save tompng/6ada3261f7d43d8a8eb09b2a409b1b33 to your computer and use it in GitHub Desktop.
Save tompng/6ada3261f7d43d8a8eb09b2a409b1b33 to your computer and use it in GitHub Desktop.

Revisions

  1. tompng created this gist Jul 27, 2025.
    31 changes: 31 additions & 0 deletions manyzero.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    def euclidsolve(cx, cy, c, small)
    return euclidsolve(cy, cx, c, small).reverse if cx > cy
    # cx <= cy
    # x * cx + y * cy = c + small
    # p [cx.to_f, cy.to_f, c.to_f, small.to_f]
    if small >= cy
    # cx <= cy, c < cy
    # cx*x + cy*y == c + small
    # x=0; cy*y == c + small
    return [0, 1]
    end
    x, y = euclidsolve(cx, cy % cx, c % cx, small)
    # x * cx + y * (cy%cx) == c%cx + small
    # (x+dx) * cx + (y+dy) * (cy%cx + (cy/cx)*cx) == c%cx + (c/cx)*cx + small
    # dx * cx + dy + (y+dy) * (cy/cx)*cx == (c/cx)*cx
    [x + (c/cx) - y * (cy/cx), y]
    end

    x,y=euclidsolve(cx=2**622, cy=10**187, c=10**(187-16)/2, small=2**(621-53))
    (53..1024).each do |bit|
    exp10 = (-400..400).bsearch{
    2**bit<10**it
    }-1
    x,y=euclidsolve(cx=2**bit, cy=10**exp10, c=10**(exp10-16)/2, small=2**(bit-1-53))
    if x.abs.bit_length <= 53
    f=(x*2**bit)
    match = f.to_s[/^\d{14}+0{5,}+[1-9]|^\d{14}9{5,}+[0-8]/]
    p [match.size, match, f.to_f] if match && match.size > 16
    end
    rescue
    end