The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.
Find the smallest cube for which exactly five permutations of its digits are cube.
open System let cubeRoot (n:int64) = Math.Pow(double(n), 1.0/3.0) // define function to investigate the numbers of d digits which are cubes let f d = // find the min & max number whose cube is d digits long let min, max = int64(cubeRoot (pown 10L d)), int64(cubeRoot (pown 10L (d+1))) // and look for groups of 5 numbers which are cubes and permutations of one another [min..max] |> List.map (fun n -> pown n 3) |> Seq.groupBy (fun n -> n.ToString().ToCharArray() |> Array.sort) |> Seq.filter (fun (k, l) -> l |> Seq.length = 5) let answer = // go through the numbers of a given number of digits and find the first set of groups // of 5 numbers which are cubes and permutations of one another let groups = Seq.unfold (fun state -> Some(state, state+1)) 7 |> Seq.map f |> Seq.filter (fun l -> Seq.length l > 0) |> Seq.head // find the smallest elements in the groups groups |> Seq.map (fun (k, l) -> l |> Seq.min) |> Seq.min
Enjoy what you’re reading? Subscribe to my newsletter and get more content on AWS and serverless technologies delivered straight to your inbox.
I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.
In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. Including basic concepts, HTTP and event triggers, activities, design patterns and best practices.
Here is a complete list of all my posts on serverless and AWS Lambda. In the meantime, here are a few of my most popular blog posts.
- Lambda optimization tip – enable HTTP keep-alive
- You are thinking about serverless costs all wrong
- Many faced threats to Serverless security
- We can do better than percentile latencies
- I’m afraid you’re thinking about AWS Lambda cold starts all wrong
- Yubl’s road to Serverless
- AWS Lambda – should you have few monolithic functions or many single-purposed functions?
- AWS Lambda – compare coldstart time with different languages, memory and code sizes
- Guys, we’re doing pagination wrong