Skip to content

Commit

Permalink
revert to test-words; merge sieve-test.8th and test.8th
Browse files Browse the repository at this point in the history
  • Loading branch information
glennj committed Oct 11, 2023
1 parent 33ad8fa commit beea96c
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 265 deletions.
9 changes: 7 additions & 2 deletions bin/test-no-docker
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ make_test_dir() {
local key=$2
(
cd "$exercise_dir"
cp -t "$test_dir" test.8th test-words.8th "${slug}-tests.8th"
cp test-words.8th "$test_dir"
while IFS= read -r test; do
cp "$test" "$test_dir"
done < <(
jq -r '.files.test[]' .meta/config.json
)
while IFS= read -r solution; do
cp "$solution" "$test_dir/$slug.8th"
done < <(
Expand All @@ -35,7 +40,7 @@ test_one() {
fi
(
cd "$test_dir" || die "cannot cd to $test_dir"
8th test.8th
8th -f test.8th
)
}

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/sieve/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"sieve.8th"
],
"test": [
"sieve-tests.8th"
"test.8th"
],
"example": [
".meta/example.8th"
Expand Down
31 changes: 17 additions & 14 deletions exercises/practice/sieve/.meta/example.8th
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,35 @@
;

: mark-multiples-of \ a i -- a
2dup a:@ !if 2drop ;; then
drop
dup dup n:* \ a i idx (initial idx is i^2)
repeat
third over \ a i idx a idx
false a:! \ a i idx a
drop over n:+
dup r@ n:>
until!
2dup a:@ if
drop
dup dup n:* \ a i idx (initial idx is i^2)
repeat
third over \ a i idx a idx
false a:! \ a i idx a
drop over n:+
dup r@ n:> \ quit loop when idx > n (from r-stack)
until!
then
2drop
;

\ from 2 to √n, mark multiples of primes as non-prime
: mark-multiples \ a -- a
' mark-multiples-of 2 r@ n:sqrt loop
;

: extract-primes \ a1 -- a2
a:new >r
( if r> a:push >r else drop then ) a:each
drop r>
a:new swap
\ a:each removes the array from the stack while it's running
( if a:push else drop then ) a:each
drop
;

: primes \ n -- a
>r
>r \ store `n` on r-stack
make-flag-array
mark-multiples
extract-primes
rdrop
rdrop \ clear `n` from r-stack
;
90 changes: 0 additions & 90 deletions exercises/practice/sieve/harness.8th

This file was deleted.

139 changes: 0 additions & 139 deletions exercises/practice/sieve/libs/utils/test

This file was deleted.

Loading

0 comments on commit beea96c

Please sign in to comment.