I before E except after C: Difference between revisions
Content added Content deleted
(→{{header|MATLAB}}: Provided a full solution in MATLAB) |
|||
Line 2,363: | Line 2,363: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
<syntaxhighlight lang="java"> |
|||
import java.io.BufferedReader; |
|||
import java.io.IOException; |
|||
import java.io.InputStreamReader; |
|||
import java.net.URI; |
|||
import java.net.URISyntaxException; |
|||
import java.net.URL; |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="java"> |
|||
public static void main(String[] args) throws URISyntaxException, IOException { |
|||
count(); |
|||
System.out.printf("%-10s %,d%n", "total", total); |
|||
System.out.printf("%-10s %,d%n", "'cei'", cei); |
|||
System.out.printf("%-10s %,d%n", "'cie'", cie); |
|||
System.out.printf("%,d > (%,d * 2) = %b%n", cei, cie, cei > (cie * 2)); |
|||
System.out.printf("%,d > (%,d * 2) = %b", cie, cei, cie > (cei * 2)); |
|||
} |
|||
static int total = 0; |
|||
static int cei = 0; |
|||
static int cie = 0; |
|||
static void count() throws URISyntaxException, IOException { |
|||
URL url = new URI("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt").toURL(); |
|||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) { |
|||
String line; |
|||
while ((line = reader.readLine()) != null) { |
|||
if (line.matches(".*?(?:[^c]ie|cei).*")) { |
|||
cei++; |
|||
} else if (line.matches(".*?(?:[^c]ei|cie).*")) { |
|||
cie++; |
|||
} |
|||
total++; |
|||
} |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
<pre> |
|||
total 25,104 |
|||
'cei' 477 |
|||
'cie' 215 |
|||
477 > (215 * 2) = true |
|||
215 > (477 * 2) = false |
|||
</pre> |
|||
<br /> |
|||
An alternate demonstration<br> |
|||
Download and save wordlist to unixdict.txt. |
Download and save wordlist to unixdict.txt. |
||