was noch so übrig war
crispy-caesus crispy@crispy-caesus.eu
Fri, 06 Mar 2026 23:20:47 +0100
20 files changed,
392 insertions(+),
0 deletions(-)
jump to
A
discord_programmieraufgaben/2025-10-27_3/shop.cpp
@@ -0,0 +1,38 @@
+#include <stdio.h> +#include <sqlite3.h> + +//using namespace std; + +static int callback(void *NotUsed, int argc, char **argv, char **azColName){ + int i; + for(i=0; i<argc; i++){ + printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); + } + printf("\n"); + return 0; +} + +int main(int argc, char **argv){ + sqlite3 *db; + char *zErrMsg = 0; + int rc; + + if( argc!=3 ){ + fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]); + return(1); + } + rc = sqlite3_open(argv[1], &db); + if( rc ){ + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + return(1); + } + rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg); + if( rc!=SQLITE_OK ){ + fprintf(stderr, "SQL error: %s\n", zErrMsg); + sqlite3_free(zErrMsg); + } + sqlite3_close(db); + return 0; +} +
A
discord_programmieraufgaben/2025-10-27_3/test.c
@@ -0,0 +1,35 @@
+#include <stdio.h> +#include <sqlite3.h> + +static int callback(void *NotUsed, int argc, char **argv, char **azColName){ + int i; + for(i=0; i<argc; i++){ + printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); + } + printf("\n"); + return 0; +} + +int main(int argc, char **argv){ + sqlite3 *db; + char *zErrMsg = 0; + int rc; + + if( argc!=3 ){ + fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]); + return(1); + } + rc = sqlite3_open(argv[1], &db); + if( rc ){ + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + return(1); + } + rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg); + if( rc!=SQLITE_OK ){ + fprintf(stderr, "SQL error: %s\n", zErrMsg); + sqlite3_free(zErrMsg); + } + sqlite3_close(db); + return 0; +}
A
gpt/2025-11-07/transponieren.c
@@ -0,0 +1,33 @@
+#include <stdio.h> + +int main() +{ + int m = 2, n = 3; + + int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; + + int t[3][2]; + + // Find transpose + for (int i = 0; i < m; i++) + { + for (int j = 0; j < n; j++) + { + t[j][i] = a[i][j]; + } + } + + // Display transpose + printf("Transpose of the matrix:\n"); + for (int i = 0; i < n; i++) + { + for (int j = 0; j < m; j++) + { + printf("%d ", t[i][j]); + } + printf("\n"); + } + + return 0; +} +
A
gpt/2025-11-07/union.c
@@ -0,0 +1,32 @@
+#include <assert.h> + +/* beende das Initialisieren der Flags */ + +const short FLAG_ON = 1 << 0; // 1 (0x01) +const short FLAG_MOVEMENT = 1 << 1; // 2 (0x02) +const short FLAG_TRANSPARENT = 1 << 2; // 4 (0x04) +const short FLAG_ALIVE = ; +const short FLAG_BROKEN = ; +const short FLAG_EDIBLE = 1 << 5; // 32 (0x20) + +int main() { + short attributes = 0; + + /* setze die Attribute ON, TRANSPARENT, und BROKEN */ + + assert(attributes == FLAG_ON | FLAG_TRANSPARENT | FLAG_BROKEN); + + /* verandere (set/clear/toggle) sodass die einzigen Attribute ON und ALIVE sind */ + + assert(attributes == FLAG_ON | FLAG_ALIVE); + + /* checke, ob das ALIVE flag gesetzt ist */ + assert(/* ??? */); + + /* checke, ob das BROKEN flag nicht gesetzt ist */ + assert(/* ??? */); + + /* verändere so, dass nur das EDIBLE Attribut gesetzt ist */ + + assert(attributes == FLAG_EDIBLE); +}
A
gpt/2025-12-03/log.go
@@ -0,0 +1,9 @@
+package main + +import( + "fmt" +) + +func main(){ + fmt.Println("hi") +}
M
gpt/2025-12-05/fakultaet.go
→
gpt/2025-12-05/fakultaet.go
@@ -40,6 +40,10 @@ eingabeString := os.Args[1]
eingabe, err := strconv.Atoi(eingabeString) check(err) + if eingabe < 0 { + panic("Zahl zu klein") + } + return eingabe }
A
gpt/2025-12-10/sorting_letters_heaps.c
@@ -0,0 +1,43 @@
+#include <stdio.h> + +#define N 10 + +void print_perm(const char *a, int n) { + for (int i = 0; i < n; i++) { + putchar(a[i]); + } + putchar('\n'); +} + +// Heap's algorithm (iterative form) +void heap_permutations(char *a, int n) { + int c[N] = {0}; // counters array + print_perm(a, n); + + int i = 0; + while (i < n) { + if (c[i] < i) { + // if i is even, swap a[0] and a[i] + // else swap a[c[i]] and a[i] + int swap_idx = (i % 2 == 0) ? 0 : c[i]; + char tmp = a[swap_idx]; + a[swap_idx] = a[i]; + a[i] = tmp; + + print_perm(a, n); + + c[i] += 1; + i = 0; + } else { + c[i] = 0; + i++; + } + } +} + +int main(void) { + char a[N] = {'a','b','c','d','e','f','g','h','i','j'}; + heap_permutations(a, N); + return 0; +} +
A
gpt/2025-12-10/sorting_letters_heaps.go
@@ -0,0 +1,77 @@
+package main + +import ( + "bufio" + "os" +) + +func letterSlice(n int) []byte { + if n <= 0 { + return []byte{} + } + if n > 26 { + n = 26 + } + + res := make([]byte, n) + for i := 0; i < n; i++ { + res[i] = 'a' + byte(i) + } + return res +} + +// Iterative Heap's algorithm with fast buffered output. +func permuteIterative(nums []byte, w *bufio.Writer) { + n := len(nums) + if n == 0 { + return + } + + // c is the control array for Heap's algorithm. + c := make([]int, n) + + // Helper to write one permutation. + writePerm := func() { + w.Write(nums) + w.WriteByte('\n') + } + + // Print the first permutation (initial order). + writePerm() + + i := 0 + for i < n { + if c[i] < i { + var swapIdx int + if i%2 == 0 { + swapIdx = 0 + } else { + swapIdx = c[i] + } + + // Swap + nums[swapIdx], nums[i] = nums[i], nums[swapIdx] + + // Print next permutation + writePerm() + + c[i]++ + i = 0 + } else { + c[i] = 0 + i++ + } + } +} + +func main() { + // Hardcode length 10: a..j + nums := letterSlice(10) + + // Buffered writer for much faster output than fmt.Printf in a tight loop. + w := bufio.NewWriter(os.Stdout) + defer w.Flush() + + permuteIterative(nums, w) +} +
A
gpt/2025-12-10/sorting_letters_recursive.go
@@ -0,0 +1,52 @@
+package main + +import "fmt" + +func permute(nums []byte, start int) { + if start == len(nums) { + fmt.Printf("%c\n", nums) + return + } + + n := len(nums) + for i := start; i < n; i++ { + nums[start], nums[i] = nums[i], nums[start] + permute(nums, start+1) + nums[start], nums[i] = nums[i], nums[start] + } +} + +func letterSlice(n int) []byte { + if n <= 0 { + return []byte{} + } + if n > 26 { + n = 26 + } + + res := make([]byte, n) + for i := 0; i < n; i++ { + res[i] = 'a' + byte(i) + } + return res +} + +func getIntFromUser() int { + var n int + //fmt.Print("Enter a number: ") + _, err := fmt.Scan(&n) + if err != nil { + fmt.Println("Error reading number:", err) + panic("Fehler") + } + + return n +} + + +func main() { + //size := getIntFromUser() + nums := letterSlice(10) + permute(nums, 0) +} +
A
gpt/2025-12-12/jasper/fak.go
@@ -0,0 +1,25 @@
+package main + +import ( + "os" + "encoding/binary" +) + +func check(e error) { + if e != nil { + panic(e) + } +} + +func writeInt64(filename string, n int64) { + f, err := os.Create(filename) + check(err) + defer f.Close() + + err = binary.Write(f, binary.LittleEndian, n) + check(err) +} + +func main() { + writeInt64("eingabe.bin", int64(54)) +}
A
gpt/2025-12-12/nicht_jasper/fak.go
@@ -0,0 +1,44 @@
+package main + +import ( + "os" + "encoding/binary" + "strconv" +) + +func check(e error) { + if e != nil { + panic(e) + } +} + +func writeString(filename string, n string) { + f, err := os.Create(filename) + check(err) + defer f.Close() + + err = binary.Write(f, binary.LittleEndian, n) + check(err) +} + +func readArg() int { + eingabeString := os.Args[1] + eingabe, err := strconv.Atoi(eingabeString) + check(err) + + return eingabe +} + +func fak(x int) int { + if x==0 { + return 1 + } + x = x * fak(x-1) + return x +} + +func main() { + eingabe := readArg() + ergebnis := fak(eingabe) + writeString("ergebnis.txt", string(ergebnis)) +}