Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function processData(input) {
- var arr = input.split("\n");
- var start = arr[0];
- var target = arr[1];
- var longest = 0;
- var L = new Array(start.length);
- for(var i=0; i<start.length; i++){
- L[i] = new Array(target.length);
- }
- for(var i=0; i<L.length; i++){
- for(var j=0; j<L[0].length; j++){
- if(start.charAt(i)==target.charAt(j)){
- if(i==0 || j==0){
- L[i][j] = 1;
- }
- else{
- L[i][j] = L[i-1][j-1] + 1;
- }
- if(L[i][j] > longest){
- longest = L[i][j];
- }
- }
- else{
- L[i][j] = 0;
- }
- }
- }
- var shortestLength = start.length + target.length - 2*longest;
- var bruteForceLength = start.length + target.length;
- var probabilities = [0,0,1/36,2/36,3/36,4/36,5/36,6/36,5/36,4/36,3/36,2/36,1/36];
- var possibles = [false,false];
- for(var i=2; i<=12; i++){
- if(i>=bruteForceLength || (i>=shortestLength && (i-shortestLength)%2==0)){
- possibles.push(true);
- }
- else{
- possibles.push(false);
- }
- }
- var sum = 0;
- for(var i=2; i<=12; i++){
- if(possibles[i]){
- sum+=probabilities[i];
- }
- }
- console.log(sum.toFixed(4));
- }
- process.stdin.resume();
- process.stdin.setEncoding("ascii");
- _input = "";
- process.stdin.on("data", function (input) {
- _input += input;
- });
- process.stdin.on("end", function () {
- processData(_input);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement