Repository navigation
Expand file tree
/
Copy pathWhack.java
More file actions
38 lines (34 loc) · 1.48 KB
/
Copy pathWhack.java
File metadata and controls
38 lines (34 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// WHACK 26 One Hour Hack: the whack() function. Call it, don't change it.
// List<String> words = Whack.whack();
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public final class Whack {
private static final String[] WORDS = {
"whack", "hack", "duck", "quack", "goose", "honk", "bug", "feature", "warwick", "oculus",
"compsoc", "marshall", "wace", "brevan", "howard", "capital", "one", "bloomberg",
"netcraft", "incident", "io", "pizza", "coffee", "sleep", "deploy", "merge", "conflict",
"commit", "push", "prod", "segfault", "null", "pointer", "stack", "overflow", "semicolon",
"rubber", "demo", "pitch", "prize", "midnight", "wifi",
};
private Whack() {}
/** Writes 1-100 random words to a file called "whack" (one per line) and returns them. */
public static List<String> whack() {
ThreadLocalRandom random = ThreadLocalRandom.current();
int count = random.nextInt(1, 101);
List<String> words = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
words.add(WORDS[random.nextInt(WORDS.length)]);
}
try {
Files.writeString(Path.of("whack"), String.join("\n", words) + "\n");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return words;
}
}