From cf4af5fc8d712d2225307035440f70c720165c58 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 14 Nov 2025 10:25:22 +0100 Subject: [PATCH] Init --- .envrc | 1 + .gitignore | 24 ++++++++ .idea/.gitignore | 3 + .idea/misc.xml | 6 ++ .idea/modules.xml | 8 +++ CountDigits.java | 18 ++++++ GNUmakefile | 12 ++++ Main.java | 9 +++ README.md | 2 + countDigitsIterative.iml | 11 ++++ flake.lock | 61 +++++++++++++++++++ flake.nix | 57 +++++++++++++++++ out/production/countDigitsIterative/.envrc | 1 + .../countDigitsIterative/.gitignore | 24 ++++++++ .../countDigitsIterative/.idea/.gitignore | 3 + .../countDigitsIterative/.idea/misc.xml | 6 ++ .../countDigitsIterative/.idea/modules.xml | 8 +++ .../countDigitsIterative/GNUmakefile | 12 ++++ out/production/countDigitsIterative/README.md | 2 + .../countDigitsIterative.iml | 11 ++++ .../countDigitsIterative/flake.lock | 61 +++++++++++++++++++ out/production/countDigitsIterative/flake.nix | 57 +++++++++++++++++ 22 files changed, 397 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 CountDigits.java create mode 100644 GNUmakefile create mode 100644 Main.java create mode 100644 README.md create mode 100644 countDigitsIterative.iml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 out/production/countDigitsIterative/.envrc create mode 100644 out/production/countDigitsIterative/.gitignore create mode 100644 out/production/countDigitsIterative/.idea/.gitignore create mode 100644 out/production/countDigitsIterative/.idea/misc.xml create mode 100644 out/production/countDigitsIterative/.idea/modules.xml create mode 100644 out/production/countDigitsIterative/GNUmakefile create mode 100644 out/production/countDigitsIterative/README.md create mode 100644 out/production/countDigitsIterative/countDigitsIterative.iml create mode 100644 out/production/countDigitsIterative/flake.lock create mode 100644 out/production/countDigitsIterative/flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..524f096 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# 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* diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f5bd2df --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1bc3fd0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CountDigits.java b/CountDigits.java new file mode 100644 index 0000000..cad8bba --- /dev/null +++ b/CountDigits.java @@ -0,0 +1,18 @@ +public class CountDigits { + public int countDigitsIterativ(int n) { + int count = 0; + while (n != 0) { + n /= 10; + count++; + } + return count; + } + + public int countDigitsRekursiv(int n) { + if (n != 0) { + n /= 10; + return 1 + countDigitsRekursiv(n); + } + return 0; + } +} diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..2ab9f2e --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,12 @@ +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 diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..38b70e5 --- /dev/null +++ b/Main.java @@ -0,0 +1,9 @@ +public class Main { + public static void main(String[] args) { + CountDigits countDigits = new CountDigits(); + for (int index = 10; index < 110; index += 10) { + System.out.println("Iterativ" + countDigits.countDigitsIterativ(index)); + System.out.println("Rekursiv" + countDigits.countDigitsRekursiv(index)); + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad6a84d --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# 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. \ No newline at end of file diff --git a/countDigitsIterative.iml b/countDigitsIterative.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/countDigitsIterative.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ddd599d --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5308613 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + 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 = { + }; + }; +} diff --git a/out/production/countDigitsIterative/.envrc b/out/production/countDigitsIterative/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/out/production/countDigitsIterative/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/out/production/countDigitsIterative/.gitignore b/out/production/countDigitsIterative/.gitignore new file mode 100644 index 0000000..524f096 --- /dev/null +++ b/out/production/countDigitsIterative/.gitignore @@ -0,0 +1,24 @@ +# 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* diff --git a/out/production/countDigitsIterative/.idea/.gitignore b/out/production/countDigitsIterative/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/out/production/countDigitsIterative/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/out/production/countDigitsIterative/.idea/misc.xml b/out/production/countDigitsIterative/.idea/misc.xml new file mode 100644 index 0000000..f5bd2df --- /dev/null +++ b/out/production/countDigitsIterative/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/countDigitsIterative/.idea/modules.xml b/out/production/countDigitsIterative/.idea/modules.xml new file mode 100644 index 0000000..1bc3fd0 --- /dev/null +++ b/out/production/countDigitsIterative/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/countDigitsIterative/GNUmakefile b/out/production/countDigitsIterative/GNUmakefile new file mode 100644 index 0000000..2ab9f2e --- /dev/null +++ b/out/production/countDigitsIterative/GNUmakefile @@ -0,0 +1,12 @@ +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 diff --git a/out/production/countDigitsIterative/README.md b/out/production/countDigitsIterative/README.md new file mode 100644 index 0000000..ad6a84d --- /dev/null +++ b/out/production/countDigitsIterative/README.md @@ -0,0 +1,2 @@ +# 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. \ No newline at end of file diff --git a/out/production/countDigitsIterative/countDigitsIterative.iml b/out/production/countDigitsIterative/countDigitsIterative.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/out/production/countDigitsIterative/countDigitsIterative.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/countDigitsIterative/flake.lock b/out/production/countDigitsIterative/flake.lock new file mode 100644 index 0000000..ddd599d --- /dev/null +++ b/out/production/countDigitsIterative/flake.lock @@ -0,0 +1,61 @@ +{ + "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 +} diff --git a/out/production/countDigitsIterative/flake.nix b/out/production/countDigitsIterative/flake.nix new file mode 100644 index 0000000..5308613 --- /dev/null +++ b/out/production/countDigitsIterative/flake.nix @@ -0,0 +1,57 @@ +{ + 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 = { + }; + }; +}