11 Replies - 14929 Views - Last Post: 05 May 2011 - 10:58 AM

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Code Golf 2: Pyramid

Post icon  Posted 11 February 2011 - 03:43 AM

Code Golf 2: Pyramid

Challenge: Write Function that take in an integer R ( greater than 0), and returns a string containing numerical pyramid of R rows.
Function Pyramid(ByVal R as Integer) As String
' Your Code goes here '
End Function


Example outputs
Pyramid of 2
3 1
  2


Pyramid of 3
6 3 1
  5 2
    4


Pyramid of 5
15 10  6  3  1
   14  9  5  2
      13  8  4
         12  7
            11



It is also required that all the number in the rows be right aligned in the columns.
So that means the follow output is wrong.
15 10 6 3 1
   14 9 5 2
      13 8 4
         12 7
            11



Restrictions
The code must be compiled with the following options turned on.
Option Strict On
Option Infer On


When submitting the .net framework version it target should also included.

Scoring
Is the number of count of non white space characters minus the 6 for implicit return statement.

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


Is This A Good Question/Topic? 2
  • +

Replies To: Code Golf 2: Pyramid

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Code Golf 2: Pyramid

Posted 13 February 2011 - 02:39 PM

This hole has seemed to scared away a lot of golfers, so I guess its a Par 6 hole.

So here's my opening attempt.
Score: 282
Spoiler

Was This Post Helpful? 0
  • +
  • -

#3 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Code Golf 2: Pyramid

Posted 15 February 2011 - 10:19 AM

I had to fall back on some old methods from the VisualBasic namespace to bum the count down.

Score: 196

Spoiler

This post has been edited by T3hC13h: 15 February 2011 - 02:14 PM

Was This Post Helpful? 1
  • +
  • -

#4 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,639
  • Joined: 24-September 10

Re: Code Golf 2: Pyramid

Posted 12 April 2011 - 09:06 AM

180

Spoiler

Was This Post Helpful? 1
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Code Golf 2: Pyramid

Posted 12 April 2011 - 02:24 PM

lordofduct Sweet code.
Was This Post Helpful? 0
  • +
  • -

#6 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,639
  • Joined: 24-September 10

Re: Code Golf 2: Pyramid

Posted 12 April 2011 - 02:38 PM

Thanks

I was a little late to the game, but I only saw the post today. I like these a lot, I hope you and Curtis (over in C#) do more of them.


I do also do the ones over at Euler Project, tons of fun.



Oh and 171, forgot about the 'Int' method, that's shorter than Math.Ceiling and Math.Floor (to bad the CInt cast rounds instead of floors)

Spoiler

This post has been edited by lordofduct: 12 April 2011 - 02:50 PM

Was This Post Helpful? 1
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Code Golf 2: Pyramid

Posted 12 April 2011 - 03:14 PM

lordofduct a few tweaks of yours and it now 159
Spoiler


151
Spoiler

This post has been edited by AdamSpeight2008: 12 April 2011 - 03:16 PM

Was This Post Helpful? 0
  • +
  • -

#8 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,639
  • Joined: 24-September 10

Re: Code Golf 2: Pyramid

Posted 13 April 2011 - 06:28 AM

CInt(...) rounds though, and the Log10 needs to be floored.
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Code Golf 2: Pyramid

Posted 13 April 2011 - 07:07 AM

What size of pyramid would the effect of rounded vs floored be evident?
Was This Post Helpful? 0
  • +
  • -

#10 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,639
  • Joined: 24-September 10

Re: Code Golf 2: Pyramid

Posted 13 April 2011 - 08:18 AM

3 will get a 3 space padding when it should get 2 [ log(6) + 2 -> 3 ]

8 through 13 will get a 4 space padding when it should only get 3.

The next won't be until 25 with 5 spaces when there should be 4 and will last until 44 [when: 10^2.5 < (R^2 + R)/2 < 10^3]

It will always occur when Log10(R^2 + R) % 1 > 0.5



we still get 150 with:

Spoiler


(your 151 score before should have been 145, you said -6 for the implicit Return... that or this one is 156)

This post has been edited by lordofduct: 13 April 2011 - 08:26 AM

Was This Post Helpful? 2
  • +
  • -

#11 Curtis Rutland  Icon User is online

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


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: Code Golf 2: Pyramid

Posted 29 April 2011 - 12:14 PM

I can't believe I missed this one. Too bad. Here's one in C#. Not great, think it's 242 if you're not counting any whitespace:

Spoiler


I did this without looking at other solutions. I'm not great at math, so I brute-forced it somewhat.
Was This Post Helpful? 0
  • +
  • -

#12 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Code Golf 2: Pyramid

Posted 05 May 2011 - 10:58 AM

A slight improvement on the last few works of lordofduct and AdamSpeight2008

Count: 126

Spoiler

This post has been edited by T3hC13h: 05 May 2011 - 11:02 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1