/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package be.fror.projecteuler.problem;

/**
 *
 * @author Olivier Grégoire
 */
public class Problem34 extends AbstractProblem {

  @Override
  public Object solve() {
    int[] factorials = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
    final int max = 50000;
    int result = 0;
    for (int i = 3; i <= max; i++) {
      int sum = 0;
      for (int n = i; n > 0; n /= 10) {
        sum += factorials[n % 10];
        if (sum > i) {
          break;
        }
      }
      if (sum == i) {
        result += sum;
      }
    }
    return result;
  }

}

@@ -480,26 +480,56 @@
 int 
-i = 3; i %3C= max; i
+sumOfDigits = 3; sumOfDigits %3C= max; sumOfDigits
 ++) 
@@ -568,23 +568,55 @@
 int 
-n = i; n
+x = sumOfDigits; x
  %3E 0
+ && sum %3C= sumOfDigits
 ; 
-n
+x
  /= 
@@ -651,17 +651,17 @@
 als%5B
-n
+x
  %25 10%5D;%0A
     
@@ -660,58 +660,8 @@
 0%5D;%0A
-        if (sum %3E i) %7B%0A          break;%0A        %7D%0A
     
@@ -681,17 +681,27 @@
 (sum == 
-i
+sumOfDigits
 ) %7B%0A    

Refactor problem 34