Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active April 25, 2024 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PEZ/6ebd843c6422d507efa327bee4bf0b50 to your computer and use it in GitHub Desktop.
Save PEZ/6ebd843c6422d507efa327bee4bf0b50 to your computer and use it in GitHub Desktop.
Implement range – Rich 4Clojure Problem 34 – See: https://github.com/PEZ/rich4clojure
(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
Copy link

amiskov commented Aug 29, 2021

(def __ #(take (- %2 %1) (iterate inc %1)))

@szalai1
Copy link

szalai1 commented Sep 23, 2021

(def __ #(loop [a %1
                 b %2
                 res []] (if (< a b ) (recur (inc a) b (conj res a)) res) ))

@StanTheBear
Copy link

#(take (- %2 %1) (iterate inc %1) )

@DjebbZ
Copy link

DjebbZ commented Jun 25, 2023

(defn __ [start end]
  (take (- end start) (iterate inc start)))

@natef-GuruTech
Copy link

(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