Skip to content

Instantly share code, notes, and snippets.

@kunjee17
Last active December 18, 2015 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunjee17/6965af56a3821ad2d850 to your computer and use it in GitHub Desktop.
Save kunjee17/6965af56a3821ad2d850 to your computer and use it in GitHub Desktop.
#r @"..\packages\FSharp.Charting.0.90.13\lib\net40\FSharp.Charting.dll"
#load "..\packages\FSharp.Charting.0.90.13\FSharp.Charting.fsx"
open System
open FSharp.Charting
open System.Windows.Forms
open System.Drawing
let posNum = seq {1..101}
let cube x = x * x * x
let cubeposNum =
posNum
|> Seq.map (fun x -> (x, cube x))
let totalCombination =
cubeposNum
|> Seq.map (fun (a,b) -> cubeposNum |> Seq.map (fun (x,y) -> (a,x,b+y)))
|> Seq.concat
let finalResult =
totalCombination
|> Seq.countBy (fun (x,y,z) -> z)
|> Seq.filter (fun (x,y) -> y >= 4)
|> Seq.map (fun (x,y) -> x)
let dirtyHack (inputSeq)=
let a = inputSeq |> Seq.item 0
let b = inputSeq |> Seq.item 1
let c = inputSeq |> Seq.item 2
(a, b, c)
let pairValues =
finalResult
|> Seq.map (fun x -> totalCombination |> Seq.filter (fun (a,b,c) -> c = x ))
|> Seq.map (fun a -> a |> Seq.map (fun (x,y,z) -> seq[x;y;z] |> Seq.sort |> dirtyHack))
|> Seq.map (fun x -> x |> Seq.distinct)
//form crazyness - a copy paste from 2010 code :P
let form = new Form(Visible = true, Text = "A Simple F# Form",
TopMost = true, Size = Size(600,600))
let data = new DataGridView(Dock = DockStyle.Fill, Text = "Hardy–Ramanujan number",
Font = new Font("Lucida Console",12.0f),
ForeColor = Color.DarkBlue
)
form.Controls.Add(data)
data.DataSource <- (pairValues |> Seq.concat |> Seq.sortBy (fun (x,y,z) -> z) |> Seq.toArray)
data.Columns.[0].Width <- 200
data.Columns.[1].Width <- 200
data.Columns.[2].Width <- 200
data.Columns.[0].HeaderText <- "a"
data.Columns.[1].HeaderText <- "b"
data.Columns.[2].HeaderText <- "(a^3 + b^3)"
//Charting
let taxicabnumbers = pairValues
|> Seq.concat
|> Seq.sortBy (fun (x,y,z) -> z)
|> Seq.map (fun (x,y,z) -> z)
|> Seq.distinct
Chart.Point (taxicabnumbers,"TaxiCabNumbers","TaxiCab Number")
let taxicabnumbersX = pairValues
|> Seq.concat
|> Seq.sortBy (fun (x,y,z) -> z)
|> Seq.map (fun (x,y,z) -> (x,z))
Chart.Point (taxicabnumbersX,"TaxiCabNumbersX","TaxiCab Number in ref to X")
let taxicabnumbersY = pairValues
|> Seq.concat
|> Seq.sortBy (fun (x,y,z) -> z)
|> Seq.map (fun (x,y,z) -> (y,z))
Chart.Point (taxicabnumbersY,"TaxiCabNumbersY","TaxiCab Number in ref to Y")
Chart.Combine[
Chart.Point(taxicabnumbersX, "TaxiCabNumbersX")
Chart.Point(taxicabnumbersY, "TaxiCabNumbersY")
]
@pirrmann
Copy link

Couldn't fit it in a tweet, so far I have

seq {
    for s in Seq.initInfinite((+)1) do
        let test x y = pown x 3 + pown y 3 = s
        let m = int((float s) ** (1./3.))
        for a in 1..m do
        for b in a+1..m do
        if test a b then
            for c in a+1..m do
            for d in c+1..m do
            if test c d then
                yield s } |> Seq.head

@StachuDotNet
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment