Add Hamming Distance, Probability and Protein problems

This commit is contained in:
Alberto Venturini 2024-09-06 12:32:54 +02:00
parent 49127ae4ef
commit e94ff2985c
3 changed files with 139 additions and 0 deletions

21
09_hamm/hamm.nim Normal file
View file

@ -0,0 +1,21 @@
import os
import std/sequtils
import std/streams
template useStream(stream: Stream, body: untyped) =
if not isNil(stream):
try:
body
finally:
stream.close()
proc hammingDist(s1, s2: string): int =
doAssert s1.len == s2.len
zip(s1, s2).countIt(it[0] != it[1])
let fileName = paramStr(1)
let fileStream = newFileStream(fileName)
useStream(fileStream):
let s1 = readLine(fileStream)
let s2 = readLine(fileStream)
echo $hammingDist(s1, s2)