I am fairly new to OCaml but I have this project that i'm working on, I don't really understand the concept of immutable objects and was wondering if i could get some help, I am doing this through a text editor and have tried String.iter and explode but still can't manage to figure it out.
Description:
You are given a DNA sequence:
a string that contains only characters 'A', 'C', 'G', and 'T'.
Your task is to calculate the number of substrings of sequence,
in which each of the symbols appears the same number of times.
Example 1:
For sequence = "ACGTACGT", the output should be 6
All substrings of length 4 contain each symbol exactly once (+5),
and the whole sequence contains each symbol twice (+1).
Example 2:
For sequence = "AAACCGGTTT", the output should be 1
Only substring "AACCGGTT" satisfies the criterion above: it contains each symbol twice.
Input: String, a sequence that consists only of symbols 'A', 'C', 'G', and 'T'.
Length constraint: 0 < sequence.length < 100000.
Output: Integer, the number of substrings where each symbol appears equally many times.
EDIT This is what I currently have:
let countA = ref 0
let countC = ref 0
let countG = ref 0
let countT = ref 0
let subStricount = ref 0
let countChar x =
match x with
'A'-> countA +1
|'C'-> countC +1
|'T'-> countT +1
|'G'-> countG +1
;;
let tempH = 0 in
let tempT = 3 in
let demoStri = "ACGTACGT" in
let striL = String.length demoStri in
for i = 0 to striL -1 do
for j = tempH to tempT do
countChar demoStri.[tempH];
done
done