TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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.
-
I can name that tune in 23 characters.... of course I am not a newbie ..
-
Ah man. Why you gotta go put rules on this one? :D
-
I can name that tune in 23 characters.... of course I am not a newbie ..
Are you counting spaces?
-
are there any hints...?
-
Sure dubb, Use a logical test.
-
I can name that tune in 23 characters.... of course I am not a newbie ..
Are you counting spaces?
Counting spaces
-
Okay, anyone done yet?
-
(defun inbetween (num1 num2 num3)
(and (> num1 num2)
(< num1 num3)
)
)
Here's mine.
-
< post deleted >
-
Outstanding!
Why did you choose "and"?
-
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.
-
Optimized for size ... functionalized ... essentially the same as Will's ...
(defun inbetween (@t @l @u)
(and(< @l @t)(> @u @t))
)
-
< post deleted >
-
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?
-
...you just told them the answer!?
-
All that means is that as a programmer you need to code it properly. duh.. :D
-
All that means is that programmers in Seattle are leaving big security holes in MSIE :D
Oh, no one saw my contribution? :lol:
-
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:
(defun inbetween (@t @l @u)
(and(< (min @l @u) @t)(> (max @l @u) @t))
)
-
To determine if x is between a and b ...
(< a x b)
What am I missing?
-
What am I missing?
Sequence of arguments is all. Not necessarily an issue as much as a convenience, I would say.
-
Cool MP, good to see you.
Here is your code the other way. :)
(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
-
Hey MP, Hows life been treating ya?
Well this thread was about the newbies, but it kinda got overrun a bit.