1

What is/are common way/s to handle what would be ArithmeticExceptions in Java in Mathematica/ Wolfram Language? The ugly code is the If...Continues in the innermost For Loop. How should I address this with the Wolfram Language programming paradigm?

```
c=0;
best={0,{}};
operators={Plus,Subtract,Times,Divide};
numbersets=Subsets[{0,1,2,3,4,5,6,7,8,9},{4}];
For[i=1,i<= Length[numbersets],i++,
results=Table[False,9^4];
currentSet=numbersets[[i]];
permutations=Permutations[currentSet];
For[j=1,j<= Length[permutations],j++,
For[op1=1,op1<= Length[operators],op1++,
For[op2=1,op2<= Length[operators],op2++,
For[op3=1,op3<= Length[operators],op3++,
c=c+1;
If[operators[[op1]]==Divide && permutations[[j]][[2]]==0,Continue[]];
If[operators[[op2]]==Divide && permutations[[j]][[3]]==0,Continue[]];
If[operators[[op3]]==Divide && permutations[[j]][[4]]==0,Continue[]];
r=operators[[op1]][permutations[[j]][[1]],permutations[[j]][[2]]];
r=operators[[op2]][r,permutations[[j]][[3]]];
r=operators[[op3]][r,permutations[[j]][[4]]];
If[r>0 && IntegerQ[r],results[[r]]=True;]
];
]
]
]
If[FirstPosition[results,False][[1]]-1>best[[1]],
best={FirstPosition[results,False][[1]]-1,currentSet};
Print[{FirstPosition[results,False]-1,currentSet}];
]
]
```

and yes it is Eul3r again and it does not work, but that is irrelevant to the question...

Simplest thing to do is to remove the If statements entirely and to add

`// Quiet`

after the whole thing. – bill s – 2017-05-05T19:08:22.4102

`Check[]`

? (In theMathematicaparadigm, you would at least use`Do[]`

instead of`For[]`

here, but also take advantage of listability/vectorization to reduce the number of loops and increase speed. But that's a side issue.) – Michael E2 – 2017-05-23T12:40:01.083Which project Euler problem is it actually? Would make some things easier ^^ – Thies Heidecke – 2017-05-23T13:57:09.323