Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 01-20-06   #1 (permalink)
Bifford
 
BFRD's Avatar
 
intel nvidia

Join Date: Dec 2004
Location: Carrollton, TX
Posts: 4,275

FAQs Submitted: 8
Folding Team Rank: 23
Hardware Reviews: 2
Trader Rating: 11
Default

OK,

Since we have a few programmers here I thought I would issue a programming challenge. It really isn't that difficult, but I would like you to focus on elegance and effciency. There really aren't any rules just submit your code as a text file and compilied (if required). Depending on the turnout I may try to do this on a weekly basis. There aren't any prizes this is just for fun.

Challenge #1:

Given a comma seperated list of numbers:
1,2,3,5,10,11,12,13,25

Convert to
1-3,5,10-13,25

So that sequential numbers are listed as start-end and all others are simply comma seperated. Please assume that the initial list is in order, but of any length. I recently had to do this for a client and thought it was something that might work as a simple challenge.

Please respond to this thread if you are interested in playing. The deadline for entries is 1/25/06 11:59 PM GMT-6. Try to stick to one of the top 20 languages on this list.


Current challenge at post #10
__________________
Helpful Posts (Hopefully )
Overclocker's Calculator
Photo Editing - B&W w/Color Accents

System: Main Rig
CPU
E6700 Conroe
Motherboard
Abit QuadGT
Memory
2GB G.Skill PC2 8000 (HZ)
Graphics Card
EVGA 8800GTX
Hard Drive
150 GB Raptor X / 300GB Storage
Sound Card
Audigy 2 ZS
Power Supply
PCP&C Silencer 750
Case
Sigma Shark
CPU cooling
Stock (for now)
GPU cooling
Stock
OS
Vista Ultimate
Monitor
Dual Samsung 204b

Last edited by BFRD : 05-03-07 at 04:05 PM.
BFRD is offline I fold for Overclock.net Overclocked Account BFRD's Gallery   Reply With Quote
Old 01-26-06   #2 (permalink)
Bifford
 
BFRD's Avatar
 
intel nvidia

Join Date: Dec 2004
Location: Carrollton, TX
Posts: 4,275

FAQs Submitted: 8
Folding Team Rank: 23
Hardware Reviews: 2
Trader Rating: 11
Default

Times up, Xaimus is the only one that got an entry in.

Code:
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

string intToStr(int);
bool isNumber(char);
bool isNegate(char);

int main(int argv, char** argc) {
    if (argv < 2) {
        cout << "usage: \n"
             << argc[0] << " list,of,integers\n";
        return 1;
    }

    string list = argc[1], output;
    bool start = true, chain = false, negate = false;
    int current = 0, next = 0, i = 0;
    
    while (isNumber(list[i]) || isNegate(list[i])) {
        if (isNumber(list[i])) {
            current = (current * 10) + (list[i] - '0');
        } else {
            negate = !negate;
        }
        i++;
    }
    if (negate) {
        current *= -1;
    }
    
    while (i < list.length()) {
        negate = false;
        next = 0;
        
        if (isNumber(list[i]) || isNegate(list[i])) {
            while(isNumber(list[i]) || isNegate(list[i])) {
                if (isNumber(list[i])) {
                    next = (next * 10) + (list[i] - '0');
                } else {
                    negate = !negate;
                }
                i++;
            }
            if (negate) {
                next *= -1;
            }
            
            if (next - 1 == current) {
                if (!chain) {
                    if (start) {
                        start = false;
                    } else {
                        output += ',';
                    }
                    output += intToStr(current) + '-';
                    chain = true;
                }
            } else {
                if (chain) {
                    output += intToStr(current);
                    chain = false;
                } else {
                    if (start) {
                        start = false;
                    } else {
                        output += ',';
                    }
                    output += intToStr(current);
                }
            }
            current = next;
        } else {
            i++;
        }
    }
    
    if (chain || start) {
        output += intToStr(next);
    } else {
        output += ',' + intToStr(next);
    }
    cout << output << endl;
    return 0;
}

