package com.google.jam.algorithms;

import java.util.function.Function;

import static java.lang.Integer.parseInt;
import static java.lang.Math.max;
import static java.lang.Math.min;

public class OminousOminoAlgorithm
        implements Function<String, String> {

    private static final String GABRIEL = "GABRIEL";
    private static final String RICHARD = "RICHARD";

    @Override
    public String apply(final String task) {
        final String[] split = task.split("\\s+");
        final int ominoRate = parseInt(split[0]);
        final int length = parseInt(split[1]);
        final int width = parseInt(split[2]);
        final int large = max(length, width);
        final int small = min(length, width);
        if ((large * small) % ominoRate != 0) {
            return RICHARD;
        }
        if (ominoRate == 3 && small == 1) {
            return RICHARD;
        }
        if (ominoRate == 4 && small <= 2) {
            return RICHARD;
        }
        if (ominoRate == 5 && (small <= 2 || small == 3 && large == 5)) {
            return RICHARD;
        }
        if (ominoRate == 6 && small <= 3) {
            return RICHARD;
        }
        if (ominoRate > 6) {
            return RICHARD;
        }
        return GABRIEL;
    }
}

@@ -184,16 +184,22 @@
 %0Apublic 
+final 
 class Om
@@ -733,40 +733,44 @@
 if (
-(large * small) %25 ominoRate != 0
+richardWins(ominoRate, large, small)
 ) %7B%0A
@@ -819,71 +819,149 @@
     
-if (ominoRate == 3 && small == 1) %7B%0A            return RICHARD;
+return GABRIEL;%0A    %7D%0A%0A    private boolean richardWins(int ominoRate, int large, int small) %7B%0A        return (large * small) %25 ominoRate != 0
 %0A   
@@ -961,34 +961,32 @@
 = 0%0A        
-%7D%0A
         
 if (ominoRat
@@ -965,36 +965,35 @@
                 
-if (
+%7C%7C 
 ominoRate == 4 &
@@ -993,9 +993,9 @@
  == 
-4
+3
  && 
@@ -1004,16 +1004,17 @@
 all 
-%3C= 2) %7B%0A
+== 1%0A    
     
@@ -1017,39 +1017,55 @@
             
-return RICHARD;
+%7C%7C ominoRate == 4 && small %3C= 2
 %0A        %7D%0A 
@@ -1057,34 +1057,32 @@
 = 2%0A        
-%7D%0A
         
 if (ominoRat
@@ -1061,36 +1061,35 @@
                 
-if (
+%7C%7C 
 ominoRate == 5 &
@@ -1130,19 +1130,16 @@
 ge == 5)
-) %7B
 %0A       
@@ -1147,46 +1147,15 @@
     
-return RICHARD;%0A        %7D%0A        if (
+    %7C%7C 
 omin
@@ -1178,19 +1178,16 @@
 all %3C= 3
-) %7B
 %0A       
@@ -1195,123 +1195,28 @@
     
-return RICHARD;%0A        %7D%0A        if (ominoRate %3E 6) %7B%0A            return RICHARD;%0A        %7D%0A        return GABRIEL
+    %7C%7C ominoRate %3E 6
 ;%0A  

simplify code