diff --git "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/BFS.java" "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/BFS.java" index 6a84351..8bd675b 100644 --- "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/BFS.java" +++ "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/BFS.java" @@ -2,4 +2,13 @@ public class BFS implements Algorithm { + @Override + public boolean isSolution(Algorithm algorithm) { + return algorithm instanceof BFS; + } + + @Override + public String getSolution() { + return "주변부터 둘러보기"; + } } diff --git "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/BinarySearch.java" "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/BinarySearch.java" index 1981fb0..66b4d67 100644 --- "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/BinarySearch.java" +++ "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/BinarySearch.java" @@ -2,4 +2,13 @@ public class BinarySearch implements Algorithm { + @Override + public boolean isSolution(Algorithm algorithm) { + return algorithm instanceof BinarySearch; + } + + @Override + public String getSolution() { + return "반띵 ㄱㄱ"; + } } diff --git "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/DFS.java" "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/DFS.java" index 3685181..62961dc 100644 --- "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/DFS.java" +++ "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/DFS.java" @@ -2,4 +2,13 @@ public class DFS implements Algorithm { + @Override + public boolean isSolution(Algorithm algorithm) { + return algorithm instanceof DFS; + } + + @Override + public String getSolution() { + return "나는 한 놈씩 조져"; + } } diff --git "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/DP.java" "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/DP.java" index 083e387..2efac87 100644 --- "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/DP.java" +++ "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/DP.java" @@ -2,4 +2,13 @@ public class DP implements Algorithm { + @Override + public boolean isSolution(Algorithm algorithm) { + return algorithm instanceof DP; + } + + @Override + public String getSolution() { + return "누가 첫날부터 DP문제를 들고옵니까"; + } } diff --git "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/Main.java" "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/Main.java" index e203928..741d71d 100644 --- "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/Main.java" +++ "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/Main.java" @@ -1,8 +1,68 @@ package com.example.algorithmbot; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.StringJoiner; +import java.util.stream.IntStream; + public class Main { + private static final int COUNT = 2; + private static final int MAX_DAY = 20; public static void main(String[] args) { + List problems = List.of(new BFS(), new DFS(), new TwoPointer(), new BinarySearch(), new DP()); + + Wchae wchae = new Wchae(); + for (int i = 0; i < MAX_DAY; i++) { + List todayProblems = selectTwoProblems(problems); + List solveResults = new ArrayList<>(); + printAlgorithmNames(todayProblems); + + for (Algorithm problem : todayProblems) { + solveResults.add(wchae.solveAlgorithm(problem)); + } + printSolveResult(solveResults); + } + } + + private static void printSolveResult(List solveResult) { + String result = generateResults(solveResult); + System.out.println("우주 : " + result + System.lineSeparator()); + } + + private static String generateResults(List solveResult) { + StringJoiner joiner = new StringJoiner(" / "); + solveResult.forEach(joiner::add); + + return joiner.toString(); + } + + private static List selectTwoProblems(List problems) { + int range = problems.size(); + + return IntStream.range(0, COUNT) + .map(i -> generateRandomNumber(range)) + .mapToObj(problems::get) + .toList(); + } + + private static int generateRandomNumber(int size) { + Random random = new Random(); + return random.nextInt(size); + } + + private static void printAlgorithmNames(List algorithms) { + String names = generateAlgorithmNames(algorithms); + System.out.println("오늘의 알고리즘 : " + names); + } + private static String generateAlgorithmNames(List algorithms) { + StringJoiner joiner = new StringJoiner(", "); + for (Algorithm algorithm : algorithms) { + String name = algorithm.getClass().getSimpleName(); + joiner.add(name); + } + return joiner.toString(); } } diff --git "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/TwoPointer.java" "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/TwoPointer.java" index 15f5ba3..3be2e7f 100644 --- "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/TwoPointer.java" +++ "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/TwoPointer.java" @@ -2,4 +2,13 @@ public class TwoPointer implements Algorithm { + @Override + public boolean isSolution(Algorithm algorithm) { + return algorithm instanceof TwoPointer; + } + + @Override + public String getSolution() { + return "너에게 닿기를..."; + } } diff --git "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/Wchae.java" "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/Wchae.java" index 8e3087a..91901f5 100644 --- "a/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/Wchae.java" +++ "b/v1/backend/JAVA_LV_2_\354\225\214\352\263\240\353\246\254\354\246\230\354\235\230_\352\265\264\353\240\210/src/main/java/com/example/algorithmbot/Wchae.java" @@ -1,5 +1,32 @@ package com.example.algorithmbot; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Random; + public class Wchae { + private final Map algorithmMap = new HashMap<>(); + private final Random random = new Random(); + + public String solveAlgorithm(Algorithm algorithm) { + int solveCount = algorithmMap.getOrDefault(algorithm, 0); + + Optional algo = algorithmMap.keySet() + .stream() + .filter(elem -> elem.isSolution(algorithm)) + .findFirst(); + if (algo.isPresent()) { + double solveProbability = solveCount * 0.1; + double percentage = random.nextDouble(); + if (percentage < solveProbability) { + algorithmMap.put(algorithm, solveCount + 1); + return algorithm.getSolution(); + } + return "스트레스 받네..."; + } + algorithmMap.put(algorithm, solveCount + 1); + return "스트레스 받네..."; + } }