string intToStr(int x) {
    ostringstream o;
    o << x;
    return o.str();
}

bool isNumber(char x) {
    return x <= '9' && x >= '0';
}

bool isNegate(char x) {
    return x == '-';
}
__________________
Helpful Posts (Hopefully )
Overclocker's Calculator
Photo Editing - B&W w/Color Accents

System: Main Rig
CPU
E6700 Conroe
Motherboard
Abit QuadGT
Memory
2GB G.Skill PC2 8000 (HZ)
Graphics Card
EVGA 8800GTX
Hard Drive
150 GB Raptor X / 300GB Storage
Sound Card
Audigy 2 ZS
Power Supply
PCP&C Silencer 750
Case
Sigma Shark
CPU cooling
Stock (for now)
GPU cooling
Stock
OS
Vista Ultimate
Monitor
Dual Samsung 204b

Last edited by BFRD : 01-26-06 at 01:09 PM.
BFRD is offline I fold for Overclock.net Overclocked Account BFRD's Gallery   Reply With Quote
Old 01-27-06   #3 (permalink)
Bifford
 
BFRD's Avatar
 
intel nvidia

Join Date: Dec 2004
Location: Carrollton, TX
Posts: 4,275

FAQs Submitted: 8
Folding Team Rank: 23
Hardware Reviews: 2
Trader Rating: 11
Default Programming Challenge - #2

OK, Here is the next challenge.

Create a web-based application to display Pascals Triangle. Please allow your code to create any number of levels based on user input. Also include processing time.

Ex. (excuse spacing)

1
11
121
1331

Excuted to 4 levels.

Deadline for entries is Feb. 10th 11:59 PM GMT-6.
__________________
Helpful Posts (Hopefully )
Overclocker's Calculator
Photo Editing - B&W w/Color Accents

System: Main Rig
CPU
E6700 Conroe
Motherboard
Abit QuadGT
Memory
2GB G.Skill PC2 8000 (HZ)
Graphics Card
EVGA 8800GTX
Hard Drive
150 GB Raptor X / 300GB Storage
Sound Card
Audigy 2 ZS
Power Supply
PCP&C Silencer 750
Case
Sigma Shark
CPU cooling
Stock (for now)
GPU cooling
Stock
OS
Vista Ultimate
Monitor
Dual Samsung 204b

Last edited by BFRD : 02-02-06 at 05:06 PM.
BFRD is offline I fold for Overclock.net Overclocked Account BFRD's Gallery   Reply With Quote
Old 02-14-06   #4 (permalink)
WaterCooler
 
amd nvidia

Join Date: Feb 2006
Location: Woodland Hills, CA
Posts: 18

Rep: 3 FaKk2 Unknown
Unique Rep: 3
Trader Rating: 0
Default

10 minutes of coding
5 minutes of refreshing PHP knowledge
5 minutes for debugging and formatting

Code:
<?
/* Challenge #2
Pascal Triangle
$_GET['level'] represents the triangle's level.
*/

$level = $_GET['level'];
$triangle = array();

$triangle[0][0] = 1;
for ($i = 1; $i < $level; $i++)
{
    $triangle[$i][0] = 1;
    $triangle[$i][count($triangle[$i-1])] = 1;
    for ($j = 1; $j < count($triangle[$i-1]); $j++)
    {
        $triangle[$i][$j] = $triangle[$i-1][$j-1] + $triangle[$i-1][$j];
    }
}

echo "<table>";
for ($i = 0; $i < $level; $i++)
{
    echo "<tr>";
    for ($j = 0; $j < count($triangle[$i]); $j++)
        echo "<td>".$triangle[$i][$j]."</td>";
    echo "</tr>";
}
echo "</table>";
?>
Could be improved of course. For example get rid of the multidimensional array and render directly.
__________________
System: My System
CPU
Barton 3000+ Socket A
Motherboard
EPoX 8RDA6+ Pro
Power Supply
Ultra 500 Watt
Case
Antec Lanboy
OS
Win XP Pro SP2
Monitor
2x LCD
FaKk2 is offline   Reply With Quote
Old 02-15-06   #5 (permalink)
Bifford
 
