1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- const fs = require('fs')
- let fp1: string = '' // data
- let fp2: string = '' // output
- // let fp3: string = '' // fingerprint
- fs.readFile('data.txt', (err, fingerprint) => {
- if (err) throw err;
- fp1 = fingerprint.toString()
- // console.log(fp1.length);
- })
- fs.readFile('fingerprint.txt', (err, fingerprint) => {
- if (err) throw err;
- fp2 = fingerprint.toString()
- // console.log(fp2.length);
- })
- // fs.readFile('fingerprint.txt', (err, fingerprint) => {
- // if (err) throw err;
- // fp3 = fingerprint.toString()
- // // console.log(fp3);
- // })
- const mismatches: number = compareAndCountDifferences(fp1, fp2);
- console.log(`Number of mismatches: ${mismatches}`);
- function compareAndCountDifferences(str1, str2): number {
- // Length validation:
- if (str1.length !== 151440 || str2.length !== 151440) {
- console.log("Error: Strings must be exactly 151440 characters long")
- }
-
- // Character comparison and difference counting:
- let differenceCount = 0;
- for (let i = 0; i < str1.length; i++) {
- if (str1[i] !== str2[i]) {
- differenceCount++;
- }
- }
-
- return differenceCount;
- }
|