Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

public class BFS implements Algorithm {

@Override
public boolean isSolution(Algorithm algorithm) {
return algorithm instanceof BFS;
}

@Override
public String getSolution() {
return "주변부터 둘러보기";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

public class BinarySearch implements Algorithm {

@Override
public boolean isSolution(Algorithm algorithm) {
return algorithm instanceof BinarySearch;
}

@Override
public String getSolution() {
return "반띵 ㄱㄱ";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

public class DFS implements Algorithm {

@Override
public boolean isSolution(Algorithm algorithm) {
return algorithm instanceof DFS;
}

@Override
public String getSolution() {
return "나는 한 놈씩 조져";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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문제를 들고옵니까";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
package com.example.algorithmbot;

import java.util.List;

public class Main {

public static void main(String[] args) {
Wchae wchae = new Wchae();
List<Algorithm> algorithmList = List.of(new BFS(), new DFS(), new TwoPointer(),
new BinarySearch(), new DP());

for (int i = 0; i < 20; i++) {
Algorithm first = algorithmList.get((int) (Math.random() * 5));
Algorithm second = algorithmList.get((int) (Math.random() * 5));
printTodaysAlgorithm(first, second);
printWchaeSolveResult(wchae.solveAlgorithm(first), wchae.solveAlgorithm(second));
System.out.println();
}
}

public static void printTodaysAlgorithm(Algorithm first, Algorithm second) {
System.out.printf("오늘의 알고리즘 : %s, %s\n", first.getClass().getSimpleName(),
second.getClass().getSimpleName());
}

public static void printWchaeSolveResult(String firstResult, String secondResult) {
System.out.printf("우주 : %s / %s\n", firstResult, secondResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

public class TwoPointer implements Algorithm {

@Override
public boolean isSolution(Algorithm algorithm) {
return algorithm instanceof TwoPointer;
}

@Override
public String getSolution() {
return "너에게 닿기를...";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
package com.example.algorithmbot;

import java.util.HashMap;
import java.util.Map;

public class Wchae {

private final Map<Algorithm, Integer> algorithmMap;

public Wchae() {
algorithmMap = new HashMap<>();
}

public String solveAlgorithm(Algorithm algorithm) {
Integer solveCount = algorithmMap.getOrDefault(algorithm, 0);
// 풀어보지 못한 알고리즘인 경우
boolean isSolvedAlgorithm = algorithmMap.keySet()
.stream()
.filter(x -> x.isSolution(algorithm))
.findAny().isPresent();
if (!isSolvedAlgorithm) {
algorithmMap.put(algorithm, 1);
return "스트레스 받네...";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수로 빼주세여~(33줄 포함)

}
// 풀어본 알고리즘인 경우
boolean isSolved = Math.random() * 10 > solveCount;
if (isSolved) {
if (solveCount < 10) {
algorithmMap.put(algorithm, solveCount + 1);
}
return algorithm.getSolution();
}
return "스트레스 받네...";
}
}