# Code Golf 1: Code Love

Page 1 of 1

## 12 Replies - 16239 Views - Last Post: 05 February 2011 - 09:30 PM

• MrCupOfT

Reputation: 2294
• Posts: 9,531
• Joined: 29-May 08

# Code Golf 1: Code Love

Posted 03 February 2011 - 04:06 PM

Code Golf (Hole 1, Code Love)

It February, the month of Love.
For those with partners, remember it Valentines Day on the 14th
(WTF, A coder with a partner?)

Challenge
Fill in the code to calculate what percentage one member loves another.

Example
Locke loves supersloth how much?

```LOVES
22022 <-- Count of each letter.
4224 <-- (2+2), (2+0), (0+2), (2+2)
646 <-- (4+2), (2+2), (2+4)
00 <-- (5+4), (4+6)          ' Last one

```

Note how the 4+6 is 0 and not 10, this so the calculation converges.
Extra Clarification The values in each must be 0<= x < 10 at all stages, this includes the count of each letter.
So Locke loves supersloth 00% of the time.

Letter casing is iqnored so Aa are the same.

```Function Loves(ByVal PersonA As String, ByVal PersonB As String) As Integer)
' Your code goes here '
End Function

```

Scoring Rules
You can assume the inputs will be non null or nothing.
Must compile with
```Option Strict On
Option Infer On

```

Is the same code golf standard, the count of non-whitespace character inside the function method.
For this hole an allowance of -6 (to account for the required keyword Return.

Edit: Update and corrected calculation

Example Submission

Spoiler

This post has been edited by AdamSpeight2008: 03 February 2011 - 07:02 PM

Is This A Good Question/Topic? 1

## Replies To: Code Golf 1: Code Love

### #2 TMKCodes

• D.I.C Regular

Reputation: 48
• Posts: 440
• Joined: 21-March 09

## Re: Code Golf 1: Code Love

Posted 03 February 2011 - 05:08 PM

I'm sorry this is not VB.NET, but I noticed it after I had written this in C++.
Spoiler

This post has been edited by TMKCodes: 03 February 2011 - 05:38 PM

• MrCupOfT

Reputation: 2294
• Posts: 9,531
• Joined: 29-May 08

## Re: Code Golf 1: Code Love

Posted 03 February 2011 - 06:58 PM

TMKCodes: That's Ok but only VB.net ones will officially be scored.

This post has been edited by AdamSpeight2008: 03 February 2011 - 07:32 PM
Reason for edit:: Updating Score

### #4 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5000
• Posts: 9,054
• Joined: 08-June 10

## Re: Code Golf 1: Code Love

Posted 04 February 2011 - 09:58 AM

Here's my go. It's certainly no 148, but I think it's pretty good for a non-regular VB.NET programmer.

Spoiler

Edit: Ignore the last one. Here's a slightly smaller version:
Spoiler

Edit 2: Saved myself 90 characters doing this:
Spoiler

Edit 3: And I just saved 27 more characters over the last one. This is an iterative process

Spoiler

This post has been edited by insertAlias: 04 February 2011 - 11:02 AM

### #5 modi123_1

• Suitor #2

Reputation: 11614
• Posts: 45,779
• Joined: 12-June 08

## Re: Code Golf 1: Code Love

Posted 04 February 2011 - 10:53 AM

452-6 = 446 using some pretty ugly looking coding practices..
460-6 = 454
Spoiler

This post has been edited by modi123_1: 04 February 2011 - 11:34 AM

### #6 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5000
• Posts: 9,054
• Joined: 08-June 10

## Re: Code Golf 1: Code Love

Posted 04 February 2011 - 11:07 AM

@modi, when I ran yours it just infinitely looped.

### #7 modi123_1

• Suitor #2

Reputation: 11614
• Posts: 45,779
• Joined: 12-June 08

## Re: Code Golf 1: Code Love

Posted 04 February 2011 - 11:18 AM

Nevermind.. I fixed it... stupid paint fumes in the office today.

This post has been edited by modi123_1: 04 February 2011 - 11:34 AM

• MrCupOfT

Reputation: 2294
• Posts: 9,531
• Joined: 29-May 08

## Re: Code Golf 1: Code Love

Posted 04 February 2011 - 11:37 AM

Remember you need to do a mod 10 on initial count the count of the letters.
So
``` L O V E S
13 1 0 4 4 becomes 3 1 0 4 4
```

I think it a good challenge.
As you consider the char cost of using Function() and Sub() when you use lambda functions.

This post has been edited by AdamSpeight2008: 04 February 2011 - 11:57 AM

### #9 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5000
• Posts: 9,054
• Joined: 08-June 10

## Re: Code Golf 1: Code Love

Posted 04 February 2011 - 11:54 AM

Updated to fix that issue:

Spoiler

261 - 6 = 255

I have considered the character cost, but I'm not sure of a way that would be shorter. I wish I could use some of my extension methods. But to be fair, the code in those would have to be counted too.

This post has been edited by insertAlias: 04 February 2011 - 11:59 AM

• MrCupOfT

Reputation: 2294
• Posts: 9,531
• Joined: 29-May 08

## Re: Code Golf 1: Code Love

Posted 04 February 2011 - 03:59 PM

Another validation check for you

Gorian LOVES BenignDesign = 58%

Score: 145c
Spoiler

This post has been edited by AdamSpeight2008: 04 February 2011 - 04:10 PM

### #11 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5000
• Posts: 9,054
• Joined: 08-June 10

## Re: Code Golf 1: Code Love

Posted 04 February 2011 - 04:28 PM

Reputation:

## Re: Code Golf 1: Code Love

Posted 05 February 2011 - 08:38 PM

I understand Java is not applicable for "official counting"... So, here is my first try for posterity:

```int Loves(String A, String B)/> {
int[] X = new int[256];
for (int a : (A+B)/>.toUpperCase().getBytes()) ++X[a];
int L=X[76],O=X[79],V=X[86],E=X[69],S=X[83];
return (L+3*O+3*V+E)%10*10+(O+3*V+3*E+S)%10;
}

```

Just shy of the current best at 146c.

- Joel.

### #13 leoJava

Reputation: 0
• Posts: 1
• Joined: 22-January 11

## Re: Code Golf 1: Code Love

Posted 05 February 2011 - 09:30 PM

OK, next try (while logged in...) 138c.

Spoiler

This post has been edited by leoJava: 05 February 2011 - 09:33 PM