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

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • Joined: 29-May 08

Code Golf 1: Code Love

Post icon  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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • 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.

As as target the best I can do so a far is 171c 148c.

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

Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4453
  • View blog
  • Posts: 7,754
  • 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

Was This Post Helpful? 1
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9055
  • View blog
  • Posts: 33,990
  • 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

Was This Post Helpful? 1
  • +
  • -

#6 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4453
  • View blog
  • Posts: 7,754
  • 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.
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9055
  • View blog
  • Posts: 33,990
  • Joined: 12-June 08

Re: Code Golf 1: Code Love

Posted 04 February 2011 - 11:18 AM

What was your input?
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

Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • 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

Was This Post Helpful? 0
  • +
  • -

#9 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4453
  • View blog
  • Posts: 7,754
  • 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

Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • 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

Was This Post Helpful? 0
  • +
  • -

#11 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4453
  • View blog
  • Posts: 7,754
  • Joined: 08-June 10

Re: Code Golf 1: Code Love

Posted 04 February 2011 - 04:28 PM

Pretty damn slick, Adam.
Was This Post Helpful? 0
  • +
  • -

#12 Guest_leojava*


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.
Was This Post Helpful? 0

#13 leoJava  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1