BFRD's Avatar
 
intel nvidia

Join Date: Dec 2004
Location: Carrollton, TX
Posts: 4,275

FAQs Submitted: 8
Folding Team Rank: 23
Hardware Reviews: 2
Trader Rating: 11
Default

Quote:
Originally Posted by FaKk2
10 minutes of coding
5 minutes of refreshing PHP knowledge
5 minutes for debugging and formatting

Code:
<?
/* Challenge #2
Pascal Triangle
$_GET['level'] represents the triangle's level.
*/
 
$level = $_GET['level'];
$triangle = array();
 
$triangle[0][0] = 1;
for ($i = 1; $i < $level; $i++)
{
    $triangle[$i][0] = 1;
    $triangle[$i][count($triangle[$i-1])] = 1;
    for ($j = 1; $j < count($triangle[$i-1]); $j++)
    {
        $triangle[$i][$j] = $triangle[$i-1][$j-1] + $triangle[$i-1][$j];
    }
}
 
echo "<table>";
for ($i = 0; $i < $level; $i++)
{
    echo "<tr>";
    for ($j = 0; $j < count($triangle[$i]); $j++)
        echo "<td>".$triangle[$i][$j]."</td>";
    echo "</tr>";
}
echo "</table>";
?>
Could be improved of course. For example get rid of the multidimensional array and render directly.
Very nice. I didn't think of doing that way, I used a mathmatical formula to produce the results. Nice job of thinking simple. It is often times the simplest solution that is the best.
__________________
Helpful Posts (Hopefully )
Overclocker's Calculator
Photo Editing - B&W w/Color Accents

System: Main Rig
CPU
E6700 Conroe
Motherboard
Abit QuadGT
Memory
2GB G.Skill PC2 8000 (HZ)
Graphics Card
EVGA 8800GTX
Hard Drive
150 GB Raptor X / 300GB Storage
Sound Card
Audigy 2 ZS
Power Supply
PCP&C Silencer 750
Case
Sigma Shark
CPU cooling
Stock (for now)
GPU cooling
Stock
OS
Vista Ultimate
Monitor
Dual Samsung 204b
BFRD is offline I fold for Overclock.net Overclocked Account BFRD's Gallery   Reply With Quote
Old 09-26-06   #6 (permalink)
Bifford
 
BFRD's Avatar
 
intel nvidia

Join Date: Dec 2004
Location: Carrollton, TX
Posts: 4,275

FAQs Submitted: 8
Folding Team Rank: 23
Hardware Reviews: 2
Trader Rating: 11
Default Programming Challenge - #3

OK, I borrowed this one from another site.

Find the largest number less than 100 quintillion* which is a palindrome and is also divisible by all primes between 10 and 30.

* American quintillion

EDIT: All entries must also include a manner of documenting how long it takes to find the answer.

PM me your answer and it if is correct I will then post your code after the deadline. Until then I will just post who completed here. The deadline for entries is Oct 14th. As stated before this is from a know challenge site, so don't just google the answer. This is about programming not the use of google.

===========================================
Results
===========================================

rabidgnome229: Solution in Progress
Burn: Solution in Progress
FrankenPC: Completed Challenge (~15 seconds)
someone153: Solution in Progress
sniperscope: Completed Challenge (~5 seconds)
__________________
Helpful Posts (Hopefully )
Overclocker's Calculator
Photo Editing - B&W w/Color Accents

System: Main Rig
CPU
E6700 Conroe
Motherboard
Abit QuadGT
Memory
2GB G.Skill PC2 8000 (HZ)
Graphics Card
EVGA 8800GTX
Hard Drive
150 GB Raptor X / 300GB Storage
Sound Card
Audigy 2 ZS
Power Supply
PCP&C Silencer 750
Case
Sigma Shark
CPU cooling
Stock (for now)
GPU cooling
Stock
OS
Vista Ultimate
Monitor
Dual Samsung 204b

