Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › The Programming Challenge Master Thread
New Posts  All Forums:Forum Nav:

The Programming Challenge Master Thread - Page 10

post #91 of 263
any chance of a new thread of each challenge as keeping them they way they are is just messy and hard to follow (in my opinion at least)
post #92 of 263
Felt I should ruin this little party here with a haskell one-liner tongue.gif
Code:
gchi> let table = [[1,2,3],[5..7],[]]
gchi> [sum x | x <- table]
[6,12,0]
15s
(13 items)
 
  
CPUMotherboardGraphicsRAM
Athlon II x4 640 Gigabyte 880GM-D2H AMD HD4250 4 GB 
Hard DriveOSMonitorPower
640GB Arch GNU/Linux i686 Fujitsu Siemens 4612 FA 350 W 
Mouse
Logitech G9x 
  hide details  
Reply
15s
(13 items)
 
  
CPUMotherboardGraphicsRAM
Athlon II x4 640 Gigabyte 880GM-D2H AMD HD4250 4 GB 
Hard DriveOSMonitorPower
640GB Arch GNU/Linux i686 Fujitsu Siemens 4612 FA 350 W 
Mouse
Logitech G9x 
  hide details  
Reply
post #93 of 263
Quote:
Originally Posted by MadCatMk2 View Post

Felt I should ruin this little party here with a haskell one-liner tongue.gif
Code:
gchi> let table = [[1,2,3],[5..7],[]]
gchi> [sum x | x <- table]
[6,12,0]

What in the world is that lachen.gif
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
post #94 of 263
Quote:
Originally Posted by ARandomOWl View Post

What in the world is that lachen.gif

Using the right tools for the job. rolleyes.gif
15s
(13 items)
 
  
CPUMotherboardGraphicsRAM
Athlon II x4 640 Gigabyte 880GM-D2H AMD HD4250 4 GB 
Hard DriveOSMonitorPower
640GB Arch GNU/Linux i686 Fujitsu Siemens 4612 FA 350 W 
Mouse
Logitech G9x 
  hide details  
Reply
15s
(13 items)
 
  
CPUMotherboardGraphicsRAM
Athlon II x4 640 Gigabyte 880GM-D2H AMD HD4250 4 GB 
Hard DriveOSMonitorPower
640GB Arch GNU/Linux i686 Fujitsu Siemens 4612 FA 350 W 
Mouse
Logitech G9x 
  hide details  
Reply
post #95 of 263
Quote:
Originally Posted by MadCatMk2 View Post

Felt I should ruin this little party here with a haskell one-liner tongue.gif
Code:
gchi> let table = [[1,2,3],[5..7],[]]
gchi> [sum x | x <- table]
[6,12,0]

I don't want to ruin your parade, but I did a 1 liner first:
Code:
while (@mda) { printf "Sum of row %i : %i\n", $count-$#mda+1, sum(@{shift(@mda)}) }

[edit]

And mine formats correctly too tongue.gif
Edited by Plan9 - 12/11/11 at 3:58pm
post #96 of 263
Thread Starter 
Sorry guys for not checking back often.

Plan9, I do not really think that we need a new thread for every challenge since I am also updating every challenge in the first post.

But if you still feel that it's important then we can discuss with all the others and decide on what to do.
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
post #97 of 263
Quote:
Originally Posted by {Unregistered} View Post

Sorry guys for not checking back often.
Plan9, I do not really think that we need a new thread for every challenge since I am also updating every challenge in the first post.
But if you still feel that it's important then we can discuss with all the others and decide on what to do.

I think it would be tidier because then you could just look at the thread title and see that a new challenge is up and plus you know all the solutions in that thread are for that challenge. But at the end of the day it's your decision smile.gif
post #98 of 263
Thread Starter 
Quote:
Originally Posted by Plan9 View Post

I think it would be tidier because then you could just look at the thread title and see that a new challenge is up and plus you know all the solutions in that thread are for that challenge. But at the end of the day it's your decision smile.gif

Yea, I guess you're right.

Hopefully, the next challenge will be posted in a separate thread. Then, what I can do is instead of posting them in this thread and quoting them in the first post, I'll simply provide the links in the first post. That way this thread can be kept tidy and only be about the whole challenge and suggestions or comments about its format or something.

Thanks.
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
post #99 of 263
Here's my perl implementation of challenge 1:
Code:
print "Max number of *s: ";
$max = <>;

for ($i = 1; $i < $max; $i++) {
    print ("*" x $i . "\n");
}
for ($i = $max; $i > 0; $i--) {
    print ("*" x $i . "\n");
}

Input/Output:
Code:
$ ./challenge1.pl
Max number of *s: 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*

And here's my PHP implementation of challenge 2:
Code:
<?php
// initialize array of test data
$arrays = array(
    array(1, 2, 3),
    array(7, 5),
    array(0),
    array(),
    array(10, 44, 1, 3, 9, 77),
    array(9, 7, 6, 3)
);
// declare array for the sums of each row
$sums = array();

// iterate through rows of test data
foreach ($arrays as $i=>$vals) {
    // initialize sum of each row to 0
    $sums[$i] = 0;
    // iterate through numbers in each row
    foreach ($vals as $val) {
        // sum up the numbers
        $sums[$i] += $val;
    }
    // print the sum of each row
    $row = $i + 1;
    echo "Sum of row $row : $sums[$i] <br />\n";
}
?>

Input/Output:
Code:
Sum of row 1 : 6 
Sum of row 2 : 12 
Sum of row 3 : 0 
Sum of row 4 : 0 
Sum of row 5 : 144 
Sum of row 6 : 25

EDIT: I reread challenge 2 and wanted to update my code a little, so I've included comments and also made it so that when output, rows start at 1 instead of 0.

More challenges pleeeeease. biggrin.gif
Edited by Seventh Badger - 12/26/11 at 11:20am
Viking
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500K @ 4.8 GHz 1.45V P8Z68-V GEN3 [2x] EVGA GeForce GTX 570 SLI [2x] Kingston HyperX 4GB 1600MHz 
Hard DriveHard DriveCoolingCooling
Crucial M4 128GB [2x] WD 320GB XSPC Single Bay Reservoir Swiftech MCP655 
CoolingCoolingOSPower
XSPC Raystorm XSPC EX240 Windows 7 Pro 64-bit Corsair HX850 
Case
Corsair Obsidian 650D 
  hide details  
Reply
Viking
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 2500K @ 4.8 GHz 1.45V P8Z68-V GEN3 [2x] EVGA GeForce GTX 570 SLI [2x] Kingston HyperX 4GB 1600MHz 
Hard DriveHard DriveCoolingCooling
Crucial M4 128GB [2x] WD 320GB XSPC Single Bay Reservoir Swiftech MCP655 
CoolingCoolingOSPower
XSPC Raystorm XSPC EX240 Windows 7 Pro 64-bit Corsair HX850 
Case
Corsair Obsidian 650D 
  hide details  
Reply
post #100 of 263
Your PHP code should be using array_sum rather than a nested loop.

So your code would look a little more like this:
Code:
<?php
$arrays = array(
        array(1, 2, 3),
        array(7, 5),
        array(0),
        array(),
        array(10, 44, 1, 3, 9, 77),
        array(9, 7, 6, 3)
);

foreach ($arrays as $i=>$vals) {
        echo "Sum of row $i : ". array_sum($i) ."<br />\n"; 
}
?>

For languages like PHP - particularly ones which have fake arrays like PHP does - it pays dividends to use built in functions rather than re-inventing the wheel.
Edited by Plan9 - 12/25/11 at 10:46am
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › The Programming Challenge Master Thread