diff options
123 files changed, 7351 insertions, 2425 deletions
diff --git a/challenge-242/paulo-custodio/forth/ch-1.fs b/challenge-242/paulo-custodio/forth/ch-1.fs index 6de8f3a904..20fe605fd2 100644 --- a/challenge-242/paulo-custodio/forth/ch-1.fs +++ b/challenge-242/paulo-custodio/forth/ch-1.fs @@ -26,8 +26,12 @@ CREATE arr1 256 CELLS ALLOT CREATE arr2 256 CELLS ALLOT -: array_size ( arr-addr -- size-addr ) ; -: array[] ( arr-addr i -- elem-addr ) 1+ CELLS + ; +: array_size ( arr-addr -- size-addr ) +; + +: array[] ( arr-addr i -- elem-addr ) + 1+ CELLS + +; : array_push_back ( arr-addr n -- ) { arr n } diff --git a/challenge-244/paulo-custodio/forth/ch-1.fs b/challenge-244/paulo-custodio/forth/ch-1.fs new file mode 100644 index 0000000000..02010237d9 --- /dev/null +++ b/challenge-244/paulo-custodio/forth/ch-1.fs @@ -0,0 +1,79 @@ +#! /usr/bin/env gforth + +\ Challenge 244 +\ +\ Task 1: Count Smaller +\ Submitted by: Mohammad S Anwar +\ +\ You are given an array of integers. +\ +\ Write a script to calculate the number of integers smaller than the integer +\ at each index. +\ Example 1 +\ +\ Input: @int = (8, 1, 2, 2, 3) +\ Output: (4, 0, 1, 1, 3) +\ +\ For index = 0, count of elements less 8 is 4. +\ For index = 1, count of elements less 1 is 0. +\ For index = 2, count of elements less 2 is 1. +\ For index = 3, count of elements less 2 is 1. +\ For index = 4, count of elements less 3 is 3. +\ +\ Example 2 +\ +\ Input: @int = (6, 5, 4, 8) +\ Output: (2, 1, 0, 3) +\ +\ Example 3 +\ +\ Input: @int = (2, 2, 2) +\ Output: (0, 0, 0) + +CREATE nums 256 CELLS ALLOT +CREATE smaller 256 CELLS ALLOT + +: array_size ( arr-addr -- size-addr ) +; + +: array[] ( arr-addr i -- elem-addr ) + 1+ CELLS + +; + +: array_push_back ( arr-addr n -- ) + { arr n } + arr array_size @ ( size ) + arr SWAP array[] ( elem-addr ) + n SWAP ! + arr array_size 1 SWAP +! +; + +: .array ( arr -- ) + { arr } |
