aboutsummaryrefslogtreecommitdiff
path: root/challenge-002/paulo-custodio/forth/ch-1.fs
blob: 9cc2f9f03deb067c1465997e7c12455e332df380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#! /usr/bin/env gforth

\ Challenge 002
\
\ Challenge #1
\ Write a script or one-liner to remove leading zeros from positive numbers.

: remove_leading_zeros      ( str len -- str len )
    DUP 0> IF
        BEGIN
            DUP 1 >             \ len > 0
            2 PICK C@ '0' =     \ starts with zero
        AND WHILE
            1 /STRING           \ remove character of string
        REPEAT
    THEN
;

NEXT-ARG remove_leading_zeros TYPE CR BYE