Created
February 11, 2016 12:38
-
-
Save wonderb0lt/53d54b605021c0a7c27b to your computer and use it in GitHub Desktop.
Something that came up in Java::chat
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
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