Skip to content

Instantly share code, notes, and snippets.

@Kah0ona
Created July 19, 2020 20:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kah0ona/9534b4e75f6e667110ff3cd3df3ee7b1 to your computer and use it in GitHub Desktop.
Save Kah0ona/9534b4e75f6e667110ff3cd3df3ee7b1 to your computer and use it in GitHub Desktop.
Disproves Euler's conjecture in Clojure, see https://twitter.com/JBezivin/status/1284415563608010752?s=20
(ns user
(:require [clojure.string :as string]))
(defn ⁵
"Returns n to the fifth power.
Note we use the UTF-character of superscript-5 as function name, because we can. ;-)"
[n]
(let [sq (* n n)]
(* sq sq n)))
(defn ⁵?
"Checks if x is of fifth power, if so, returns the radix. Starts looking from start-root onwards"
[start-root n]
(reduce (fn [_ radix]
(let [fifth-power (⁵ radix)]
(cond
(= n fifth-power) (reduced radix)
(> fifth-power n) (reduced false)))) ;;else, return nil, continue
(drop (inc start-root) (range))))
(def solutions
"Disproves Euler's conjecture, returns a lazy seq of counter-examples.
Note: in Clojure, `for` is *not* an imperative for-loop, but list comprehension, see:
https://clojuredocs.org/clojure.core/for ."
(for [a (drop 6 (range))
b (range 1 a)
c (range 1 b)
d (range 1 c)
:let [radix (->> [a b c d]
(map ⁵)
(reduce +)
(⁵? a))]
:when radix]
[a b c d radix]))
(first solutions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment