Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Custom User Avatar

    For some reason test cases 7 and 8 fail for me, even though my solution works locally. Oddly, test case 8 works on some attempts but not others.
    I had to forfeit eligibility for the points to see the cases but haven't changed my solution since. If it is correct, is there a way to reinstate eligibility?

    private static final String DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
    public static String converter(double n, int decimals, double base) {
        if (n == 0) return "0";
    
        boolean isNeg = n < 0;
        n = Math.abs(n);
    
        StringBuilder sb = new StringBuilder();
        for (int exponent = (int) (Math.log(n) / Math.log(base)); exponent > -decimals - 1; exponent--) {
            if (exponent == -1) {
                sb.append(".");
            }
            sb.append(DIGITS.charAt((int) (n / Math.pow(base, exponent))));
            n %= Math.pow(base, exponent);
        }
        return (isNeg ? "-" : "") + sb.toString();
    }
    
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution