<commit_before>// Playground - noun: a place where people can play

import Cocoa


/**
* recurisve algorithm
*/
func memoize<T: Hashable, U>( body: (T)->U ) -> (T)->U {
var memo = Dictionary<T, U>()
return { x in
if let q = memo[x] { return q }
let r = body(x)
memo[x] = r
return r
}
}

/*
let fibonacci: (Int)->Double = memoize{
fibonacci, n in
n < 2 ? Double(n) : fibonacci(n-2) + fibonacci(n-1)
}
*/
let fibonacci: (Int)->Int = memoize{
    fibonacci, n in
    n < 2 ? n : fibonacci(n-2) + fibonacci(n-1)
}

//fibonacci(3)

/**
* recursive algorithm - fail to run successfully, take part 1
*/
func memoize<T: Hashable, U>( body: (T)->U ) -> (T)->U {
    var memo = Dictionary<T, U>()
    return { x in
        if let q = memo[x] { return q }
        let r = body(x)
        memo[x] = r
        return r
    }
}
var fibonacci: (Int)->Double = { Double($0) }
fibonacci = memoize {
    (n: Int) in
    n < 2 ? Double(n) : fibonacci(n-2) + fibonacci(n-1)
}
fibonacci(3)

let φ = fibonacci(45) / fibonacci(44)

///**
//* recursive algorithm - take part 2
//*/
func memoize2<T: Hashable, U>( body: ((T)->U, T)->U ) -> (T)->U {
    var memo = Dictionary<T, U>()
    var result: ((T)->U)! // for declaration in reference in recursive memo
    result = { x in
        if let q = memo[x] { return q }
        let r = body(result, x)
        memo[x] = r
        return r
    }
    return result
}
let fibo = memoize2 { (fib, x: Int) in x < 2 ? Double(x) : fib(x - 2) + fib(x - 1) }

let φ2 = fibo(45) / fibo(44)<commit_msg>llv22 - swift programming of recursive<commit_after>// Playground - noun: a place where people can play

import Cocoa


/**
* recurisve algorithm
*/
func memoize<T: Hashable, U>( body: (T)->U ) -> (T)->U {
var memo = Dictionary<T, U>()
return { x in
if let q = memo[x] { return q }
let r = body(x)
memo[x] = r
return r
}
}

/*
let fibonacci: (Int)->Double = memoize{
fibonacci, n in
n < 2 ? Double(n) : fibonacci(n-2) + fibonacci(n-1)
}
let fibonacci: (Int)->Int = memoize{
    fibonacci, n in
    n < 2 ? n : fibonacci(n-2) + fibonacci(n-1)
}
*/
//fibonacci(3)

/**
* recursive algorithm - fail to run successfully, take part 1
*
func memoize<T: Hashable, U>( body: (T)->U ) -> (T)->U {
    var memo = Dictionary<T, U>()
    return { x in
        if let q = memo[x] { return q }
        let r = body(x)
        memo[x] = r
        return r
    }
}
var fibonacci: (Int)->Double = { Double($0) }
fibonacci = memoize {
    (n: Int) in
    n < 2 ? Double(n) : fibonacci(n-2) + fibonacci(n-1)
}
fibonacci(3)

let φ = fibonacci(45) / fibonacci(44)
*/

///**
//* recursive algorithm - take part 2
//*/
func memoize2<T: Hashable, U>( body: ((T)->U, T)->U ) -> (T)->U {
    var memo = Dictionary<T, U>()
    var result: ((T)->U)! // for declaration in reference in recursive memo
    result = { x in
        if let q = memo[x] { return q }
        let r = body(result, x)
        memo[x] = r
        return r
    }
    return result
}
let fibo = memoize2 { (fib, x: Int) in x < 2 ? Double(x) : fib(x - 2) + fib(x - 1) }

let φ2 = fibo(45) / fibo(44)
{'fraction_non_alphanumeric': 0.1806282722513089, 'fraction_numerical': 0.018979057591623036, 'mean_word_length': 2.4620611551528877, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '977372', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1207, 'n_words': 371}