Last edited by BFRD : 10-13-06 at 03:45 PM.
BFRD is offline I fold for Overclock.net Overclocked Account BFRD's Gallery   Reply With Quote
Old 10-15-06   #7 (permalink)
Bifford
 
BFRD's Avatar
 
intel nvidia

Join Date: Dec 2004
Location: Carrollton, TX
Posts: 4,275

FAQs Submitted: 8
Folding Team Rank: 23
Hardware Reviews: 2
Trader Rating: 11
Default

Ok times up.

sniperscope and FrankenPC completed the challenge.

Kudos go to both members as they were able to use some lateral thinking and come up with a solution without using the obvious route. In this particular case the obvious route would have been to start with the largest possible number "99999999999999999999" and work your way down until a match was found. As some of you found out that this takes a very very long time. What I found most interesting about this excersize is that the two solutions are completely different. I will post my code and a brief explanation of what I did. I will let the other two guys do the same.

My Way (which as it turns out isn't the fastest):
Code:
 class Program
{
static void Main(string[] args)
{
//Initialize Timer
DateTime startTime = DateTime.Now;
 
//Set Roof
decimal iRoof = 9999999999M;
//Go
for (decimal i = iRoof; i > 0; i--)
{
bool bResult = CheckNumber(i);
if (bResult)
{
Console.WriteLine(AssembleNumber(i).ToString());
break;
}
}
//Stop Timer
DateTime stopTime = DateTime.Now;
//Calculate Time and Display
TimeSpan duration = stopTime - startTime;
Console.WriteLine("Execution Time: " + duration);
//Keep the Window Open
Console.WriteLine("\r\nq <enter> to quit.");
while (Console.Read() != 'q') ;
}
static bool PrimeCheck(decimal iNumber)
{
//11 13 17 19 23 29 
if (iNumber % 29 != 0)
return false;
if (iNumber % 23 != 0)
return false;
if (iNumber % 19 != 0)
return false;
if (iNumber % 17 != 0)
return false;
if (iNumber % 13 != 0)
return false;
if (iNumber % 11 != 0)
return false;
return true;
}
static bool CheckNumber(decimal dblNumber)
{ 
//Assemble Number
decimal dblPalindrome = AssembleNumber(dblNumber);
//Check Prime
if (PrimeCheck(dblPalindrome))
{
return true;
}
else
{
return false;
}
}
static decimal AssembleNumber(decimal dblNumber)
{
string tFirst = dblNumber.ToString();
char[] arLast = dblNumber.ToString().ToCharArray();
Array.Reverse(arLast);
string tLast = new string(arLast); 
 
return Convert.ToDecimal(tFirst + tLast);
}
}
Since I knew we were dealing with palindromes I decided to assemble palindromes rather than look for them. I knew my largest possilbe palindrome was "99999999999999999999" so I split that number in half making 9999999999. Using that as a base to start from I decreased the base number by one, and then assembled a 20 digit palindrome using a custom function. To assemble the palindrom I converted my number to a string, and then converted the string to character array. Once I had the array, I reversed the array and then conatenated the original string with the new reversed string. So for my first loop (actually second) my base number was 9999999998 and the assembled palindrome being 99999999988999999999. From then I just checked each number for being divisible by the set of prime numbers. I used the modal method to determine if the number was evenly divisible and broke out of the function as soon as my test palindrome failed one of the divisible tests. So there isn't much to it, just took a little time out of the box to make it effcient.

EDIT: I will enclose my compiled program here. I promise it is trojan/virus free. Your results may vary. I get just a little under 7.5 seconds on my home rig. (but please lets not turn this into a benchmark thread ).
Attached Files
File Type: zip ocnQuintillion.zip (2.3 KB, 22 views)
__________________
Helpful Posts (Hopefully )
Overclocker's Calculator
Photo Editing - B&W w/Color Accents

System: Main Rig
CPU
E6700 Conroe
Motherboard
Abit QuadGT
Memory
2GB G.Skill PC2 8000 (HZ)
Graphics Card
EVGA 8800GTX
Hard Drive
150 GB Raptor X / 300GB Storage
Sound Card
Audigy 2 ZS
Power Supply
PCP&C Silencer 750
Case
Sigma Shark
CPU cooling
Stock (for now)
GPU cooling
Stock
OS
Vista Ultimate
Monitor
Dual Samsung 204b

Last edited by BFRD : 10-15-06 at 10:42 AM.
BFRD is offline I fold for Overclock.net Overclocked Account BFRD's Gallery   Reply With Quote
Old 10-15-06   #8 (permalink)
Programmer
 
sniperscope's Avatar
 
amd nvidia

Join Date: Apr 2006
Location: Kent (England)
Posts: 1,237

Rep: 89 sniperscope is acknowledged by some
Unique Rep: 77
FAQs Submitted: 3
Trader Rating: 0
Default

My entry:

Code:
Public Class Form1

    Public a As Decimal = 99999999999999999999D

    Public Sub go()
        Me.Text = "Running..."
        Dim time1 As Decimal = Now.Ticks
        For h As Integer = 0 To 9
            For g As Integer = 0 To 9
                For f As Integer = 0 To 9
                    For e As Integer = 0 To 9
                        For d As Integer = 0 To 9
                            For c As Integer = 0 To 9
                                For b As Integer = 0 To 9
                                    If frac(a / 30808063) = 0 Then GoTo 1
                                    a -= 11000000000D
                                Next
                                a += 9900000000D
                            Next
                            a += 990000000D
                        Next
                        a += 99000000D
                    Next
                    a += 9900000D
                Next
                a += 990000D
            Next
            a += 99000D
        Next
        MessageBox.Show(a & Environment.NewLine & "Multiple not Found...")
        GoTo 2
1:      Dim time2 As Decimal = Now.Ticks
        Me.Text = "Complete"
        Dim processtime As Decimal = ((time2 - time1) / 10000000)
        MessageBox.Show(a & Environment.NewLine & "Processing Time: " & processtime, "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information)
        TextBox1.Text = a
2:
    End Sub

    Public Function frac(ByVal num As Decimal)
        Return Math.Floor(num) - num
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = 99999999999999999999D
        go()
    End Sub
End Class
Answer:

99976239844893267999

Divisible by primes:

99976239844893267999 / 11 = 9088749076808478909
99976239844893267999 / 13 = 7690479988068712923
99976239844893267999 / 17 = 5880955284993721647
99976239844893267999 / 19 = 5261907360257540421
99976239844893267999 / 23 = 4346793036734489913
99976239844893267999 / 29 = 3447456546375629931

Solved in 5.421875 seconds on 2.6Ghz Oc'd Athlon 64 3800+ proccy.

System: Bob
CPU
AMD Athlon 64 3800+
Motherboard
ASUS A8N- SLI Premium
Memory
2GB (2X1GB) Corsair XMS Pro LED TwinX DDR400
Graphics Card
XFX GeForce 7800GT Extreme Edition
Hard Drive
2x200GB Barracuda SATA RAID0 + 250Gb ATA
Sound Card
AC'97
Power Supply
Antec TruePower 550W
Case
Thermaltake Armour
CPU cooling
Stock
GPU cooling
Stock
OS
Windows Vista Home Premium x64
Monitor
Hanns G 19" widescreen HW191D
sniperscope is offline sniperscope's Gallery   Reply With Quote
Old 10-16-06   #9 (permalink)
<= Humanaut
 
FrankenPC's Avatar
 
intel nvidia

Join Date: Jun 2006
Location: Bay Area
Posts: 5,548

Rep: 372 FrankenPC is a proven memberFrankenPC is a proven memberFrankenPC is a proven memberFrankenPC is a proven member
Unique Rep: 243
FAQs Submitted: 1
Trader Rating: 4
Default

This is how I dit it. Same concept as BFRD, slightly different code (VB.NET 2.0). NOTE: Only because the answer is so close to the starting position is the viable.

Dim I As Decimal

Dim Stringpart As String
Dim Reverse As String
Dim NewString As String
Dim NewNumber As Decimal

Dim Counter As Int32 = 0
Dim TotalCount As Int32 = 0

Dim Quint As Decimal = 9999999999

For I = Quint To 1 Step -1

Stringpart = I.ToString

'Need to adjust behavior due to even/odd Palindromes
If I Mod 2 = 0 Then
Reverse = StrReverse(Stringpart)
Else
Reverse = StrReverse(Microsoft.VisualBasic.Left(Stringpart, Len(Stringpart) - 1))
End If

NewString = Stringpart & Reverse
Decimal.TryParse(NewString, NewNumber)

If NewNumber Mod 11 = 0 Then
If NewNumber Mod 13 = 0 Then
If NewNumber Mod 17 = 0 Then
If NewNumber Mod 19 = 0 Then
If NewNumber Mod 23 = 0 Then
If NewNumber Mod 29 = 0 Then
msgbox (NewString) 'palindrome found
End If
End If
End If
End If
End If
End If

Next
__________________
Previous Member of Team Owners - 1st to hit 200k and 250K

Previous member of Rough Riders - 1st to hit 300k!!!

Adios everyone! I've been proud to be a member of Owners and Riders.

System: TITAN-2
CPU
Q6600 G0 @ 3.4GHZ
Motherboard
ASUS P5K-E
Memory
4GB GSkill DDR2-1000 CAS5
Graphics Card
BFG 8800GT OC
Hard Drive
340GB Raptor SATA II
Sound Card
SB X-FI
Power Supply
SilverStone 750W 4-rail
Case
Lian Li Mid-tower
CPU cooling
OCZ Vindicator
GPU cooling
Stock
OS
Vista Home Premium 32bit
Monitor
Sceptre 24" LCD
FrankenPC is offline Overclocked Account   Reply With Quote
Old 05-03-07   #10 (permalink)
Bifford
 
BFRD's Avatar
 
intel nvidia

Join Date: Dec 2004
Location: Carrollton, TX
Posts: 4,275

FAQs Submitted: 8
Folding Team Rank: 23
Hardware Reviews: 2
Trader Rating: 11
Default New Challenge

Here is a challenge from one of our members, ravicus. Lets make an old-school style encoder/decoder. Some of you may remember the decoder rings that used to come in cereal boxes. Where you could twist one set of the alphabet around to line up with the inner set. I will do my best to demonstrate with numbers only:


1234567890
8901234567

So 8004 = 1337.


I want you to create a system to encode and decode messages using a simple shift substitution as outlined above. You should allow for letters and numbers (case is up to you). Leave spaces and punctuation alone. You also need to figure out a way to set the shift. So if you send a message to your buddy, he knows what shift to use to decode your message. Understandably the shift method is much easier to break than a random substitution, but much easier when it comes to setting a key.


As always any common programming language is fine. Just make sure any exes you submit are clean. If you use a web based approach- No Ads!


Happy Programming, and lets give a round of thanks to ravicus for the idea. Let's set the deadline for submissions at May 18th 9:00 PM CST.
__________________
Helpful Posts (Hopefully )
Overclocker's Calculator
Photo Editing - B&W w/Color Accents

System: Main Rig
CPU
E6700 Conroe
Motherboard
Abit QuadGT
Memory
2GB G.Skill PC2 8000 (HZ)
Graphics Card
EVGA 8800GTX
Hard Drive
150 GB Raptor X / 300GB Storage
Sound Card
Audigy 2 ZS
Power Supply
PCP&C Silencer 750
Case
Sigma Shark
CPU cooling
Stock (for now)
GPU cooling
Stock
OS
Vista Ultimate
Monitor
Dual Samsung 204b
BFRD is offline I fold for Overclock.net Overclocked Account BFRD's Gallery   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 02:15 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.72840 seconds with 10 queries