How to resolve the algorithm Sequence of non-squares step by step in the Scheme programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sequence of non-squares step by step in the Scheme programming language
Table of Contents
Problem Statement
Show that the following remarkable formula gives the sequence of non-square natural numbers:
This is sequence A000037 in the OEIS database.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sequence of non-squares step by step in the Scheme programming language
Source code in the scheme programming language
(define non-squares
(lambda (index)
(+ index (inexact->exact (floor (+ (/ 1 2) (sqrt index)))))))
(define sequence
(lambda (function)
(lambda (start)
(lambda (stop)
(if (> start stop)
(list)
(cons (function start)
(((sequence function) (+ start 1)) stop)))))))
(define square?
(lambda (number)
((lambda (root)
(= (* root root) number))
(floor (sqrt number)))))
(define any?
(lambda (predicate?)
(lambda (list)
(and (not (null? list))
(or (predicate? (car list))
((any? predicate?) (cdr list)))))))
(display (((sequence non-squares) 1) 22))
(newline)
(display ((any? square?) (((sequence non-squares) 1) 999999)))
(newline)
You may also check:How to resolve the algorithm SEDOLs step by step in the Perl programming language
You may also check:How to resolve the algorithm Read entire file step by step in the TXR programming language
You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the Haskell programming language
You may also check:How to resolve the algorithm Number names step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Vector step by step in the zkl programming language