forked from Comamoca/Awesome-DDSK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Comamoca#25 from jiro4989/feature/java
Add Java version
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class Ddsk { | ||
public static void main(String... args) { | ||
// ドドスコ要素のセットアップ | ||
List<String> ddskItems = new ArrayList<>(); | ||
ddskItems.add("ドド"); | ||
ddskItems.add("スコ"); | ||
|
||
List<String> ddskHistory = new ArrayList<>(); | ||
|
||
// ドドスコスコスコ * 3 で終了しない限り無限に処理し続ける | ||
while (!endsWith3Ddsk(ddskHistory)) { | ||
// ドド か スコ のどちらかを選択するのを4回繰り返す | ||
StringBuilder ddskStringBuilder = new StringBuilder(); | ||
for (int i=0; i<4; i++) { | ||
Collections.shuffle(ddskItems); | ||
String ddskItem = ddskItems.get(0); | ||
ddskStringBuilder.append(ddskItem); | ||
} | ||
|
||
String ddsk = ddskStringBuilder.toString(); | ||
System.out.println(ddsk); | ||
|
||
ddskHistory.add(ddsk); | ||
} | ||
|
||
System.out.println("ラブ注入❤"); | ||
} | ||
|
||
/** | ||
* リストの末尾3つを取り出して、それらがすべて "ドドスコスコスコ" であった場合に true を返す。 | ||
* | ||
* @param items リスト要素 | ||
* @return リストの末尾要素3つがすべて "ドドスコスコスコ" であるか否か | ||
*/ | ||
private static boolean endsWith3Ddsk(List<String> items) { | ||
int itemSize = items.size(); | ||
if (itemSize < 3) { | ||
return false; | ||
} | ||
|
||
List<String> tailItems = items.subList(itemSize - 3, itemSize); | ||
List<String> filteredItems = tailItems.stream().filter(i -> "ドドスコスコスコ".equals(i)).collect(Collectors.toList()); | ||
return filteredItems.size() == 3; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM openjdk:20-jdk | ||
|
||
WORKDIR /work | ||
|
||
COPY ./Ddsk.java . | ||
RUN javac Ddsk.java | ||
|
||
ENTRYPOINT ["java", "Ddsk"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# DDSK-Java | ||
|
||
## 実行方法 | ||
|
||
```bash | ||
docker build -t ddsk:java . | ||
docker run --rm -t ddsk:java | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters