Created
April 11, 2026 18:47
-
-
Save theMackabu/ab1476f8bcc0dff5c8de3d351b993367 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| const Managed = std.math.big.int.Managed; | |
| pub fn main() !void { | |
| var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
| defer _ = gpa.deinit(); | |
| const allocator = gpa.allocator(); | |
| const n = 1_000_000; | |
| var a = try Managed.initSet(allocator, 0); | |
| defer a.deinit(); | |
| var b = try Managed.initSet(allocator, 1); | |
| defer b.deinit(); | |
| var c = try Managed.init(allocator); | |
| defer c.deinit(); | |
| var i: u32 = 0; | |
| while (i < n - 1) : (i += 1) { | |
| try c.add(a.toConst(), b.toConst()); | |
| a.swap(&b); | |
| b.swap(&c); | |
| } | |
| const res = try b.toString(allocator, 10, .lower); | |
| defer allocator.free(res); | |
| const out = std.io.getStdOut().writer(); | |
| try out.print("fib: {d}\n", .{res.len}); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment