Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #52780

:Re: A simple lisp problem.

From "Robert L." <No_spamming@noWhere_7073.org>
Newsgroups comp.lang.forth
Subject :Re: A simple lisp problem.
Date 2016-11-21 00:16 +0000
Organization Aioe.org NNTP Server
Message-ID <o0tecm$1ora$1@gioia.aioe.org> (permalink)

Show all headers | View raw


Frank Schwieterman wrote:

> >I am Lisp beginner and I am doing a simple execise on lisp. I was asked
> >to write a lisp program , by using either recursion or do, to return
> >true if the difference between each successive pair of the them is 1.
> >
> >ie:
> >
> >>(difference '(2 1))
> >T
> >>(difference'(3 4 5 6 5 4))
> >T
> >>(differnce '(3 4 5 3))
> >NIL
 ....
> 
> (defun difference (param)
>      (if (> (length param) 1)
>         (if (<= (abs (- (first param) (first (rest param)))) 1 )
>            (difference (rest param))
>            nil
>            )
>         T
>         )
>      )


Ruby:

def diff1 array
  array.each_cons(2).all?{|a,b| 1 == (a-b).abs}
end


diff1 [2,1]
    ==>true
diff1 [3,4,5,6,5,4]
    ==>true
diff1 [3,4,5,3]
    ==>false


In Forth?


-- 
Again, commenters focused on the double standard whereby Jews advocate
multiculturalism and immigration for Europe, but have Israel as an avowedly
Jewish state to fall back on....
theoccidentalobserver.net/2015/11/douglas-murrays-warning-to-the-jewish-community

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

:Re: A simple lisp problem. "Robert L." <No_spamming@noWhere_7073.org> - 2016-11-21 00:16 +0000

csiph-web