Skip to content

Instantly share code, notes, and snippets.

@KurzGedanke
Created December 1, 2017 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KurzGedanke/4626916709ba764de0e7f8293336fb24 to your computer and use it in GitHub Desktop.
Save KurzGedanke/4626916709ba764de0e7f8293336fb24 to your computer and use it in GitHub Desktop.
/**
* Scheiß Kommentare
*/
public class Zahldarstellung {
public static boolean checkBasis(long zahl, int basis) {
System.out.println("Zahl: " + zahl);
return zahl % 10 <= basis || zahl == 0 && checkBasis(zahl / 10, basis);
}
public static long hornerSchema(long zahl, int basis) {
return zahl < 10 ?
(long) zahl :
hornerSchema(zahl / 10, basis) * basis + (long) zahl % 10;
}
public static long makeMeBasis(long zahl, int basis) {
return zahl == 0 ? 0 : makeMeBasis(zahl / basis, basis) * 10 + (zahl % basis);
}
public static long addiere(long zahlEins, long zahlZwei, int basis) {
return checkBasis(zahlEins, basis) && checkBasis(zahlZwei, basis) ?
makeMeBasis((hornerSchema(zahlEins, basis) + hornerSchema(zahlZwei, basis)), basis)
: -1;
}
public static void main(String[] args) {
System.out.println(addiere(773, 1239, 8));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment