You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
const std = @import("std");
|
|
const PiFinder = @import("pi-finder");
|
|
|
|
/// This example demonstrates how to use the formatSearchResultAsPlainText function
|
|
/// to output search results in plain text format instead of JSON
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
defer _ = gpa.deinit();
|
|
const allocator = gpa.allocator();
|
|
|
|
// Path to the Pi file (relative to the main project)
|
|
const pi_file_path = "../../data/pi-decimal-10_000_000_000.txt";
|
|
|
|
// Initialize Pi Finder
|
|
var pi_finder = PiFinder.PiFinder.init(allocator, pi_file_path) catch |err| {
|
|
std.debug.print("Error initializing Pi finder: {}\n", .{err});
|
|
return;
|
|
};
|
|
defer pi_finder.deinit();
|
|
|
|
// Configure birth date
|
|
const birth_date = "010102"; // 01.01.02
|
|
|
|
// Context configuration with delimiter '-'
|
|
const context_config = PiFinder.ContextConfig{
|
|
.size = 50,
|
|
.position = 25,
|
|
.delimiter = "-",
|
|
.delimiter_interval = 2,
|
|
.prefix = "[",
|
|
.suffix = "]",
|
|
};
|
|
|
|
// Perform search
|
|
const result = try pi_finder.searchSequence(birth_date, context_config, allocator);
|
|
defer result.deinit();
|
|
|
|
// Output result as plain text
|
|
const plain_text_output = try PiFinder.formatSearchResultAsPlainText(allocator, result);
|
|
defer allocator.free(plain_text_output);
|
|
|
|
const stdout = std.io.getStdOut().writer();
|
|
try stdout.print("{s}\n", .{plain_text_output});
|
|
}
|
|
|