Compare commits
2 Commits
cc0e9bfb77
...
a7ba9515c1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7ba9515c1 | ||
|
|
9d57ebb781 |
3
.idea/.gitignore
generated
vendored
3
.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
6
.idea/misc.xml
generated
6
.idea/misc.xml
generated
@ -1,6 +0,0 @@
|
|||||||
<?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
8
.idea/modules.xml
generated
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/countDigitsIterative.iml" filepath="$PROJECT_DIR$/countDigitsIterative.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
38
Algorithm.java
Normal file
38
Algorithm.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
public class Algorithm {
|
||||||
|
// Nr 2
|
||||||
|
public int binarySearch(int[] arr, int left, int right, int target) {
|
||||||
|
if (left > right) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mid = left + (right - left) / 2;
|
||||||
|
|
||||||
|
if (arr[mid] == target) {
|
||||||
|
return mid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target < arr[mid]) {
|
||||||
|
return binarySearch(arr, left, mid - 1, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
return binarySearch(arr, mid + 1, right, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NR 1
|
||||||
|
public int ggt(int m, int n) {
|
||||||
|
while (n != 0) {
|
||||||
|
int rest = m % n;
|
||||||
|
m = n;
|
||||||
|
n = rest;
|
||||||
|
}
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NR 3
|
||||||
|
public long potenz(long a, int b) {
|
||||||
|
if (b == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return a * potenz(a, b - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Algorithms
38
Algorithms
@ -1,38 +0,0 @@
|
|||||||
public class Algorithm {
|
|
||||||
// Nr 2
|
|
||||||
public int binarySearch(int[] arr, int left, int right, int target) {
|
|
||||||
if (left > right) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mid = left + (right - left) / 2;
|
|
||||||
|
|
||||||
if (arr[mid] == target) {
|
|
||||||
return mid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target < arr[mid]) {
|
|
||||||
return binarySearch(arr, left, mid - 1, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
return binarySearch(arr, mid + 1, right, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NR 1
|
|
||||||
public int ggt(int m, int n) {
|
|
||||||
while (n != 0) {
|
|
||||||
int rest = m % n;
|
|
||||||
m = n;
|
|
||||||
n = rest;
|
|
||||||
}
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NR 3
|
|
||||||
public long potenz(long a, int b) {
|
|
||||||
if (b == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return a * potenz(a, b - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,5 +5,12 @@ public class Main {
|
|||||||
System.out.println("Iterativ" + countDigits.countDigitsIterativ(index));
|
System.out.println("Iterativ" + countDigits.countDigitsIterativ(index));
|
||||||
System.out.println("Rekursiv" + countDigits.countDigitsRekursiv(index));
|
System.out.println("Rekursiv" + countDigits.countDigitsRekursiv(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Nr 1 2 & 3:");
|
||||||
|
int[] arr = {1, 2, 4, 7, 9, 12, 15, 18, 20};
|
||||||
|
Algorithm algorithms = new Algorithm();
|
||||||
|
System.out.println("ggt: " + algorithms.ggt(8, 4));
|
||||||
|
System.out.println("binarySearch: " + algorithms.binarySearch(arr, 0, arr.length, 12));
|
||||||
|
System.out.println("potenz: " + algorithms.potenz(4, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
use flake .
|
|
||||||
24
out/production/countDigitsIterative/.gitignore
vendored
24
out/production/countDigitsIterative/.gitignore
vendored
@ -1,24 +0,0 @@
|
|||||||
# Compiled class file
|
|
||||||
*.class
|
|
||||||
|
|
||||||
# Log file
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# BlueJ files
|
|
||||||
*.ctxt
|
|
||||||
|
|
||||||
# Mobile Tools for Java (J2ME)
|
|
||||||
.mtj.tmp/
|
|
||||||
|
|
||||||
# Package Files #
|
|
||||||
*.jar
|
|
||||||
*.war
|
|
||||||
*.nar
|
|
||||||
*.ear
|
|
||||||
*.zip
|
|
||||||
*.tar.gz
|
|
||||||
*.rar
|
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
|
||||||
hs_err_pid*
|
|
||||||
replay_pid*
|
|
||||||
3
out/production/countDigitsIterative/.idea/.gitignore
generated
vendored
3
out/production/countDigitsIterative/.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
<?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>
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/countDigitsIterative.iml" filepath="$PROJECT_DIR$/countDigitsIterative.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
JAVA_FMT = google-java-format
|
|
||||||
JAVA_FILES = $(shell find . -name '*.java')
|
|
||||||
XML_FMT = xmlindent
|
|
||||||
XML_FILES = $(shell find . -name '*.xml')
|
|
||||||
|
|
||||||
.PHONY: fmt
|
|
||||||
fmt:
|
|
||||||
@echo "Formatting all Java files..."
|
|
||||||
@for f in $(JAVA_FILES); do \
|
|
||||||
echo " $$f"; \
|
|
||||||
$(JAVA_FMT) -i $$f; \
|
|
||||||
done
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
# Count digits
|
|
||||||
Count digits teilt die Zahl n durch 10 und gibt danach die zahl zurück als int wie oft die zahl teilbar ist.
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
<?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>
|
|
||||||
61
out/production/countDigitsIterative/flake.lock
generated
61
out/production/countDigitsIterative/flake.lock
generated
@ -1,61 +0,0 @@
|
|||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"flake-parts": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs-lib": "nixpkgs-lib"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1762980239,
|
|
||||||
"narHash": "sha256-8oNVE8TrD19ulHinjaqONf9QWCKK+w4url56cdStMpM=",
|
|
||||||
"owner": "hercules-ci",
|
|
||||||
"repo": "flake-parts",
|
|
||||||
"rev": "52a2caecc898d0b46b2b905f058ccc5081f842da",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "hercules-ci",
|
|
||||||
"repo": "flake-parts",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1762977756,
|
|
||||||
"narHash": "sha256-4PqRErxfe+2toFJFgcRKZ0UI9NSIOJa+7RXVtBhy4KE=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "c5ae371f1a6a7fd27823bc500d9390b38c05fa55",
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
{
|
|
||||||
description = "count digits iterativ";
|
|
||||||
|
|
||||||
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 = "count-digits-iterativ";
|
|
||||||
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/count-digits-iterativ --add-flags "-cp $out/lib/ Main"
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
flake = {
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user