PermaLinkBigBill's Big 7, number 206:37:10 AM
Written By : Scott Good

#2: Using permutated addition.

Doing what?, you may already be asking. That's "permutated" as in "permutation." This is one of those things most people don't know is possible in the formula language. Most of the others who do know about it still don't have any clue why they'd use it.

Well, fear not; I'm here to tell you.

But before I tell you how to use it, let me spend a few paragraphs on what it is. You know what addition is. In Notes there are really two kinds of addition: addition with number (1 + 1 = 2), and addition with strings ("A" + "B" = "AB"). You already knew that.

There's also addition of sets of numbers or strings. List (or array) addition, in other words:

(1 : 2 : 3) + (1 : 2 : 3) = 2 : 4 : 6

("A" : "B" : "C") + ("A" : "B" : "C") = "AA" : "BB" : "CC"

You probably knew that. Permutated addition takes this to the next step by giving you all possible combinations of the numbers or strings being added together. Permutated addition uses the *+ sign instead of just the +. With permutation, you get all the combinations of answers:

(1 : 2 : 3) *+ (1 : 2 : 3) = 2 : 3 : 4 : 3 : 4 : 5 : 4 : 5 : 6

Start with the first number in the first list, 1, then add it to each of the second list's number (1, 2 and 3), then do the same with the 2 and the 3 from the first list. It's a little easier to see what comes from where if you do it with two different strings:

L1 := "A" : "B" : "C";
L2 := "D" : "E" : "F";
L1 *+ L2 = "AD" : "AE" : "AF" : "BD" : "BE" : "BF" : "CD" : "CE" : "CF"

OK, so how do you use it?

Did you ever need a list of sequential numbers? Let's say you need a list of the numbers 1 through 99. How do you get it in the formula language? You could simply type the numbers into a variable:

numList := 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 : 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 20 : 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : 30 : 31 : 32 : 33 : 34 : 35 : 36 : 37 : 38 : 39 : 40 : 41 : 42 : 43 : 44 : 45 : 46 : 47 : 48 : 49 : 50 : 51 : 52 : 53 : 54 : 55 : 56 : 57 : 58 : 59 : 60 : 61 : 62 : 63 : 64 : 65 : 66 : 67 : 68 : 69 : 70 : 71 : 72 : 73 : 74 : 75 : 76 : 77 : 78 : 79 : 80 : 81 : 82 : 83 : 84 : 85 : 86 : 87 : 88 : 89 : 90 : 91 : 92 : 93 : 94 : 95 : 96 : 97 : 98 : 99;

That's exactly what you're trying to get but man it seems like a lot of work. If you're using ND6 you could write an @Formula loop:

@For(n := 1; n <= 99; n := n + 1;
    numList := @If(numList = ""; n; numList : n);
    @Return(numList);
)

I'll admit that works pretty well, but (a) it doesn't work in R5, and (b) I have to go look up the syntax to remember how to do it. You can do the same thing with permutated addition. The only catch here is you need to do it with strings and then convert to numbers if that's what you really need to have:

L1 := "0" : "1" : "2" : "3" : "4" : "5" : "6" : "7" : "8" : "9";
@TextToNumber(@Subset(L1 *+ L1; -99))

The "@Subset" was added because L1 *+ L1 actually returns the numbers zero through 99 and I wanted to remove the leading zero element. If you need the numbers 1 through 999, just do it one more time:

L1 := "0" : "1" : "2" : "3" : "4" : "5" : "6" : "7" : "8" : "9";
@TextToNumber(@Subset(L1 *+ L1 *+ L1; -999))

You say you need the numbers as text and padded with leading zeros (001, 002, 003...999) so they sort properly in a dialog box? That's even easier: Don't do the @TextToNumber conversion:

L1 := @Explode("0~1~2~3~4~5~6~7~8~9"; "~");
@Subset(L1 *+ L1 *+ L1; -999)

(Yes, I could just as easily have typed all ten digits as a colon-separated list like the other examples. This way is quicker...and cooler.)

Yeah, but where can I use this?

