/*
 * 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 me.jittagornp.profile;

import java.util.Set;
import me.jittagornp.profile.game24.Equations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author jitta
 */
@RestController
public class Game24Controller {

    @GetMapping("/game24")
    public Set<String> getResult(@RequestParam("q") String q) {
        return Equations.withAnswer(24).andNumbers(q).get();
    }

}

@@ -233,64 +233,252 @@
 ava.
-util.Set;%0D%0Aimport me.jittagornp.profile.game24.Equations
+io.IOException;%0D%0Aimport java.util.HashMap;%0D%0Aimport java.util.Map;%0D%0Aimport java.util.Set;%0D%0Aimport javax.servlet.http.HttpServletResponse;%0D%0Aimport me.jittagornp.profile.game24.Equations;%0D%0Aimport static org.springframework.util.StringUtils.hasText
 ;%0D%0Ai
@@ -756,156 +756,807 @@
     
-@GetMapping(%22/game24%22)%0D%0A    public Set%3CString%3E getResult(@RequestParam(%22q%22) String q) %7B%0D%0A        return Equations.withAnswer(24).andNumbers(q).get()
+private final Map%3CString, Set%3CString%3E%3E cached = new HashMap%3C%3E();%0D%0A%0D%0A    private boolean isValidInput(String q) %7B%0D%0A        return hasText(q)%0D%0A                && q.length() == 4%0D%0A                && q.matches(%22%5E%5B%5C%5Cd%5D+$%22);%0D%0A    %7D%0D%0A%0D%0A    @GetMapping(%22/game24%22)%0D%0A    public Set%3CString%3E getResult(@RequestParam(value = %22q%22, required = false) String q, HttpServletResponse httpResp) throws IOException %7B%0D%0A        if (!isValidInput(q)) %7B%0D%0A            httpResp.sendError(HttpServletResponse.SC_BAD_REQUEST, %22require query string %5C%22q%5C%22 as a number 4 digit.%22);%0D%0A            return null;%0D%0A        %7D%0D%0A        Set%3CString%3E result = cached.get(q);%0D%0A        if (result == null) %7B%0D%0A            result = Equations.withAnswer(24).andNumbers(q).get();%0D%0A            cached.put(q, result);%0D%0A        %7D%0D%0A        return result
 ;%0D%0A 

add game24