From 817415a43c977bfc90abec58c9bbec348d98b9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 13 Aug 2022 02:14:43 -0300 Subject: Initial Commit --- main.rkt | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 main.rkt (limited to 'main.rkt') diff --git a/main.rkt b/main.rkt new file mode 100644 index 0000000..845bd18 --- /dev/null +++ b/main.rkt @@ -0,0 +1,44 @@ +#lang racket + +(require "modulo-arithmetic.rkt") + +;; 4a^3 + 27b^2 != 0 +(define a 2) +(define b 3) + +(define (point-in-curve lst) + (define x (car lst)) + (define y (cadr lst)) + (= (* y y) (+ (* x x x) (* x a) b))) + +(define (add p q) + (cond ((not (point-in-curve p)) + q) + ((not (point-in-curve q)) + p) + (else + (define xp (first p)) + (define xq (first q)) + (define yp (second p)) + (define yq (second q)) + (let* ((m (if (equal? p q) + (/ (+ (* 3 xp xp) a) + (* 2 yp)) + (/ (- yp yq) + (- xp xq)))) + (xr (- (* m m) xp xq)) + (yr (+ yp (* m (- xr xp))))) + (list xr (- yr)))))) + +(define (mul n p) + (cond ((= n 0) + (list 0 0)) + ((= n 1) + p) + (else + (add p (mul (sub1 n) p))))) + +(define curve-points (filter point-in-curve + (cartesian-product (range cardinality) + (range cardinality)))) + -- cgit v1.2.3