commit b8ea28c9158ea51eca787f2830ac40d641ce6e31 Author: Sobottasgithub Date: Wed Nov 12 11:45:31 2025 +0100 Init 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/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/IntToBinary.java b/IntToBinary.java new file mode 100644 index 0000000..1d251be --- /dev/null +++ b/IntToBinary.java @@ -0,0 +1,15 @@ +public class IntToBinary { + // !!!!! DER REST DER AUFGABE IST IN DER README.md BEANTWORTED !!!!! + + public int binary(int n) { + if (n < 0) { + // Invalid input + return -1; + } else if (n <= 1) { + return n; + } else { + // Prevent adding the numbers by converting to String and convert it back to int after + return Integer.parseInt(Integer.toString(binary(n/2)) + (n%2)); + } + } +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..2a06224 --- /dev/null +++ b/Main.java @@ -0,0 +1,11 @@ +public class Main { + // !!!!!DER REST DER AUFGABE IST IN DER README.md BEANTWORTET!!!!! + public static void main(String[] args) { + IntToBinary intToBinary = new IntToBinary(); + + // Test function: + System.out.println(intToBinary.binary(3)); + System.out.println(intToBinary.binary(6)); + System.out.println(intToBinary.binary(9)); + } +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8752544 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1762810396, + "narHash": "sha256-dxFVgQPG+R72dkhXTtqUm7KpxElw3u6E+YlQ2WaDgt8=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "0bdadb1b265fb4143a75bd1ec7d8c915898a9923", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1762844143, + "narHash": "sha256-SlybxLZ1/e4T2lb1czEtWVzDCVSTvk9WLwGhmxFmBxI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9da7f1cf7f8a6e2a7cb3001b048546c92a8258b4", + "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..2ceb1d5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "int to binary"; + + 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 = "int-to-binary"; + 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/int-to-binary --add-flags "-cp $out/lib/ Main" + ''; + }; + }; + }; + flake = { + }; + }; +}