Sha256: e02266876900d6b5beed3edb1d3943c9518f1ac6dbee57663c3db35ae7a912c9

Contents?: true

Size: 509 Bytes

Versions: 396

Compression:

Stored size: 509 Bytes

Contents

(defmodule difference-of-squares
  (export (square-of-sums 1)
          (sum-of-squares 1)))

(defun square (x) (trunc (math:pow x 2)))

(defun square-of-sums (x) (square (lists:sum (lists:seq 1 x))))

;; Traverses the list only once.
(defun sum-of-squares (x)
  (lists:foldl
    (lambda (x sum)
      (+ (square x) sum))
    0
    (lists:seq 1 x)))

;; Unnecessarily traverses the list twice, though maybe easier to read.
;; (defun sum-of-squares (x)
;;   (lists:sum (lists:map #'square/1 (lists:seq 1 x))))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.179 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.178 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.177 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.176 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.175 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.174 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.173 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.172 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.171 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.170 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.169 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.167 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.166 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.165 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.164 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.163 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.162 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.161 tracks/lfe/exercises/difference-of-squares/src/example.lfe
trackler-2.2.1.160 tracks/lfe/exercises/difference-of-squares/src/example.lfe