Author Topic: Increment Challenge..  (Read 8406 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
Increment Challenge..
« on: September 07, 2016, 05:02:13 PM »
Hi All,..

for any who are interested to this challenge..
The function must increment Alphabetic value with two (2) parameter...

ex: (AphaIncrement  A B)

A= Start Letter as a string
B= Increment value as integer (this can be also negative value)

So the challenge is this...
(AphaIncrement  "A" 1) = "B"
(AphaIncrement  "D" 3) = "G"
(AphaIncrement  "AAP" 1) = "AAQ"
(AphaIncrement  "BAU" 2) = "BAW"
(AphaIncrement  "A" -1) = "Z"
(AphaIncrement  "FFFC" 2) = "FFFE"

the goal is to have,...
a,b,c,d,e,....z,
aa,ab,ac,ad,ae...az,
ba,bc,bd,be,..bz
ca,cb,cd,ce,...cz,..
etc...

$5 for who can make this....

Get ready !...
this challenge will start NOW !

Good luck !  :knuppel2:
Keep smile...

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Increment Challenge..
« Reply #1 on: September 07, 2016, 05:20:25 PM »
(AphaIncrement  "A" -1) = "Z"
are you sure about this one?

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Increment Challenge..
« Reply #2 on: September 07, 2016, 06:04:21 PM »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Increment Challenge..
« Reply #3 on: September 07, 2016, 06:52:22 PM »
Should've held out for a sammich.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Increment Challenge..
« Reply #4 on: September 07, 2016, 09:54:31 PM »
(AphaIncrement  "A" -1) = "Z"
are you sure about this one?

You're right....no sense..it must be nil or "A"
+1
« Last Edit: September 07, 2016, 09:58:53 PM by Andrea »
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Increment Challenge..
« Reply #5 on: September 07, 2016, 09:57:08 PM »
http://lee-mac.com/columnreference.html#incalpha

LEE !!!!!!!!!!!!!!   that's sick !  4 recursive in row !?
you're just amazing.. :uglystupid2:

one thing....your code do not allow negative value..as increment.
Keep smile...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Increment Challenge..
« Reply #6 on: September 08, 2016, 03:24:08 AM »
(AphaIncrement  "A" -1) = "Z"
are you sure about this one?

You're right....no sense..it must be nil or "A"
+1
You need a representation for zero. If "A" is the first digit it follows that it represents zero. But this is counterintuitive. And if "A" is zero then "AA" is zero as well.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Increment Challenge..
« Reply #7 on: September 08, 2016, 05:12:19 AM »
You need a representation for zero. If "A" is the first digit it follows that it represents zero. But this is counterintuitive. And if "A" is zero then "AA" is zero as well.
i believe Lee's code is written to deal with MS Excel, so it's got no zero

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Increment Challenge..
« Reply #8 on: September 08, 2016, 05:42:04 AM »
i have this to work with custom "numeral" systems based on positional notation
no negative numbers
Code: [Select]
(defun vk_AlphaBet2Dec (ABC AlphaBet / Len)
  (setq Len (strlen AlphaBet))
  (if (/= ABC "")
    (+ (* (expt Len (1- (strlen ABC)))
  (vl-string-position (ascii (substr ABC 1 1)) AlphaBet)
       )
       (vk_AlphaBet2Dec (substr ABC 2) AlphaBet)
    )
    0
  )
)
(defun vk_Dec2AlphaBet (Dec AlphaBet / Len)
  (setq Len (strlen AlphaBet))
  (if (< Dec Len)
    (substr AlphaBet (1+ Dec) 1)
    (strcat (vk_Dec2AlphaBet (/ Dec Len) AlphaBet)
    (substr AlphaBet (1+ (rem Dec Len)) 1)
    )
  )
)
Code: [Select]
(vk_Dec2AlphaBet 35 "01")
(vk_Dec2AlphaBet 35 "0123456789")
(vk_Dec2AlphaBet 35 "0123456789ABCDEF")
(vk_Dec2AlphaBet 35 "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
(vk_Dec2AlphaBet 35 "Aa")
(vk_Dec2AlphaBet 35 "theSwamp")

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Increment Challenge..
« Reply #9 on: September 08, 2016, 07:41:17 AM »
Hi,

Quite a long time since I've been here...

You can see the (quite old too) topic.
Speaking English as a French Frog

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Increment Challenge..
« Reply #10 on: September 08, 2016, 08:17:32 AM »
Code: [Select]
(defun ALE_ZetaStrIncVal (ZetStr IncVal / SttStr SttLen)
  (if (eq "" (setq SttStr (vl-string-right-trim "Z" ZetStr)))
    (strcat (vl-string-translate "Z" "A" ZetStr) "A")
    (strcat
      (substr SttStr 1 (setq SttLen (1- (strlen SttStr))))
      (chr (+ IncVal (vl-string-elt SttStr SttLen)))
      (if (eq ZetStr SttStr)
        ""
        (vl-string-translate "Z" "A" (substr ZetStr (+ 2 SttLen)))
      )
    )
  )
)
Code: [Select]
(ALE_ZetaStrIncVal  "A" 1) "B"
(ALE_ZetaStrIncVal  "D" 3) "G"
(ALE_ZetaStrIncVal  "AAP" 1) "AAQ"
(ALE_ZetaStrIncVal  "BAU" 2) "BAW"
(ALE_ZetaStrIncVal  "A" -1) "@"  <<<<<<<<<<<<<<<<<
(ALE_ZetaStrIncVal  "FFFC" 2) "FFFE"

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Increment Challenge..
« Reply #11 on: September 08, 2016, 10:06:38 AM »
this is my quick attempt..
Working with negative value and Upper or lower case :smitten:

Code: [Select]
(defun AA:setcar (startwith increment / carpref iba_alphabet cval str# startwith2 nextcar newstartwith)
  (setq startwith2 startwith)
  (if (< (ascii (substr startwith 1 1)) 96)
    (setq cval 64)
    (setq cval 96)
  )
  (setq iba_alphabet nil)
  (repeat 26
    (setq iba_alphabet (append iba_alphabet (list (chr (setq cval (1+ cval))))))
  )
  (setq carpref "")
  (if (> (setq str# (strlen startwith2)) 1)
    (progn (setq carpref (substr startwith2 1 (1- str#)))
           (setq startwith2 (substr startwith2 str#))
    )
  )
  (if (not
        (setq nextcar (nth (+ increment (vl-position startwith2 iba_alphabet))
                           iba_alphabet
                      )
        )
      )
    (progn (setq carpref startwith)
           (if (> (setq str# (strlen startwith2)) 1)
             (progn (setq carpref (substr startwith2 1 (1- str#)))
                    (setq startwith2 (substr startwith2 str#))
             )
           )
           (setq nextcar startwith2)
    )
  )
  (setq newstartwith (strcat carpref nextcar))
)

Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Increment Challenge..
« Reply #12 on: September 08, 2016, 10:17:53 AM »
Well,...you guys are just amazing..
many concept, diffrent thinking remind me how human can be intelligent sometime.
Thank you very much for sharing all these samples and knowledge.

Now,..who is the winner of this 5$ ?   :whistling:
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Increment Challenge..
« Reply #13 on: September 08, 2016, 11:06:51 AM »
Test Made:
Code: [Select]
(ALE_ZetaStrIncVal "aa" -1)   = "a`"   I think it must be "z"  ?
Code: [Select]
(LM:incalpha "a" 1)  = "AH"  ?   lowercase ?
Code: [Select]
(incsuff "aB" 1 7) = work perfectly
Code: [Select]
(aa:setcar "BB" -1)  = "BA"
(aa:setcar "BA" -1) = Error  :)

so,.....GILE is the winner !
Also,..his code allow numeric value and respect CASE sensitive..
nice coding GILE.  merci.
Keep smile...

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Increment Challenge..
« Reply #14 on: September 08, 2016, 02:29:13 PM »
Merci Andrea,

This routine has been used as base routine in the "Increment" LISP suite which is the ancestor of the quite popular .NET "Increment" plugin on Exchange Apps.
Speaking English as a French Frog