TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: JohnK on January 05, 2005, 11:07:09 AM

Title: (challange - newbie) in between two numbers
Post by: JohnK on January 05, 2005, 11:07:09 AM
I want a way to see if a number is inbetween to numbers.
For example:
Is the number 4 inbetween the numbers 2 89?

Write a lisp that will tell me. The lisp should return either "T" or "nil"

Rules: Make a post when you have your lisp complete. After three hours we will post our lisp solutions.
Title: (challange - newbie) in between two numbers
Post by: Keith™ on January 05, 2005, 11:40:10 AM
I can name that tune in 23 characters.... of course I am not a newbie ..
Title: (challange - newbie) in between two numbers
Post by: whdjr on January 05, 2005, 11:40:51 AM
Ah man.  Why you gotta go put rules on this one? :D
Title: (challange - newbie) in between two numbers
Post by: CADaver on January 05, 2005, 01:12:21 PM
Quote from: Keith
I can name that tune in 23 characters.... of course I am not a newbie ..
Are you counting spaces?
Title: (challange - newbie) in between two numbers
Post by: dubb on January 05, 2005, 01:17:53 PM
are there any hints...?
Title: (challange - newbie) in between two numbers
Post by: JohnK on January 05, 2005, 01:28:05 PM
Sure dubb, Use a logical test.
Title: (challange - newbie) in between two numbers
Post by: Keith™ on January 05, 2005, 01:41:57 PM
Quote from: CADaver
Quote from: Keith
I can name that tune in 23 characters.... of course I am not a newbie ..
Are you counting spaces?


Counting spaces
Title: (challange - newbie) in between two numbers
Post by: JohnK on January 05, 2005, 01:46:06 PM
Okay, anyone done yet?
Title: (challange - newbie) in between two numbers
Post by: whdjr on January 05, 2005, 01:57:26 PM
Code: [Select]
(defun inbetween (num1 num2 num3)
  (and (> num1 num2)
       (< num1 num3)
  )
)


Here's mine.
Title: (challange - newbie) in between two numbers
Post by: Kerry on January 05, 2005, 02:03:53 PM
< post deleted >
Title: (challange - newbie) in between two numbers
Post by: JohnK on January 05, 2005, 02:04:27 PM
Outstanding!

Why did you choose "and"?
Title: (challange - newbie) in between two numbers
Post by: whdjr on January 05, 2005, 02:06:57 PM
Quote from: Se7en
Outstanding!

Why did you choose "and"?


Because with and they both have to be true or it's false.
You did ask for a T or nil answer.
Title: (challange - newbie) in between two numbers
Post by: Keith™ on January 05, 2005, 02:13:21 PM
Optimized for size ... functionalized ... essentially the same as Will's ...
Code: [Select]

(defun inbetween (@t @l @u)
  (and(< @l @t)(> @u @t))
)
Title: (challange - newbie) in between two numbers
Post by: Kerry on January 05, 2005, 02:19:47 PM
< post deleted >
Title: (challange - newbie) in between two numbers
Post by: JohnK on January 05, 2005, 02:22:45 PM
Quote from: whdjr
Because with and they both have to be true or it's false.
You did ask for a T or nil answer.


Aweosme!

Now, Can you tell me any problems you might see with this procedure the way it is?
Title: (challange - newbie) in between two numbers
Post by: JohnK on January 05, 2005, 02:24:25 PM
...you just told them the answer!?
Title: (challange - newbie) in between two numbers
Post by: whdjr on January 05, 2005, 02:29:26 PM
All that means is that as a programmer you need to code it properly.  duh.. :D
Title: (challange - newbie) in between two numbers
Post by: SMadsen on January 05, 2005, 03:15:57 PM
All that means is that programmers in Seattle are leaving big security holes in MSIE :D

Oh, no one saw my contribution? :lol:
Title: (challange - newbie) in between two numbers
Post by: Keith™ on January 05, 2005, 03:22:35 PM
precisely ... The rules were followed .... the numbers were given and the code was written to match the numbers, not the other way around. Of course, it IS good practice to code to many scenarios, BUT if you quantify the syntax and code to that, the overhead is significantly lower.

It is always best to code to the simplest form, otherwize you end up creating bloatware just like Microsoft, I remember when Windows could be loaded on a 100MB drive and have tons of extra space... now you are required a minimum of 2GB just to install windows where 8Mb of memory was sufficient for most programming 10 years ago, now you almost MUST have 512Mb. The issue has to do with the size of the code and the gobs of things put in the code that are designed to circumvent user stupidity.

To "fix" the code so the user can enter the range values .. use this:
Code: [Select]

(defun inbetween (@t @l @u)
  (and(< (min @l @u) @t)(> (max @l @u) @t))
)
Title: (challange - newbie) in between two numbers
Post by: MP on January 05, 2005, 04:07:02 PM
To determine if x is between a and b ...

(< a x b)

What am I missing?
Title: (challange - newbie) in between two numbers
Post by: SMadsen on January 05, 2005, 04:53:30 PM
Quote from: MP
What am I missing?

Sequence of arguments is all. Not necessarily an issue as much as a convenience, I would say.
Title: (challange - newbie) in between two numbers
Post by: CAB on January 05, 2005, 05:18:18 PM
Cool MP, good to see you.
Here is your code the other way. :)
Code: [Select]
(defun between (mid start end) (< start mid end))

(between 5 1 10)
(between 1 3 10)
(between 5 8 10)
(between 5 5 10)

T
nil
nil
nil
Title: (challange - newbie) in between two numbers
Post by: JohnK on January 05, 2005, 09:43:19 PM
Hey MP, Hows life been treating ya?

Well this thread was about the newbies, but it kinda got overrun a bit.