Have you ever built a dynamic table using multiple-value fields so you could add extra lines without needing extra fields (You haven't? You need to come to one of my presentations!)? Maybe you want a leading column with line numbers. Let's say one of the columns is really a field called "ProductName." Your number column could be this:

L1 := @Explode("0~1~2~3~4~5~6~7~8~9"; "~");
@TextToNumber(@Subset(@Subset(L1 *+ L1; -99); @Elements(ProductName))

The extra @Subset removes all the extra numbers so you don't get 99 line numbers for three items.

Another place we use this all the time, also associated with dynamic tables, is figuring out which item the user wants to edit. Let's say there are some duplications in the ProductNames field:

"Apples" : "Bananas" : "Carrots" : "Apples" : "Bananas"

You want to pop up a dialog to ask the user which one she wants to edit:

@Prompt([OKCancelList]; "Choose item"; "Which item would you like to edit?"; ""; ProductName);

The problem is, if she picks, say, "Apples," you won't know whether that means to edit line 1 or line 4. With a little string parsing and our new best friend permutation, though, you can know:

L1 := @Explode("0~1~2~3~4~5~6~7~8~9"; "~");
LeadingNums := @Subset(@Subset(L1 *+ L1; -99); @Elements(ProductName)) + ". ";
Choice := @Prompt([OKCancelList]; "Choose item"; "Which item would you like to edit?"; ""; LeadingNums + ProductName);
EditLineNum := @TextToNumber(@Left(Choice; "."));

A little convoluted? Maybe, but let's see you do it with less code. Permutation is surprisingly handy to know about. You watch: Sometime in the next week or so you'll be working on something or, better yet, looking over a co-worker's shoulder and say, "hey, all you need for that is a little permutated addition."

After you whip off a couple of lines of code to the amazement of everyone else on your team, smile a thankful smile at Bill playing golf up there with Saint Peter.

Comments :v

1. Scott Good05/07/2005 11:57:54 AM
Homepage: http://www.scottgood.com


A late addition: Reading through Damien Katz's blog this morning (http://damienkatz.net/2004/11/formula-languages-dirty-secret.html) I discovered that the methods I'm showing here are not only cool, they're the fast way to go.

One more reason to learn about permutated addition (and list management)!

Scott




Enter Comments^


Email addresses provided are not made available on this site.





You can use UUB Code in your posts.

[b]bold[/b]  [i]italic[/i]  [u]underline[/u]  [s]strikethrough[/s]

URL's will be automatically converted to Links


:-) :cry: :-\ :huh: ;-) :cool: :grin: :emb: :laugh: :-p :lips: :-( :rolleyes: :-o :-D :angry: :-x
bold italic underline Strikethrough





Remember me    

Disclaimer & Copyright
Monthly Archive
Contact me...
Racing sponsors and such...

Thank you sponsors!

GABlogLogo.jpg

GOODAero

GOODAero specializes in building aerodynamic products for racing cars. Our first product, the GOODAero Raptor wing is available at a surprisingly reasonable price (under a grand) for a full carbon, full-sized, racing wing. Check it out.


Infinite Fiberworks Co, a great source for high-quality Porsche fiberglass parts

Infinite Fiberworks Co.

If you are looking for fiberglass for Porsches, IFC is the place to go. I have used parts from most of the major suppliers and IFC's are easily the highest quality and the most reasonably-priced. Contact Mike at Infinite Fiberworks for more information.

Located in Racine, OH (so far Southeast they're almost in West Virginia), IFC's goal is to be The Best. Give 'em a try.


Bent or ugly wheels? Call Wheel Medic!

Wheel Medic & The Round House

Whether you need to repair, repaint, refinish or just replace your wheels, the guys at Wheel Medic/Round House can get you back on the road in no time!

Wheel Medic, Inc is a family-owned company which specializes in the repair and restoration of aluminum wheels.

The Round House was founded to service Wheel Medic's clients looking for more than just repair work...from custom wheel colors to high-end wheel applications and body kits, the Round House is there to serve the discriminating automotive enthusiast.


Used Porsche parts, great prices!

A Part Above

Looking for used parts for 944s, 924s, 968s or other late-model water-cooled Porsches? Contact John at A Part Above.

Located in Strongsville, OH (20 miles south of Cleveland) their goal is to provide top quality parts and services. I can tell you, John is great to work with and the prices? Very hard to beat.


SMRT Motorsports wants you!

SMRT (that's short for Skid Mark Racing Team), a very-

loosely organized band of fun-loving friends who enjoy auto racing (heck, cars in general), and the occasional adult beverage, wants you to be a part of our team.

Go here to find cool T-shirts, sweatshirts, caps and mugs with the SMRT team logo.

The BlogRoll
Lotus Domino ND6 RSS News Feed RSS Comments Feed Geo URL RSS Validator Blog Admin Lotus Geek Open Notes Picture Database OpenNTF BlogSphere
Calendar
February 2012
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
By Category
What I do for a living


I am the President of Teamwork Solutions a long-time Lotus, now IBM, Premier Partner.

With offices in Columbus and Cincinnati, Ohio, we specialize in custom application development for IBM Lotus Notes, Domino, and related technologies. Our software product, ProcessIt! (see below), is quite possibly the world's best, most powerful and easiest-to-use workflow tool for Notes and the web.

Our clients are some of the world's largest corporations along with others that aren't so big.

We do excellent work, quickly, and often on a fixed-fee basis. We'd love to talk to you about your next project.




I am a Contributing Author to Lotus Advisor Magazine, with more than 40 articles under my belt.

I've written how-to series (serieses?) on LotusScript, JavaScript, Cascading Style Sheets (CSS), and now, AJAX (Asynchronous JavaScript and XML), as well as a bit on miscellaneous web development topics.


TheView.jpg

I also write for The View as of the July/August issue where I showed how to take an ugly Notes applications and make it beautiful with just a few minutes' (careful) work.



I am the chief architect and one of two primary developers for what many consider the best all-around workflow tool for Notes/Domino, anywhere, regardless of price.

It's called ProcessIt!, and you can read all about it at www.notesworkflow.com but the bottom line is this: ProcessIt! is fast and easy to learn, extremely powerful, and can be used by mortals. Even--dare I say it?--common users.

You can spend a lot more on a workflow tool but you won't be able to do a lot more for all the extra money.

Don't believe me? Download and try it for free for 60 days.



GTSLogoSm.gif
Copyright Porsche and NASA...not me!

I race a Porsche 944 S2 in National Auto Sport Assocation events and am the 2008 National Champion in NASA's GTS2 class.

Blame this event, a few years ago, for starting that particular money drain all over again.

In support of my habit, I am the NASA Great Lakes Region's GTS (German Touring Series) Director.

I'm also a Nationally-Certified Instructor for the Porsche Club of America and am in charge of classroom sessions for the Mid-Ohio region when we are doing high performance driving events.

In a prior racing life, I was the Midwestern Regional Formula Atlantic Champion and, in 1991, the Ohio Vally Region of SCCA's Regional Driver of the Year (but that, alas, went away when my credit cards let go of the rope!).




I'm writing a book...or at least trying to.

It's murder mystery in which, not too surprisingly, the main character runs a small software company and races cars for fun. Oh yeah, and lives near where I do.

Just where do they come up with these crazy ideas?

Facebook