Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Repeat-a-string/Zig/repeat-a-string-1.zig
Normal file
1
Task/Repeat-a-string/Zig/repeat-a-string-1.zig
Normal file
|
|
@ -0,0 +1 @@
|
|||
const laugh = "ha" ** 5;
|
||||
21
Task/Repeat-a-string/Zig/repeat-a-string-2.zig
Normal file
21
Task/Repeat-a-string/Zig/repeat-a-string-2.zig
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
const std = @import("std");
|
||||
const warn = std.debug.warn;
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
fn repeat(s: []const u8, times: u16, allocator: *Allocator) ![]u8 {
|
||||
const repeated = try allocator.alloc(u8, s.len*times);
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < s.len*times) : (i += 1) {
|
||||
repeated[i] = s[i % 2];
|
||||
}
|
||||
|
||||
return repeated;
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
const allocator = std.debug.global_allocator;
|
||||
const ex = try repeat("ha", 5, allocator);
|
||||
defer allocator.free(ex);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue