Package org.apache.commons.lang.math

Examples of org.apache.commons.lang.math.Fraction


    public static void main(String[] args) {
        System.out.println(new P33().solve());
    }

    private int solve() {
        Fraction prod = Fraction.ONE;
        /*The problem simplifies to looking for any of:
         * 1: ax/bx = a/b
         * 2: ax/xb = a/b
         * 3: xa/xb = a/b
         * 4: xa/bx = a/b
         */
        for (int a = 1; a < 10; a++) {
            for (int b = 0; b < 10; b++) {
                for (int x = 0; x < 10; x++) {
                    int ln = 0;
                    int ld = 0;
                    int rn = 0;
                    int rd = 0;
                    // case 1
                    ln = (10 * a) + x;
                    ld = 10 * b + x;
                    rn = a;
                    rd = b;
                    if (compareEqual(ln, ld, rn, rd)) {
                        prod=prod.multiplyBy(Fraction.getFraction(ln, ld));
                        System.out.printf("found: %d/%d = %d/%d\n", ln, ld, rn, rd);
                    }
                    // case 2
                    ln = (10 * a) + x;
                    ld = 10 * x + b;
                    rn = a;
                    rd = b;
                    if (compareEqual(ln, ld, rn, rd)) {
                        prod=prod.multiplyBy(Fraction.getFraction(ln, ld));
                        System.out.printf("found: %d/%d = %d/%d\n", ln, ld, rn, rd);
                    }

                    // case 3
                    ln = (10 * x) + a;
                    ld = 10 * x + b;
                    rn = a;
                    rd = b;
                    if (compareEqual(ln, ld, rn, rd)) {
                        prod=prod.multiplyBy(Fraction.getFraction(ln, ld));
                        System.out.printf("found: %d/%d = %d/%d\n", ln, ld, rn, rd);
                    }

                    // case 4
                    ln = (10 * x) + a;
                    ld = 10 * b + x;
                    rn = a;
                    rd = b;
                    if (compareEqual(ln, ld, rn, rd)) {
                        prod=prod.multiplyBy(Fraction.getFraction(ln, ld));
                        System.out.printf("found: %d/%d = %d/%d\n", ln, ld, rn, rd);
                    }
                }
            }
        }
        System.out.println("Prod is: "+prod);
        return prod.getDenominator();
    }
View Full Code Here


            return false;
        }
        if (ln % 10 == 0 || ld % 10 == 0) {
            return false;
        }
        Fraction f1 = Fraction.getFraction(ln, ld);
        Fraction f2 = Fraction.getFraction(rn, rd);
        return (f1.compareTo(f2) == 0);
    }
View Full Code Here

    }

    public Fraction getProportion(DateTime date) {
        Days fromStartToDate = Days.daysBetween(startInclusive,
                date.toLocalDate());
        Fraction result = Fraction.getFraction(fromStartToDate.getDays(),
                this.daysBetween.getDays());
        try {
            return result.add(inTheDayIncrement(date));
        } catch (ArithmeticException e) {
            return result;
        }
    }
View Full Code Here

        private Duration calculateDurationInDayFor(EffortDuration effortDuration) {
            if (workingDayDuration.getStandardSeconds() == 0) {
                return Duration.ZERO;
            }
            Fraction fraction = fractionOfWorkingDayFor(effortDuration);
            try {
                return new Duration(fraction.multiplyBy(
                        Fraction.getFraction(DAY_MILLISECONDS, 1)).intValue());
            } catch (ArithmeticException e) {
                // if fraction overflows use floating point arithmetic
                return new Duration(
                        (int) (fraction.doubleValue() * DAY_MILLISECONDS));
            }
        }
View Full Code Here

        private Fraction fractionOfWorkingDayFor(EffortDuration effortDuration) {
            Duration durationInDay = toMilliseconds(effortDuration);
            // cast to int is safe because there are not enough seconds in
            // day
            // to overflow
            Fraction fraction = Fraction.getFraction(
                    (int) durationInDay.getStandardSeconds(),
                    (int) workingDayDuration.getStandardSeconds());
            return (Fraction) Collections.min(Arrays.asList(fraction,
                    Fraction.ONE));
        }
View Full Code Here

            LOG.warn("total effort is " + totalEffort
                    + " but effortAssigned is zero");
            getEffortAssigned();
            return 0;
        }
        Fraction fraction = effortAssigned.divivedBy(totalEffort);
        Fraction percentage = fraction.multiplyBy(Fraction.getFraction(100, 1));
        return percentage.intValue();
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.lang.math.Fraction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.