From e92ee9005075ee10e0d4e8831003d76701a2df13 Mon Sep 17 00:00:00 2001 From: 0qln <0qln@proton.me> Date: Mon, 24 Nov 2025 10:36:08 +0100 Subject: [PATCH] pa-03 --- pa-03/a1/hello.c | 5 +++ pa-03/a2/calcggt.c | 11 ++++++ pa-03/a2/flake.lock | 61 +++++++++++++++++++++++++++++ pa-03/a2/flake.nix | 53 +++++++++++++++++++++++++ pa-03/a2/ggt.c | 6 +++ pa-03/a2/ggt.h | 1 + pa-03/a3/flake.lock | 61 +++++++++++++++++++++++++++++ pa-03/a3/flake.nix | 52 ++++++++++++++++++++++++ pa-03/a3/funktionen/to_ascii.c | 13 ++++++ pa-03/a3/funktionen/to_ascii.h | 1 + pa-03/a3/funktionen/to_upper_case.c | 4 ++ pa-03/a3/funktionen/to_upper_case.h | 1 + pa-03/a3/main.c | 21 ++++++++++ pa-03/a4/flake.lock | 61 +++++++++++++++++++++++++++++ pa-03/a4/flake.nix | 52 ++++++++++++++++++++++++ pa-03/a4/test.c | 18 +++++++++ 16 files changed, 421 insertions(+) create mode 100644 pa-03/a1/hello.c create mode 100644 pa-03/a2/calcggt.c create mode 100644 pa-03/a2/flake.lock create mode 100644 pa-03/a2/flake.nix create mode 100644 pa-03/a2/ggt.c create mode 100644 pa-03/a2/ggt.h create mode 100644 pa-03/a3/flake.lock create mode 100644 pa-03/a3/flake.nix create mode 100644 pa-03/a3/funktionen/to_ascii.c create mode 100644 pa-03/a3/funktionen/to_ascii.h create mode 100644 pa-03/a3/funktionen/to_upper_case.c create mode 100644 pa-03/a3/funktionen/to_upper_case.h create mode 100644 pa-03/a3/main.c create mode 100644 pa-03/a4/flake.lock create mode 100644 pa-03/a4/flake.nix create mode 100644 pa-03/a4/test.c diff --git a/pa-03/a1/hello.c b/pa-03/a1/hello.c new file mode 100644 index 0000000..dcfb86b --- /dev/null +++ b/pa-03/a1/hello.c @@ -0,0 +1,5 @@ +#include +int main() { + printf("Hello, World!"); + return 0; +} diff --git a/pa-03/a2/calcggt.c b/pa-03/a2/calcggt.c new file mode 100644 index 0000000..83c3127 --- /dev/null +++ b/pa-03/a2/calcggt.c @@ -0,0 +1,11 @@ +#include +#include "ggt.h" + +int main() { + printf("ggt(9, 27) = %d\n", ggt(9, 27)); + printf("ggt(12, 8) = %d\n", ggt(12, 8)); + printf("ggt(0, 0) = %d\n", ggt(0, 0)); + printf("ggt(1, 0) = %d\n", ggt(1, 0)); + printf("ggt(0, 1) = %d\n", ggt(0, 1)); + return 0; +} diff --git a/pa-03/a2/flake.lock b/pa-03/a2/flake.lock new file mode 100644 index 0000000..0b825be --- /dev/null +++ b/pa-03/a2/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1763759067, + "narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1763835633, + "narHash": "sha256-HzxeGVID5MChuCPESuC0dlQL1/scDKu+MmzoVBJxulM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "050e09e091117c3d7328c7b2b7b577492c43c134", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1761765539, + "narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "719359f4562934ae99f5443f20aa06c2ffff91fc", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/pa-03/a2/flake.nix b/pa-03/a2/flake.nix new file mode 100644 index 0000000..1ba6908 --- /dev/null +++ b/pa-03/a2/flake.nix @@ -0,0 +1,53 @@ +{ + description = "Description for the project"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + # To import an internal flake module: ./other.nix + # To import an external flake module: + # 1. Add foo to inputs + # 2. Add foo as a parameter to the outputs function + # 3. Add here: foo.flakeModule + ]; + systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; + perSystem = { + config, + self', + inputs', + pkgs, + system, + ... + }: { + # Per-system attributes can be defined here. The self' and inputs' + # module parameters provide easy access to attributes of the same + # system. + + # Equivalent to inputs'.nixpkgs.legacyPackages.hello; + packages.default = pkgs.stdenv.mkDerivation { + name = "ggt"; + src = ./.; + buildPhase = '' + cc *.c -o calcggt.out + ''; + installPhase = '' + mkdir -p $out/bin/ + mv calcggt.out $out/bin/ + ''; + meta = { + mainProgram = "calcggt.out"; + }; + }; + }; + flake = { + # The usual flake attributes can be defined here, including system- + # agnostic ones like nixosModule and system-enumerating ones, although + # those are more easily expressed in perSystem. + }; + }; +} diff --git a/pa-03/a2/ggt.c b/pa-03/a2/ggt.c new file mode 100644 index 0000000..f67b8cb --- /dev/null +++ b/pa-03/a2/ggt.c @@ -0,0 +1,6 @@ +int ggt(int a, int b) { + // https://de.wikipedia.org/wiki/Gr%C3%B6%C3%9Fter_gemeinsamer_Teiler#Rechenregeln_f%C3%BCr_Zahlen + if (a == 0) return b; + if (b == 0) return a; + return ggt(b, a % b); +} diff --git a/pa-03/a2/ggt.h b/pa-03/a2/ggt.h new file mode 100644 index 0000000..5adcb26 --- /dev/null +++ b/pa-03/a2/ggt.h @@ -0,0 +1 @@ +int ggt(int a, int b); diff --git a/pa-03/a3/flake.lock b/pa-03/a3/flake.lock new file mode 100644 index 0000000..0b825be --- /dev/null +++ b/pa-03/a3/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1763759067, + "narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1763835633, + "narHash": "sha256-HzxeGVID5MChuCPESuC0dlQL1/scDKu+MmzoVBJxulM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "050e09e091117c3d7328c7b2b7b577492c43c134", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1761765539, + "narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "719359f4562934ae99f5443f20aa06c2ffff91fc", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/pa-03/a3/flake.nix b/pa-03/a3/flake.nix new file mode 100644 index 0000000..1e4dd7a --- /dev/null +++ b/pa-03/a3/flake.nix @@ -0,0 +1,52 @@ +{ + description = "Description for the project"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + # To import an internal flake module: ./other.nix + # To import an external flake module: + # 1. Add foo to inputs + # 2. Add foo as a parameter to the outputs function + # 3. Add here: foo.flakeModule + ]; + systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; + perSystem = { + config, + self', + inputs', + pkgs, + system, + ... + }: { + # Per-system attributes can be defined here. The self' and inputs' + # module parameters provide easy access to attributes of the same + # system. + + packages.default = pkgs.stdenv.mkDerivation { + name = "a3"; + src = ./.; + buildPhase = '' + cc main.c funktionen/*.c -o main.out + ''; + installPhase = '' + mkdir -p $out/bin/ + mv main.out $out/bin/ + ''; + meta = { + mainProgram = "main.out"; + }; + }; + }; + flake = { + # The usual flake attributes can be defined here, including system- + # agnostic ones like nixosModule and system-enumerating ones, although + # those are more easily expressed in perSystem. + }; + }; +} diff --git a/pa-03/a3/funktionen/to_ascii.c b/pa-03/a3/funktionen/to_ascii.c new file mode 100644 index 0000000..138ea39 --- /dev/null +++ b/pa-03/a3/funktionen/to_ascii.c @@ -0,0 +1,13 @@ + int to_ascii(char c) { + if (c >= 'A' && c <= 'Z') { + int ascii_A = 65; + int off = ascii_A - 'A'; + return c + off; + } + if (c >= 'a' && c <= 'z') { + int ascii_a = 97; + int off = ascii_a - 'a'; + return c + off; + } + return -1; + } diff --git a/pa-03/a3/funktionen/to_ascii.h b/pa-03/a3/funktionen/to_ascii.h new file mode 100644 index 0000000..0c24b77 --- /dev/null +++ b/pa-03/a3/funktionen/to_ascii.h @@ -0,0 +1 @@ +int to_ascii(char c); diff --git a/pa-03/a3/funktionen/to_upper_case.c b/pa-03/a3/funktionen/to_upper_case.c new file mode 100644 index 0000000..7cf48ff --- /dev/null +++ b/pa-03/a3/funktionen/to_upper_case.c @@ -0,0 +1,4 @@ +int to_upper_case(char c) { + if (c >= 'A' && c <= 'Z') return c; + return c - ('a' - 'A'); +} diff --git a/pa-03/a3/funktionen/to_upper_case.h b/pa-03/a3/funktionen/to_upper_case.h new file mode 100644 index 0000000..278849b --- /dev/null +++ b/pa-03/a3/funktionen/to_upper_case.h @@ -0,0 +1 @@ +int to_upper_case(char c); diff --git a/pa-03/a3/main.c b/pa-03/a3/main.c new file mode 100644 index 0000000..1cdfe6f --- /dev/null +++ b/pa-03/a3/main.c @@ -0,0 +1,21 @@ +#include "./funktionen/to_upper_case.h" +#include "./funktionen/to_ascii.h" +#include + +int main() { + printf("Beenden von Schleifen mit ~ ...\n"); + printf("Geben sie Zeichen ein. Diese werden in Uppercase wieder ausgegeben:\n"); + while (1) { + int c = getchar(); + if (c == '~') break; + printf("[%d] %c", c, to_upper_case(c)); + } + printf("Geben sie Zeichen ein. Diese werden als Ascii-Code wieder ausgegeben:\n"); + while (1) { + int c = getchar(); + if (c == '~') break; + printf("[%d] %d", c, to_ascii(c)); + } + + return 0; +} diff --git a/pa-03/a4/flake.lock b/pa-03/a4/flake.lock new file mode 100644 index 0000000..0b825be --- /dev/null +++ b/pa-03/a4/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1763759067, + "narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1763835633, + "narHash": "sha256-HzxeGVID5MChuCPESuC0dlQL1/scDKu+MmzoVBJxulM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "050e09e091117c3d7328c7b2b7b577492c43c134", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1761765539, + "narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "719359f4562934ae99f5443f20aa06c2ffff91fc", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/pa-03/a4/flake.nix b/pa-03/a4/flake.nix new file mode 100644 index 0000000..5b0d1f4 --- /dev/null +++ b/pa-03/a4/flake.nix @@ -0,0 +1,52 @@ +{ + description = "Description for the project"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + imports = [ + # To import an internal flake module: ./other.nix + # To import an external flake module: + # 1. Add foo to inputs + # 2. Add foo as a parameter to the outputs function + # 3. Add here: foo.flakeModule + ]; + systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; + perSystem = { + config, + self', + inputs', + pkgs, + system, + ... + }: { + # Per-system attributes can be defined here. The self' and inputs' + # module parameters provide easy access to attributes of the same + # system. + + packages.default = pkgs.stdenv.mkDerivation { + name = "a3"; + src = ./.; + buildPhase = '' + cc test.c funktionen/*.c -o test.out + ''; + installPhase = '' + mkdir -p $out/bin/ + mv test.out $out/bin/ + ''; + meta = { + mainProgram = "test.out"; + }; + }; + }; + flake = { + # The usual flake attributes can be defined here, including system- + # agnostic ones like nixosModule and system-enumerating ones, although + # those are more easily expressed in perSystem. + }; + }; +} diff --git a/pa-03/a4/test.c b/pa-03/a4/test.c new file mode 100644 index 0000000..72b04d1 --- /dev/null +++ b/pa-03/a4/test.c @@ -0,0 +1,18 @@ +#include + +void ascii(int s) { + if (s < 1) s = 1; + + for (char c = 32; c <= 126;) { + for (int i = 0; i < s && c <= 126; i++) { + printf("%3d %c ", c, c); + c++; + } + printf("\n"); + } +} + +int main() { + ascii(5); + return 0; +}