Last active
April 25, 2024 15:57
-
-
Save PEZ/6ebd843c6422d507efa327bee4bf0b50 to your computer and use it in GitHub Desktop.
Implement range – Rich 4Clojure Problem 34 – See: https://github.com/PEZ/rich4clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns rich4clojure.easy.problem-034 | |
(:require [hyperfiddle.rcf :refer [tests]])) | |
;; = Implement range = | |
;; By 4Clojure user: dbyrne | |
;; Difficulty: Easy | |
;; Tags: [seqs core-functions] | |
;; | |
;; Write a function which creates a list of all integers | |
;; in a given range. | |
(def restricted [range]) | |
(def __ :tests-will-fail) | |
(comment | |
) | |
(tests | |
(__ 1 4) := '(1 2 3) | |
(__ -2 2) := '(-2 -1 0 1) | |
(__ 5 8) := '(5 6 7)) | |
;; To participate, fork: | |
;; https://github.com/PEZ/rich4clojure | |
;; Post your solution below, please! |
amiskov
commented
Aug 29, 2021
(def __ #(loop [a %1
b %2
res []] (if (< a b ) (recur (inc a) b (conj res a)) res) ))
#(take (- %2 %1) (iterate inc %1) )
(defn __ [start end]
(take (- end start) (iterate inc start)))
(def __ (fn myfn [start end]
(if (= start end)
'()
(cons start (myfn (inc start) end)))))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment