Shortest Formula Challenge #1: Material Gains 13

The challenge this week is as follows: given a random – though legal. according to the laws of the game – position on a standard chessboard, here occupying the range A1:H8, a single formula to give the material evaluation of the position. For example, on the board below:

Pic2

the result of the formula would be -3.

Notes:

Each piece scores the following:

P (Pawn): 1
N (Knight): 3
B (Bishop): 3
R (Rook): 5
Q (Queen): 9

Each side will always have one King each, though other material may vary.

The prefixes “W” and “B” indicate a White piece and a Black piece respectively.

The formula result is the material evaluation from White’s perspective. Hence, if White’s material total is greater than Black’s, this result should be positive; conversely, if White’s material total is less than Black’s, this result should be negative. And if material is equal, the result should be zero.

This week’s challenge is also a shortest formula challenge, which means that readers should attempt to find not only a correct solution to the problem but also one which has the least number of characters as possible.

Formulas must reference the range A1:H8 – no other range references are permitted, including Named Ranges.

Solution next week. Best of luck!

13 comments

  1. Nominally 1, though, as I said, both sides will always have precisely one king each, so this piece cannot ever affect the material balance.

  2. Alright short or not here is my solution:

    =SUM(IFERROR(VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1:H8,"WP",1),"WN",3),"WB",3),"WR",5),"WQ",9)),""))-SUM(IFERROR(VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1:H8,"BP",1),"BN",3),"BB",3),"BR",5),"BQ",9)),""))

    Entered as an array from White’s perspective.

  3. Hi XOR LX

    This will be short…. i suppose ;-)))

    =SUM(COUNTIF($A$1:$H$8,{"B","W"}&{"P";"N";"B";"R";"Q"})*{-1,1}*{1;3;3;5;9})

    Regards.

  4. @GreasySpot

    Good stuff! Works perfectly! Now let’s just see if anyone can come along with a shorter version.

    Thanks a lot for your contribution. Cheers

  5. @Bill Szysz

    Hi Bill. Not sure I understand. How does this formula account for the possible different number of pieces that Black and White have?

    Regards

  6. I feel a bit of a cheapskate offering this as the donkeywork has already been done by Bill. However given the prize money that’s at stake, it has to be done…….

    =SUM(COUNTIF(A1:H8,{"B","W"}&{"P";"N";"B";"R";"Q"})*{-1,1}*{1;3;3;5;9})

    Would I be pushing my luck to suggest using lowercase letters and transposing the arrays so that commas outnumber the semicolons?

    =SUM(COUNTIF(A1:H8,{"b";"w"}&{"p","n","b","r","q"})*{-1;1}*{1,3,3,5,9})

    Although it contains the same number of characters it is actually ‘shorter ‘, left to right and will use up less ink!!!

  7. Looks like my (Bill’s if we’re being honest. What’s a couple of $’s between friends?) formulas have fallen foul of your editor?

    *First visit to site. Looks interesting, I will be back!!!

  8. @Snakehips

    Welcome! Good to see someone of such standing in the Excel world here! (No offence, everyone else 🙂 )

    “Harsh” is the word that springs to mind! But then, Bill did kind of leave that door wide open, so who can blame you for walking through it?

    As for the lower-case stuff, you should know me better than that! So that one’s not getting you any extra points, I’m afraid. And prize money?? You and everyone else wish! 🙂

    Cheers and hope to see you around here again!

    P.S. Sorry about the editor here. Not nearly on the same level of technical expertise as at Mr. Excel. Have amended your formula, hopefully to what you intended.

  9. Pingback: Shortest Formula Challenge #1: Results and Discussion | EXCELXOR

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s