package com.euler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class Config {

    private static interface ProblemLoader {
        public Problem load();
    }

    private static final Map<String,ProblemLoader> LOADERS = new HashMap<>();
    {
        // TODO This is a pain to maintain. Can we use ClassLoader magic?
        LOADERS.put("24", new ProblemLoader() {
            @Override
            public Problem load() {
                return new Problem24();
            }
        });
        LOADERS.put("27", new ProblemLoader() {
            @Override
            public Problem load() {
                return new Problem27();
            }
        });
        LOADERS.put("28", new ProblemLoader() {
            @Override
            public Problem load() {
                return new Problem28();
            }
        });
        LOADERS.put("29", new ProblemLoader() {
            @Override
            public Problem load() {
                return new Problem29();
            }
        });
        LOADERS.put("29a", new ProblemLoader() {
            @Override
            public Problem load() {
                return new Problem29a();
            }
        });
        LOADERS.put("30", new ProblemLoader() {
            @Override
            public Problem load() {
                return new Problem30();
            }
        });
    }

    private static Problem loadProblem(String key) {
        ProblemLoader loader = LOADERS.get(key);
        if (loader == null) {
            // TODO Print a list of known problems then.
            throw new IllegalArgumentException(
                "Not a known problem: "+key);
        }
        return loader.load();
    }

    private final String[] args;

    public Config(String[] args) {
        this.args = args;
    }

    public Map<String,Problem> getProblems() {
        Map<String,Problem> result = new TreeMap<>();
        for (int i = 0; i < args.length; ++i) {
            String key = args[i];
            result.put(key, loadProblem(key));
        }
        return result;
    }

}

@@ -34,1750 +34,61 @@
 til.
-ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.TreeMap;%0A%0Apublic class Config %7B%0A%0A    private static interface ProblemLoader %7B%0A        public Problem load();%0A    %7D%0A%0A    private static final Map%3CString,ProblemLoader%3E LOADERS = new HashMap%3C%3E();%0A    %7B%0A        // TODO This is a pain to maintain. Can we use ClassLoader magic?%0A        LOADERS.put(%2224%22, new ProblemLoader() %7B%0A            @Override%0A            public Problem load() %7B%0A                return new Problem24();%0A            %7D%0A        %7D);%0A        LOADERS.put(%2227%22, new ProblemLoader() %7B%0A            @Override%0A            public Problem load() %7B%0A                return new Problem27();%0A            %7D%0A        %7D);%0A        LOADERS.put(%2228%22, new ProblemLoader() %7B%0A            @Override%0A            public Problem load() %7B%0A                return new Problem28();%0A            %7D%0A        %7D);%0A        LOADERS.put(%2229%22, new ProblemLoader() %7B%0A            @Override%0A            public Problem load() %7B%0A                return new Problem29();%0A            %7D%0A        %7D);%0A        LOADERS.put(%2229a%22, new ProblemLoader() %7B%0A            @Override%0A            public Problem load() %7B%0A                return new Problem29a();%0A            %7D%0A        %7D);%0A        LOADERS.put(%2230%22, new ProblemLoader() %7B%0A            @Override%0A            public Problem load() %7B%0A                return new Problem30();%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private static Problem loadProblem(String key) %7B%0A        ProblemLoader loader = LOADERS.get(key);%0A        if (loader == null) %7B%0A            // TODO Print a list of known problems then.%0A            throw new IllegalArgumentException(%0A                %22Not a known problem: %22+key);%0A        %7D%0A        return loader.load();%0A    %7D
+Map;%0Aimport java.util.TreeMap;%0A%0Apublic class Config %7B
 %0A%0A  
@@ -457,10 +457,346 @@
 %0A    %7D%0A%0A
+    private Problem loadProblem(String key) %7B%0A        try %7B%0A            String classPath = %22com.euler.Problem%22 + key;%0A            Class cls = Class.forName(classPath);%0A            Object obj = cls.newInstance();%0A            return (Problem)obj;%0A        %7D catch (Exception e) %7B%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A
 %7D%0A

Use Class.forName to load problems