If the user has made a small typo on the answer to a question, the app tries to detect this. It uses the Wagner-Fisher DP algorithm to calculate the Levenstein distance number of letter insertions, deletions and substitutions to change one word into another between the answer and submitted answer to check if this distance is below a threshold i.e. the error is small enough to likely be a typo.
private boolean wagnerFischer(String input, String answer){
int[][] matrix = new int[input.length()+1][answer.length()+1]; //userAnswer is on rows and answer is on columns
for(int i=0;i<input.length()+1;i++){ //Fill in first column and first row with incrementing numbers;
matrix[i][0] = i;
}
for(int i=0;i<answer.length()+1;i++){
matrix[0][i] = i;
}
int value = 0;
for(int i=1;i<input.length()+1;i++){
for(int j=1;j<answer.length()+1;j++){
value = Math.min(matrix[i-1][j-1],Math.min(matrix[i-1][j],matrix[i][j-1]));
if(input.charAt(i-1) == answer.charAt(j-1)) matrix[i][j] = value;
else matrix[i][j] = value + 1;
}
}
int editDistance = matrix[input.length()][answer.length()];
int limit = (input.length()>8)?2:1;
return editDistance <= limit;
}
(This is only used on words with 5 or more letters as otherwise it makes single letter answers quite easy)
Additionally, the app uses hard-coded regexes such as
"([^\w]+|^)(united kingdom)([^\w]+|$)" -> {$1uk$3", "$1great britain$3", "$1britain$3"}
Each option is tried and then checked against the answer. An answer may require multiple corrections e.g. also a
"(.+)" -> {"a $1", "the $1", "$1s"}
. Different orders of subtitutions yields different strings and so the solution to checking multiple variants is a DFS with a depth limit. It is hardcoded approach but is quite effective.
On the app, you get a "neurone" for each day that you keep your streak going or go up a level. These form an image of a brain on the homepage (see images below). There are some interesting things about this image. Firstly, the brain is the shape of an ellipse and has the equation \(\frac{(x-\frac{w}{2})^{2}}{\frac{w}{2}^{2}}+\frac{(y-\frac{h}{2})^{2}}{(\frac{h}{2})^{2}}=1\). Secondly, the connections between neurones (axons), only connect neurones within a certain radius. If this radius is fixed, the first few neurones are a bit disheartening as they wouldn't connect and then, when you have hundreds of neurones, it would be one homogeneous mess. The same applies to the thickness of the axons and radii of the neurones. For a visually appealing boosted brain, I found the best scaling equations to be exponetial decay with the number of neurones with the constants found through regression on values which looked sensible.