aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-06-23 20:32:51 +0200
committerCharles Cabergs <me@cacharle.xyz>2021-06-23 20:32:51 +0200
commit8e3786904f6ea6d1f3422a36d9bacdc9f18bed04 (patch)
tree446b641361ec765f303085a0cc5016d593282633
parentf9b3a26d7134e5a4520a237fe8f48f7e4f2fda29 (diff)
downloadproject_euler-8e3786904f6ea6d1f3422a36d9bacdc9f18bed04.tar.gz
project_euler-8e3786904f6ea6d1f3422a36d9bacdc9f18bed04.tar.bz2
project_euler-8e3786904f6ea6d1f3422a36d9bacdc9f18bed04.zip
problem 62 julia
-rw-r--r--julia/062-cubic_permutations.jl32
1 files changed, 32 insertions, 0 deletions
diff --git a/julia/062-cubic_permutations.jl b/julia/062-cubic_permutations.jl
new file mode 100644
index 0000000..08c07fc
--- /dev/null
+++ b/julia/062-cubic_permutations.jl
@@ -0,0 +1,32 @@
+###
+# Cubic permutations
+# Problem 62
+#
+# The cube, 41063625 (345^3), can be permuted to produce two other cubes: 56623104 (384^3)
+# and 66430125 (405^3). 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.
+###
+
+
+using Base.Iterators
+
+cache = Dict()
+
+const PERMUTATIONS_COUNT = 5
+
+for n in countfrom(2)
+ cube = n ^ 3
+ key = sort(collect(string(cube)))
+ if !haskey(cache, key)
+ cache[key] = [cube]
+ else
+ push!(cache[key], cube)
+ end
+ for v in values(cache)
+ if length(v) == PERMUTATIONS_COUNT
+ println(minimum(v))
+ exit(0)
+ end
+ end
+end