Skip to content

Instantly share code, notes, and snippets.

@gmenard
gmenard / WordFrequencies.java
Last active February 12, 2017 12:28
Given an arbitrary text document written in English, this solution will generate an alphabetical list of all word occurrences with their frequencies and the sentence numbers in which they appear.
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@gmenard
gmenard / BoyerMooreSearch.java
Created October 27, 2013 04:53
Boyer–Moore string search algorithm.
/**
* Search if a string (pattern) is contained in another string (text)
* according to the Boyer–Moore string search algorithm.
*
* @param pattern string to search for
* @param text string to search in
* @return true if text contains pattern, otherwise false
*/
public static Boolean search(String pattern, String text) {
@gmenard
gmenard / RegExConverter.java
Last active February 21, 2023 10:50
Convert regular expression from infix to postfix notation using Shunting-yard algorithm. Insert a '.' as explicit concatenation operator.
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
public class RegExConverter {
/** Operators precedence map. */