第二个出租车编号发生器

时间:2015-10-22 18:10:33

标签: f# number-theory

我试图为第二个出租车编号生成一系列猜测。我想要做的是在有限序列中调用一系列整数上的Attempt函数。我在评论中有两个关于实施的问题。 如果您想知道的话,出租车号码是满足2个独特立方体的n个独特立方体中2个独特立方体总和的最小数量。 Ta(2)是1729年。

[<EntryPoint>]
let main argv =
    let Attempt (start : int) =
        let stop = start+20
        let integerList = [start..stop]
        let list = List.init 3 (fun x -> integerList.[x])
        //Is there a simple way to make initialize the list with random indices of integerList?
        let Cube x = x*x*x
        let newlist = list |> List.map (fun x -> Cube x)
        let partitionList (x : List<int>) (y : int) = List.sum [x.[y];x.[y+1]]
        let intLIST = [0..2]
        let partitionList' = [for i in intLIST do yield partitionList newlist i]
        let x = Set.ofList partitionList'
        let y = Set.ofList partitionList'
        //I was going to try to use some kind of equality operator to determine whether the two sets were equal, which could tell me whether we had actually found a Taxicab number by the weakened definition.
        System.Console.Write(list)
        System.Console.Write(newlist)
let rnd = System.Random()
//My primary question is how can I convert a random to an integer to use in start for the function Attempt?
System.Console.ReadKey() |> ignore
printfn("%A") argv
0

1 个答案:

答案 0 :(得分:0)

用另一个列表的随机索引初始化列表的脏方法:

let randomIndexes count myList =
    let rand = System.Random()
    seq {
        for n = 1 to count do
            yield rand.Next(List.length myList) }
    |> Seq.distinct 
    //|> Seq.sort // if you need them sorted
    |> List.ofSeq

let result = randomIndexes 5 [3;2;4;5]
printfn "%A" result