let rec traverseNumberWithCondition' n f init predicate =
    match n with
    | 0 -> init
    | n -> 
        let digit = n % 10
        let newAcc = 
            match predicate digit with
            | true -> f init digit
            | false -> init
        traverseNumberWithCondition' (n / 10) f newAcc predicate

let traverseNumberWithCondition n f init predicate = 
    traverseNumberWithCondition' n f init predicate

[<EntryPoint>]
let main argv =
    System.Console.WriteLine("Введите число:")
    let number = System.Console.ReadLine() |> int
    
    // Пример 1: Количество цифр, больших 3
    let isGreaterThan3 x = x > 3
    let countGreaterThan3 = traverseNumberWithCondition number (fun acc _ -> acc + 1) 0 isGreaterThan3
    System.Console.WriteLine($"Количество цифр больше 3: {countGreaterThan3}")
    
    // Пример 2: Сумма цифр, кратных 3
    let isDivisibleBy3 x = x > 0 && x % 3 = 0
    let sumDivisibleBy3 = traverseNumberWithCondition number (fun acc x -> acc + x) 0 isDivisibleBy3
    System.Console.WriteLine($"Сумма цифр, кратных 3: {sumDivisibleBy3}")
    
    // Пример 3: Произведение цифр в диапазоне [3,7]
    let isInRange3to7 x = x >= 3 && x <= 7
    let mulInRange = traverseNumberWithCondition number (fun acc x -> acc * x) 1 isInRange3to7
    System.Console.WriteLine($"Произведение цифр в диапазоне [3,7]: {mulInRange}")
    
    // Демонстрация композиции условий
    let isEvenAndGreaterThan3 x = x % 2 = 0 && x > 3
    let sumEvenGreaterThan3 = traverseNumberWithCondition number (fun acc x -> acc + x) 0 isEvenAndGreaterThan3
    System.Console.WriteLine($"Сумма четных цифр, больших 3: {sumEvenGreaterThan3}")
    
    0