bunch of changes
Some checks failed
Build / build (push) Failing after 5m54s
Publish Image / publish (push) Failing after 35s
Test / build (push) Failing after 5m46s

This commit is contained in:
Chuck Smith
2024-03-28 17:19:23 -04:00
parent 244b71d245
commit fb0cebaf56
16 changed files with 174 additions and 320 deletions

33
examples/fib.c Normal file
View File

@@ -0,0 +1,33 @@
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
int n = 35;
int fib(int x) {
if (x < 2) {
return x;
}
return fib(x - 1) + fib(x - 2);
}
int main(int argc, char *argv[]) {
if (argc > 1) {
char*p;
errno = 0;
long conv = strtol(argv[1], &p, 10);
// Check for errors: e.g., the string does not represent an integer
// or the integer is larger than int
if (errno != 0 || *p != '\0' || conv > INT_MAX || conv < INT_MIN) {
printf("invalid argument: %s\n", p);
exit(1);
}
n = conv;
}
printf("%d\n", fib(n));
}

25
examples/fib.go Normal file
View File

@@ -0,0 +1,25 @@
//go:build ignore
package main
import (
"fmt"
"os"
"strconv"
)
func fib(x int) int {
if x < 2 {
return x
}
return fib(x-1) + fib(x-2)
}
var n = 35
func main() {
if len(os.Args) > 2 {
n, _ = strconv.Atoi(os.Args[1])
}
fmt.Println(fib(n))
}

View File

@@ -7,7 +7,7 @@ fib := fn(x) {
N := 35
if (len(args()) == 1) {
if (len(args()) > 0) {
N = int(args()[0])
}

22
examples/fib.py Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env python3
import sys
print(sys.argv)
n = 35
def fib(x):
if (x < 2):
return x
return fib(x-1) + fib(x-2)
def main():
global n
if len(sys.argv) > 1:
n = int(sys.argv[1])
print("{}\n".format(fib(n)))
if __name__ == "__main__":
main()

10
examples/fib.tau Normal file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env tau
fib = fn(n) {
if n < 2 {
return n
}
fib(n-1) + fib(n-2)
}
println(fib(35))