📜 ⬆️ ⬇️

Keyboard tricks

Today in the afternoon, dreaming to live until the weekend and rereading bash.org.ru, I came across a quote:

, entity () , ? :-)

Immediately I became interested, and how many keystrokes in general would be that existing words would give words that, when pressed in the English and Russian layout?


')
Of course, as a programmer, I could not deny myself the pleasure of writing such a program that would have found all such words. First of all, dictionaries with all word forms were required. Everything your heart desires found on http://wiki.services.openoffice.org/wiki/Dictionaries

Next code:

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.TreeSet;

public class EqualTypedWords {
final static String RU = "";
final static String EN = "f,dult;pbqrkvyjghcnea[wxio]sm'.z";
private static final int WORD_SIZE = 3;

static TreeSet readFile(String fname) throws IOException {
TreeSet result = new TreeSet();
List lines = FileUtils.readLines(new File(fname), "KOI8-R");
for (String s : lines) {
result.add(s.split("/")[0].toLowerCase());
}
return result;
}

public static void main(String[] args) throws IOException {
TreeSet ruset = readFile("data/ru_RU_ie.dic");
TreeSet enset = readFile("data/en_GB.dic");
for (String en : enset) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < en.length(); i++) {
int ind = EN.indexOf(en.charAt(i));
if (ind != -1) {
sb.append(RU.charAt(ind));
}
}
String newWord = sb.toString();
String c = ruset.ceiling(newWord);
String f = ruset.floor(newWord);
if (ruset.contains(newWord) && fit(newWord)) {
System.out.println("en: " + en + "; ru: " + newWord);
continue;
}
if (!fit(c) || !fit(f) || !fit(newWord)) continue;
if (newWord.startsWith(f)) {
System.out.println("en: " + en + "; ru: " + f + "; retyped: " + newWord);
}
if (c.startsWith(newWord)) {
System.out.println("en: " + en + "; ru: " + c + "; retyped: " + newWord);
}
}
}

private static boolean fit(String c) {
return (c != null && c.length() > WORD_SIZE);
}
}


, en ru openoffice , .

:

en: ababa; ru: ; retyped:
en: belt; ru: ; retyped:
en: blench; ru: ; retyped:
en: blend; ru: ; retyped:
en: celsius; ru: ; retyped:
en: derby; ru: ; retyped:
en: eire; ru: ; retyped:
en: entity; ru:
en: entrench; ru: ; retyped:
en: exec; ru: ; retyped:
en: hdtv; ru:
en: herb; ru:

en: herbage; ru: ; retyped:
en: herbal; ru: ; retyped:
en: herbert; ru: ; retyped:
en: inert; ru:
en: kbps; ru:
en: kerb; ru:
en: lens; ru: ; retyped:
en: next; ru: ; retyped:
en: verb; ru:



Source: https://habr.com/ru/post/28075/


All Articles