Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
30
Task/Catamorphism/Chipmunk-Basic/catamorphism.basic
Normal file
30
Task/Catamorphism/Chipmunk-Basic/catamorphism.basic
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
100 DIM n(10)
|
||||
110 FOR i = 1 TO 10 : n(i) = i : NEXT i
|
||||
120 SUB cat(cnt,op$)
|
||||
130 temp = n(1)
|
||||
140 FOR i = 2 TO cnt
|
||||
150 IF op$ = "+" THEN temp = temp+n(i)
|
||||
160 IF op$ = "-" THEN temp = temp-n(i)
|
||||
170 IF op$ = "*" THEN temp = temp*n(i)
|
||||
180 IF op$ = "/" THEN temp = temp/n(i)
|
||||
190 IF op$ = "^" THEN temp = temp^n(i)
|
||||
200 IF op$ = "max" THEN temp = FN MAX(temp,n(i))
|
||||
210 IF op$ = "min" THEN temp = FN MIN(temp,n(i))
|
||||
220 IF op$ = "avg" THEN temp = temp+n(i)
|
||||
230 IF op$ = "cat" THEN temp$ = temp$+STR$(n(i))
|
||||
240 NEXT i
|
||||
250 IF op$ = "avg" THEN temp = temp/cnt
|
||||
260 IF op$ = "cat" THEN temp = VAL(STR$(n(1))+temp$)
|
||||
270 cat = temp
|
||||
280 END SUB
|
||||
290 '
|
||||
300 PRINT " +: ";cat(10,"+")
|
||||
310 PRINT " -: ";cat(10,"-")
|
||||
320 PRINT " *: ";cat(10,"*")
|
||||
330 PRINT " /: ";cat(10,"/")
|
||||
340 PRINT " ^: ";cat(10,"^")
|
||||
350 PRINT "min: ";cat(10,"min")
|
||||
360 PRINT "max: ";cat(10,"max")
|
||||
370 PRINT "avg: ";cat(10,"avg")
|
||||
380 PRINT "cat: ";cat(10,"cat")
|
||||
390 END
|
||||
8
Task/Catamorphism/Zig/catamorphism-1.zig
Normal file
8
Task/Catamorphism/Zig/catamorphism-1.zig
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/// Asserts that `array`.len >= 1.
|
||||
pub fn reduce(comptime T: type, comptime applyFn: fn (T, T) T, array: []const T) T {
|
||||
var val: T = array[0];
|
||||
for (array[1..]) |elem| {
|
||||
val = applyFn(val, elem);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
26
Task/Catamorphism/Zig/catamorphism-2.zig
Normal file
26
Task/Catamorphism/Zig/catamorphism-2.zig
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const std = @import("std");
|
||||
|
||||
fn add(a: i32, b: i32) i32 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
fn mul(a: i32, b: i32) i32 {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
fn min(a: i32, b: i32) i32 {
|
||||
return @min(a, b);
|
||||
}
|
||||
|
||||
fn max(a: i32, b: i32) i32 {
|
||||
return @max(a, b);
|
||||
}
|
||||
|
||||
pub fn main() void {
|
||||
const arr: [5]i32 = .{ 1, 2, 3, 4, 5 };
|
||||
std.debug.print("Array: {any}\n", .{arr});
|
||||
std.debug.print(" * Reduce with add: {d}\n", .{reduce(i32, add, &arr)});
|
||||
std.debug.print(" * Reduce with mul: {d}\n", .{reduce(i32, mul, &arr)});
|
||||
std.debug.print(" * Reduce with min: {d}\n", .{reduce(i32, min, &arr)});
|
||||
std.debug.print(" * Reduce with max: {d}\n", .{reduce(i32, max, &arr)});
|
||||
}
|
||||
10
Task/Catamorphism/Zig/catamorphism-3.zig
Normal file
10
Task/Catamorphism/Zig/catamorphism-3.zig
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
const vec: @Vector(5, i32) = .{ 1, 2, 3, 4, 5 };
|
||||
std.debug.print("Vec: {any}\n", .{vec});
|
||||
std.debug.print(" * Reduce with add: {d}\n", .{@reduce(.Add, vec)});
|
||||
std.debug.print(" * Reduce with mul: {d}\n", .{@reduce(.Mul, vec)});
|
||||
std.debug.print(" * Reduce with min: {d}\n", .{@reduce(.Min, vec)});
|
||||
std.debug.print(" * Reduce with max: {d}\n", .{@reduce(.Max, vec)});
|
||||
}
|
||||
12
Task/Catamorphism/Zig/catamorphism-4.zig
Normal file
12
Task/Catamorphism/Zig/catamorphism-4.zig
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
const vec: @Vector(2, i32) = .{ std.math.minInt(i32), std.math.minInt(i32) + 1 };
|
||||
std.debug.print("Vec: {any}\n", .{vec});
|
||||
std.debug.print(" * Reduce with .Add: {d}\n", .{@reduce(.Add, vec)});
|
||||
std.debug.print(" * Reduce with .Mul: {d}\n", .{@reduce(.Mul, vec)});
|
||||
|
||||
var zero: usize = 0; // Small trick to make compiler not emit compile error for overflow below:
|
||||
std.debug.print(" * Reduce with regular add operator: {d}\n", .{vec[zero] + vec[1]});
|
||||
std.debug.print(" * Reduce with regular mul operator: {d}\n", .{vec[zero] * vec[1]});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue