June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -4,4 +4,4 @@
(and (< 1 x)
(odd? x)
(not-any? (partial divides? x)
(range 3 (math/sqrt x) 2)))))
(range 3 (inc (Math/sqrt x)) 2)))))

View file

@ -7,4 +7,4 @@
(and (integer? x)
(< 1 x)
(not-any? (partial divides? x)
(take-while (partial > (math/sqrt x)) primes)))))
(take-while (partial >= (Math/sqrt x)) primes)))))

View file

@ -0,0 +1,15 @@
;; Project : Primality by trial division
;; Date : 2018/03/06
;; Author : Gal Zsolt [~ CalmoSoft ~]
;; Email : <calmosoft@gmail.com>
(defun prime(n)
(setq flag 0)
(loop for i from 2 to (- n 1) do
(if (= (mod n i) 0)
(setq flag 1)))
(if (= flag 0)
(format t "~d is a prime number" n)
(format t "~d is not a prime number" n)))
(prime 7)
(prime 8)

View file

@ -0,0 +1,8 @@
on isPrime (n)
if n<=1 or (n>2 and n mod 2=0) then return FALSE
sq = sqrt(n)
repeat with i = 3 to sq
if n mod i = 0 then return FALSE
end repeat
return TRUE
end

View file

@ -0,0 +1,5 @@
primes = []
repeat with i = 0 to 100
if isPrime(i) then primes.add(i)
end repeat
put primes

View file

@ -0,0 +1,8 @@
func is_prime(n) {
return (n >= 2) if (n < 4)
return false if (n%%2 || n%%3)
for k in (5 .. n.isqrt -> by(6)) {
return false if (n%%k || n%%(k+2))
}
return true
}

View file

@ -0,0 +1,27 @@
Option Explicit
Sub FirstTwentyPrimes()
Dim count As Integer, i As Long, t(19) As String
Do
i = i + 1
If IsPrime(i) Then
t(count) = i
count = count + 1
End If
Loop While count <= UBound(t)
Debug.Print Join(t, ", ")
End Sub
Function IsPrime(Nb As Long) As Boolean
If Nb = 2 Then
IsPrime = True
ElseIf Nb < 2 Or Nb Mod 2 = 0 Then
Exit Function
Else
Dim i As Long
For i = 3 To Sqr(Nb) Step 2
If Nb Mod i = 0 Then Exit Function
Next
IsPrime = True
End If
End Function