Skip to content

Instantly share code, notes, and snippets.

@wonderb0lt
Created February 11, 2016 12:38
Show Gist options
  • Save wonderb0lt/53d54b605021c0a7c27b to your computer and use it in GitHub Desktop.
Save wonderb0lt/53d54b605021c0a7c27b to your computer and use it in GitHub Desktop.
Something that came up in Java::chat
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import static java.util.stream.Collectors.toList;
public class Main {
public static void main(String[] args) throws IOException {
List<String> words = Files.readAllLines(Paths.get("test.txt"));
List<String> with100AsWeight = words.parallelStream()
.filter(s -> !s.contains("'")) // Weird thing from the word list
.map(String::toLowerCase)
.filter((s) -> (calculateLetterSum(s) == 100))
.limit(3)
.collect(toList());
System.out.println(with100AsWeight);
}
private static int calculateLetterSum(String s) {
int sum = 0;
for (char c : s.toCharArray()) {
sum += c - 97;
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment