23 September 2012

Project Euler - Problem 28

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:
21 22 23 24 25
20  7  8  9 10
19  6  1  2 11
18  5  4  3 12
17 16 15 14 13

It can be verified that the sum of the numbers on the diagonals is 101.
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?


To solve this problem, I used VB.NET. Here are the design and the code.

Design:












It consists of 1 Textbox, 1 Label, and 1 Button.


Code:

Public Class Form1
    Dim x, y, z, a, b, c As Integer
    Dim num As Double
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        c = 1
        z = 1
        x = TextBox1.Text
        If x > 0 And x Mod 2 = 1 Then
            For a = 1 To x * 2 - 2
                y = 2 * c
                z = z + y
                num = num + z
                b = b + 1
                If b = 4 Then
                    c = c + 1
                    b = 0
                End If
            Next
        Else
            MsgBox("Spiral must be of odd size and has a minimum size of 1.")
            End
        End If
        Label1.Text = num + 1
    End Sub
End Class




Explanation:

The Textbox receives the size of the spiral.
Note that the size must be an odd number starting from the minimum of 1. 
The sum of the numbers on the diagonals will be shown in the Label. 

Answer to PROBLEM 28 of Project Euler :
The sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way is  669171001.



Happy Coding !
Cyber Frost

VB.NET - PROGRAM 1

Name : Text Transport
Difficulty : Very Easy

Today, I will show you how to make a program which transports the text input in the Textbox into a Label.


First of all, create a new Windows Application Project.

An empty form will show.












Now, drag a Textbox, a Label, and a Button from the toolbox on the left. It will look somewhat like this :












Click once on the Form. Change its "Text" Property to : Text Transport
If you do not know already, the properties box is located on the lower right of your VB.NET screen.
  
Click once on the Button and change its "Text" Property to : Transport


Click once on the Label and clear its "Text" Property.

It will now look like this :













Here comes the fun part, coding. 

Simply right click on the form and choose View Code.
 Now, you should be in the code editor.

All you have to do is copy this code and paste it into your code editor:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = TextBox1.Text
    End Sub

End Class


Next, run the program by pressing F5 or clicking the green play button on the top. 
 A window will show, you may type anything into the textbox (for example : ABC) and then clicking on the Transport button. The text on the Textbox (which is ABC) will be copied onto the Label which indicates that you are successful.














Happy Coding !

Cyber Frost

02 June 2012

Apology

I would like to apologize for not writing for a long time.
It was merely because I was bombarded with tasks and exams.
As I have long stopped writing and researching about computing matters, I am still in search of inspiration.
Meanwhile, I would like to share an extremely useful link.

Here it is : http://home.mcafee.com/virusinfo

It is by far the most complete virus database which provides information on the most recent computer viruses, its description, indications of infection, methods of infection, virus characteristics, and even the removal instructions.


Hope it helps 
Cyber Frost

Search