From bfa557c6a1c050336d2928b7486093432f62a28d Mon Sep 17 00:00:00 2001 From: Nic McPhee Date: Tue, 10 Nov 2020 16:59:32 -0600 Subject: [PATCH 1/2] Fix bug in `random-int` The `random-int` function in both `number-io` and `smallest` subtracted a floating point value (`100.0`), which means they were both _actually_ returning a float instead of an int. This removes both of the ".0"s so that they return integers as advertised. --- src/propeller/problems/software/number_io.cljc | 2 +- src/propeller/problems/software/smallest.cljc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/propeller/problems/software/number_io.cljc b/src/propeller/problems/software/number_io.cljc index 698feaf..cf8819b 100755 --- a/src/propeller/problems/software/number_io.cljc +++ b/src/propeller/problems/software/number_io.cljc @@ -37,7 +37,7 @@ (defn random-float [] (- (* (rand) 200) 100.0)) ; Random integer between -100 and 100 -(defn random-int [] (- (rand-int 201) 100.0)) +(defn random-int [] (- (rand-int 201) 100)) (def instructions (utils/not-lazy diff --git a/src/propeller/problems/software/smallest.cljc b/src/propeller/problems/software/smallest.cljc index e77c615..915043e 100755 --- a/src/propeller/problems/software/smallest.cljc +++ b/src/propeller/problems/software/smallest.cljc @@ -38,7 +38,7 @@ ;; ============================================================================= ; Random integer between -100 and 100 -(defn random-int [] (- (rand-int 201) 100.0)) +(defn random-int [] (- (rand-int 201) 100)) (def instructions (utils/not-lazy From a8e9de97ce57a99d96e0e8c766e129e8feffb843 Mon Sep 17 00:00:00 2001 From: Lee Spector Date: Mon, 23 Nov 2020 09:57:04 -0500 Subject: [PATCH 2/2] Fix peek-stack for false on boolean stack --- .gitignore | 3 +++ src/propeller/push/state.cljc | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d18f225..5211373 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ pom.xml.asc /.nrepl-port .hgignore .hg/ +out +notes +.idea/ \ No newline at end of file diff --git a/src/propeller/push/state.cljc b/src/propeller/push/state.cljc index 5026dec..f06bc89 100755 --- a/src/propeller/push/state.cljc +++ b/src/propeller/push/state.cljc @@ -38,9 +38,9 @@ ;; Returns the top item on the stack (defn peek-stack [state stack] - (if-let [top-item (first (get state stack))] - top-item - :no-stack-item)) + (if (empty? (get state stack)) + :no-stack-item + (first (get state stack)))) ;; Returns the top n items on the stack, as a chunk. If there are less than n ;; items on the stack, returns the entire stack