TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: myloveflyer on May 30, 2011, 04:54:39 AM
-
For example:
"165478952"
Results: "A" "/" "Y" "4"
-
Check this . :-)
(vl-list->string '(65 47 89 52))
-
(defun c:test()
(setq a (getstring "\nEnter numbers:"))
(setq b (vl-list->string ' a))
(princ)
)
Finally, the error
How to make a transition to form groups and then conversion
-
Not certain to understand the task, but this works with the example.
(foo "165478952") returns ("A" "/" "Y" "4")
(defun foo (str / num char lst)
(if (numberp (setq num (read str)))
(while (< 9 (setq char (rem num 100)))
(setq num (/ num 100)
lst (cons (chr char) lst)
)
)
)
)
-
Like this .... :-)
(defun c:test (/ ss)
(if (setq ss (getint "\n Enter Number (ascii) :"))
(print (chr ss))
)
(princ)
)
-
I think this task needs more clarification, but perhaps:
(defun num->str ( num )
(cond
( (< 31 num 100) (list (chr num)))
( (< 31 num) (append (num->str (/ num 100)) (num->str (rem num 100))))
)
)
_$ (num->str 165478952)
("A" "/" "Y" "4")
-
Like this .... :-)
(defun c:test (/ ss)
(if (setq ss (getint "\n Enter Number (ascii) :"))
(print (chr ss))
)
(princ)
)
Thanks coder,but "enter number"requires an integer between -32768 and 32767.My version is 04 CAD
Not certain to understand the task, but this works with the example.
(foo "165478952") returns ("A" "/" "Y" "4")
(defun foo (str / num char lst)
(if (numberp (setq num (read str)))
(while (< 9 (setq char (rem num 100)))
(setq num (/ num 100)
lst (cons (chr char) lst)
)
)
)
)
thanks,gile,When the input number is 11, when an error。
thanks,LEE,As your programs and gile error
I may be the expression of this program is not clear, I mean that when I enter the number as 11, when, for example: 16738883211, rounding first need to form a list ("67" "38" "88" "32" "11"), the group then identified the corresponding code in general is to enter the figures are rounded down first, and then behind the two figures as a whole, the basic input of the number of digits is 9 or 11, Thank you for your help, hope that help me look,
-
Your figure of 16738883211 exceeds the signed integer limit for 32-bit systems (2147483647 = ((2^32)/2)-1) and is hence converted to a real in LISP.
-
LEE, you mean 11 out of 32-bit systems has been limited, indeed, as you said the program will error, whether to enter the number from 11 into 9 digits, so I would like to no error Right?
-
LEE, you mean 11 out of 32-bit systems has been limited, indeed, as you said the program will error, whether to enter the number from 11 into 9 digits, so I would like to no error Right?
Use this instead perhaps:
(defun num->str ( num )
(cond
( (< 31 num 100) (list (chr (fix num))))
( (< 31 num) (append (num->str (/ num 100)) (num->str (rem num 100))))
)
)
What are you trying to achieve?
-
(foo "165478952") returns ("A" "/" "Y" "4")
(num->str 165478952) returns ("A" "/" "Y" "4")
I need 11-bit digital input when you are as follows:
(foo "16547895233") returns ("A" "/" "Y" "4" "!")
(num->str 16547895233) returns ("A" "/" "Y" "4" "!")
-
Would keeping up with a count variable work by taking the substring of count + 2?
I not fimilar enough with lisp but get sslen and while count < slen
do your magic here
-
Nice idea Jeff, how about this approach:
(defun decode ( x / l )
(setq x (reverse (vl-string->list x)))
(while (cadr x)
(setq l (cons (chr (- (+ (car x) (* 10 (cadr x))) 528)) l) x (cddr x))
)
l
)
_$ (decode "165478952")
("A" "/" "Y" "4")
Or, using substr (likely to be slower):
(defun decode2 ( s / l x )
(repeat (/ (setq x (strlen s)) 2)
(setq l (cons (chr (atoi (substr s (setq x (1- x))))) l)
s (substr s 1 (setq x (1- x)))
)
)
l
)
-
Nice Lee,
I played with it for a little bit and could'nt get it to work.
-
I seem to be missing a couple things here ...
- Is the original data correct? i.e. why the superfluous 1 prefix ("165478952")?
- What assurances does the coder have that ASCII values less than 10 or greater than 99 are not in the string? Subtitle: it would screw up the pairing.
- What is the context of the challenge?
Mommy I need a coffee. Back to you Jim.
-
- Is the original data correct? i.e. why the superfluous 1 prefix ("165478952")?
- What assurances does the coder have that ASCII values less than 10 or greater than 99 are not in the string? Subtitle: it would screw up the pairing.
- What is the context of the challenge?
Oh exactly - I'm with you on all three points. I'm just going with the info given :|
-
oh (http://www.theswamp.org/screens/mp/oh.gif)
Can I get you a coffee too?
:D
-
I completely agree Michael.
Rather than a "challenge" this thread appears to me as an enigma.
-
ok, 3 coffee to go :-D
-
I'll have an espresso 8-)
-
(http://dl.dropbox.com/u/10117392/happy_coffee.png)
-
:lol: Cheers :lol:
-
Nice idea Jeff, how about this approach:
(defun decode ( x / l )
(setq x (reverse (vl-string->list x)))
(while (cadr x)
(setq l (cons (chr (- (+ (car x) (* 10 (cadr x))) 528)) l) x (cddr x))
)
l
)
_$ (decode "165478952")
("A" "/" "Y" "4")
Or, using substr (likely to be slower):
(defun decode2 ( s / l x )
(repeat (/ (setq x (strlen s)) 2)
(setq l (cons (chr (atoi (substr s (setq x (1- x))))) l)
s (substr s 1 (setq x (1- x)))
)
)
l
)
Nice,LEE,But for less than 31 if there is no corresponding data in ASCII, for example:
(decode "105122231")
("\005" "\014" "\026" "\037")
Give each person a cup of coffee :laugh:
-
http://www.asciitable.com/
using that site
How about this.
2 == Start of Text
3 == End of Text
And in between must at least equal 32 and can equal up to 126.
So for example:
("2457646124553")
2 starts
45
76
46
124 So when a 1 appears as example above it cannot be followed by a number higher than 2 and if 2 the next number must be 6 or less.
55
3 ends
-
/giveup
-
Jeff H, difficult for you than I will.
LEE, thank you, now my needs have been met, the conversion of data can be converted over to go back? With vl-list-> string?
-
/giveup
If me
Never
Been playing with my son and usually is asleep by now but poor guy just went downhill quick and fever shot up etc....
If you got a solution go ahead or I know you do I won't look until I fail a couple of times
-
/giveup
If me
Never
Been playing with my son and usually is asleep by now but poor guy just went downhill quick and fever shot up etc....
If you got a solution go ahead or I know you do I won't look until I fail a couple of times
Jeff ,Hope that the healthy growth of your son, your perseverance worthy of our study.
-
Thanks mloveflyer,
I have messed with it a little and have not come up with anything useful.