21 lines
452 B
Zig
21 lines
452 B
Zig
const std = @import("std");
|
|
const mem = std.mem;
|
|
|
|
const FactorErrors = error{FactorOfZero};
|
|
|
|
pub fn sum(allocator: mem.Allocator, factors: []const u32, limit: u32) !u64 {
|
|
_ = allocator;
|
|
var s: u64 = 0;
|
|
for (0..limit) |i| {
|
|
for (factors) |f| {
|
|
if (f == 0) {
|
|
continue;
|
|
}
|
|
if (i % f == 0) {
|
|
s += i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return s;
|
|
}
|