This commit is contained in:
Sobottasgithub 2025-11-12 21:19:54 +01:00
commit 701d32c021
20 changed files with 378 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake .

3
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

6
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/recursivFakultaet.iml" filepath="$PROJECT_DIR$/recursivFakultaet.iml" />
</modules>
</component>
</project>

27
Fakultaet.java Normal file
View File

@ -0,0 +1,27 @@
public class Fakultaet {
public Fakultaet() {
int inputNum = 30;
System.out.println("Iterativ: " + iterativFakultaet(inputNum));
System.out.println("Recursiv: " + recursivFakultaet(inputNum));
}
public Fakultaet(int num) {
System.out.println("Iterativ: " + iterativFakultaet(num));
System.out.println("Recursiv: " + recursivFakultaet(num));
}
public int iterativFakultaet(int num) {
int result = 1;
for (int index = 1; index <= num; index++) {
result = index * result;
}
return result;
}
public int recursivFakultaet(int num) {
if (num == 1) {
return num;
}
return num * recursivFakultaet(num-1);
}
}

6
Main.java Executable file
View File

@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
//Fakultaet fakultaet = new Fakultaet(30);
Rekursion rekursion = new Rekursion();
}
}

51
Rekursion.java Normal file
View File

@ -0,0 +1,51 @@
public class Rekursion {
public Rekursion() {
System.out.println(fibonacci(10));
System.out.println(fibonacciIterativ(10));
System.out.println("Result " + mystery(5));
}
public int fibonacci(int n) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
return fibonacci(n-1) + fibonacci(n-2);
}
}
public int fibonacciIterativ(int n) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
}
int next = 0;
int a = 1;
int b = 0;
for (int index = 0; index < n; index++) {
next = a + b;
a = b;
b = next;
}
return next;
}
public int mystery(int n) {
System.out.println(n);
if (n <= 1) {
return 1;
}
return n + mystery(n-1);
}
private static String getString(int binaryNum) {
return String.valueOf(binaryNum);
}
}

61
flake.lock generated Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1760948891,
"narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1761114652,
"narHash": "sha256-f/QCJM/YhrV/lavyCVz8iU3rlZun6d+dAiC3H+CDle4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01f116e4df6a15f4ccdffb1bcd41096869fb385c",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1754788789,
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "a73b9c743612e4244d865a2fdee11865283c04e6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

57
flake.nix Normal file
View File

@ -0,0 +1,57 @@
{
description = "Inventar";
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 = [
];
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: let
jdk = pkgs.jdk21.override {
};
buildInputs = [
jdk
];
devTools = [
pkgs.google-java-format
];
in {
devShells.default = pkgs.mkShell {
buildInputs = buildInputs ++ devTools;
};
packages = {
default = pkgs.stdenv.mkDerivation {
pname = "recursiveFakultaet";
version = "1.0.0";
src = ./.;
nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ];
buildPhase = ''
javac -Werror -g:none -deprecation -verbose Main.java
'';
installPhase = ''
mkdir -p $out/{bin,lib}
cp *.class $out/lib
makeWrapper ${pkgs.lib.getExe jdk} $out/bin/recursiveFakultaet --add-flags "-cp $out/lib/ Main"
'';
};
};
};
flake = {
};
};
}

View File

@ -0,0 +1 @@
use flake .

3
out/production/recursivFakultaet/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/recursivFakultaet.iml" filepath="$PROJECT_DIR$/recursivFakultaet.iml" />
</modules>
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1760948891,
"narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1761114652,
"narHash": "sha256-f/QCJM/YhrV/lavyCVz8iU3rlZun6d+dAiC3H+CDle4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01f116e4df6a15f4ccdffb1bcd41096869fb385c",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1754788789,
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "a73b9c743612e4244d865a2fdee11865283c04e6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

View File

@ -0,0 +1,57 @@
{
description = "Inventar";
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 = [
];
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: let
jdk = pkgs.jdk21.override {
};
buildInputs = [
jdk
];
devTools = [
pkgs.google-java-format
];
in {
devShells.default = pkgs.mkShell {
buildInputs = buildInputs ++ devTools;
};
packages = {
default = pkgs.stdenv.mkDerivation {
pname = "recursiveFakultaet";
version = "1.0.0";
src = ./.;
nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ];
buildPhase = ''
javac -Werror -g:none -deprecation -verbose Main.java
'';
installPhase = ''
mkdir -p $out/{bin,lib}
cp *.class $out/lib
makeWrapper ${pkgs.lib.getExe jdk} $out/bin/recursiveFakultaet --add-flags "-cp $out/lib/ Main"
'';
};
};
};
flake = {
};
};
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

11
recursivFakultaet.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>