Updated hw6 to a newer version

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-01-24 21:23:08 -08:00
parent 9224001a22
commit 0c04936ccf
356 changed files with 8408 additions and 4725 deletions

View file

@ -1,32 +0,0 @@
struct Node {
int i;
Node next;
bool hasNext
}
int minus(int x, int y) { return x - y; }
int plus(int x, int y) { return x + y; }
int fold_str_int(Node n, (int, int) -> int f, int base) {
if(n.hasNext) {
var newBase = f(base, n.i);
return fold_str_int(n.next, f, newBase);
} else {
return f(base, n.i);
}
}
int program(int argc, string[] argv) {
var n9 = new Node {i=9; next=Node null; hasNext=false};
var n8 = new Node {i=8; next=n9; hasNext=true};
var n7 = new Node {i=7; next=n8; hasNext=true};
var n6 = new Node {i=6; next=n7; hasNext=true};
var n5 = new Node {i=5; next=n6; hasNext=true};
var n4 = new Node {i=4; next=n5; hasNext=true};
var n3 = new Node {i=3; next=n4; hasNext=true};
var n2 = new Node {i=2; next=n3; hasNext=true};
var n1 = new Node {i=1; next=n2; hasNext=true};
return fold_str_int(n1, plus, 0) - fold_str_int(n1, minus, 2);
}