We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c3d9c40 commit 1c51061Copy full SHA for 1c51061
Math.ark
@@ -62,6 +62,25 @@
62
(impl (- n 1) c (+ p c))))))
63
(impl n 0 1) }))
64
65
+# @brief Check if a given number is prime
66
+# @param n the number
67
+# @author https://github.com/SuperFola
68
+(let prime? (fun (n)
69
+ (if (= 2 n)
70
+ true
71
+ (if (or (= 0 (mod n 2)) (= 1 n))
72
+ false
73
+ {
74
+ (let k (math:ceil (+ 1 (sqrt n))))
75
+ (mut i 3)
76
+ (mut continue true)
77
+
78
+ (while (and continue (< i k)) {
79
+ (if (= 0 (mod n i))
80
+ (set continue false))
81
+ (set i (+ 2 i)) })
82
+ continue }))))
83
84
# @brief Returns the list of a number's divisors
85
# @param n the number
86
# @author https://github.com/Wafelack
0 commit comments