fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. /* The class name doesn't have to be Main, as long as the class is not public. */
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String unwieldy = "The average New York City taxi cab driver makes $90,747 in revenue per year. There are roughly 13,267 cabs in the city. In 2007, NYC forced cab drivers to begin taking credit cards, which involved installing a touch screen system for payment. During payment, the user is presented with three default buttons for tipping: 20%, 25%, and 30%. When cabs were cash only, the average tip was roughly 10%. After the introduction of this system, the tip percentage jumped to 22%. Those three buttons resulted in $144,146,165 of additional tips. Per year. Those are some very valuable buttons.";
  9. String thenextweb = "If you’ve ever been to the city of New York during the past five years, you’ll know that cab drivers don’t always give off a warm and cuddly feeling. This was especially true for short trips, where I’d whip out my debit card and have to argue with the driver that I didn’t have any cash on me ’til he finally gave in. Lately, however, the attitude towards paying with cards seems to have shifted — just in time for our new in-cab iPads. So, what’s caused the change? Here’s what one Joshua Gross found: The average New York City taxi driver makes $90,747 in gross revenue per year (less some hefty operating expenses). In 2007, NYC required cab drivers to begin accepting cards, which involved installing a touch screen system for payment in all ~13,267 cars. During payment, users are shown three default buttons for tipping: 20%, 25% and 30%. Back when cabs were cash-only, the average tip was around a modest 10%. But since this system was introduced system, the average tipping percentage jumped to 22%. “Those three buttons resulted in $144,146,165 of additional tips. Per year. Those are some very valuable buttons (via Joshua Gross).”";
  10. String thenextwebBottomHalf = "The average New York City taxi driver makes $90,747 in gross revenue per year (less some hefty operating expenses). In 2007, NYC required cab drivers to begin accepting cards, which involved installing a touch screen system for payment in all ~13,267 cars. During payment, users are shown three default buttons for tipping: 20%, 25% and 30%. Back when cabs were cash-only, the average tip was around a modest 10%. But since this system was introduced system, the average tipping percentage jumped to 22%. “Those three buttons resulted in $144,146,165 of additional tips. Per year. Those are some very valuable buttons (via Joshua Gross).”";
  11. double diff = levenshteinDifference(unwieldy, thenextweb);
  12. double diffBottomHalf = levenshteinDifference(unwieldy, thenextwebBottomHalf);
  13. System.out.println("There is a " + diff + "% difference between Unwieldy's article and TheNextWeb's (" + (100 - diff) + ".% similar).");
  14. System.out.println("If you remove the intro from TheNextWeb's article, there is a " + diffBottomHalf + "% difference between Unwieldy's article and TheNextWeb's (" + (100 - diffBottomHalf) + ".% similar).");
  15. }
  16. private static int minimum(int a, int b, int c) {
  17. return Math.min(Math.min(a, b), c);
  18. }
  19.  
  20. public static int computeLevenshteinDistance(CharSequence str1,
  21. CharSequence str2) {
  22. int[][] distance = new int[str1.length() + 1][str2.length() + 1];
  23.  
  24. for (int i = 0; i <= str1.length(); i++)
  25. distance[i][0] = i;
  26. for (int j = 0; j <= str2.length(); j++)
  27. distance[0][j] = j;
  28.  
  29. for (int i = 1; i <= str1.length(); i++)
  30. for (int j = 1; j <= str2.length(); j++)
  31. distance[i][j] = minimum(
  32. distance[i - 1][j] + 1,
  33. distance[i][j - 1] + 1,
  34. distance[i - 1][j - 1]
  35. + ((str1.charAt(i - 1) == str2.charAt(j - 1)) ? 0
  36. : 1));
  37.  
  38. return distance[str1.length()][str2.length()];
  39. }
  40.  
  41. public static double levenshteinDifference(String str1, String str2) {
  42. int distance = computeLevenshteinDistance(str1, str2);
  43. double difference = 100 * ((1.0 * distance) / Math.max(str1.length(), str2.length()));
  44. return difference;
  45. }
  46. }
Success #stdin #stdout 0.08s 245824KB
stdin
Standard input is empty
stdout
There is a 58.632778264680105% difference between Unwieldy's article and TheNextWeb's (41.367221735319895.% similar).
If you remove the intro from TheNextWeb's article, there is a 28.213166144200624% difference between Unwieldy's article and TheNextWeb's (71.78683385579937.% similar).