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 11

post #101 of 263
Quote:
Originally Posted by Plan9 View Post

Your PHP code should be using array_sum rather than a nested loop.
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.

Ah yeah, it was such a simple program I didn't even think about that. PHP has so many built-in functions, I always seem to forget which ones are available, especially the simple ones like array_sum().
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 #102 of 263
Thread Starter 
Hi!

It's great to know people have an interest in this.

I know I haven't updated this thread in quite some time but I have just been really really busy. I hope to have a new challenge up in a few days.
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 #103 of 263
Ok heres my code for the first challenge
Quote:
$star='*';
$max=10;
for($i=1;$i {
$last=$last.$star;
$history[]=$last;
}
$rhistory=array_reverse($history);
$history[]=$last.$star
$whole=array_merge($history,$rhistory);
echo implode('
',$whole);
?>

I made it on my phone with codepad smile.gif
$star can be changed to another string like $ or @ or fish and $max sets the peak length.
What do you think?
If anyone wants an explanation just ask smile.gif

http://codepad.org/3pp2VO7O

(The opening php tag disapears on ocn)
Teh neon walris
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD 1090T Asus M5A99X EVO Asus 7950 2x Kingston ValueRAM DDR3 PC10600/1333MHz CL9 2GB 
Hard DriveHard DriveOptical DriveOS
WD Caviar Blue 1tb 7200rpm Corsair force 3 LiteOn iHAS424 Arch Linux 
OSMonitorMonitorKeyboard
Windows 7 23" LG (Not sure what model) Asus vs247h razer blackwidow 
CaseMouseAudio
Cooler Master Storm Scout Razer naga Beyerdynamic DT-770 
  hide details  
Reply
Teh neon walris
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD 1090T Asus M5A99X EVO Asus 7950 2x Kingston ValueRAM DDR3 PC10600/1333MHz CL9 2GB 
Hard DriveHard DriveOptical DriveOS
WD Caviar Blue 1tb 7200rpm Corsair force 3 LiteOn iHAS424 Arch Linux 
OSMonitorMonitorKeyboard
Windows 7 23" LG (Not sure what model) Asus vs247h razer blackwidow 
CaseMouseAudio
Cooler Master Storm Scout Razer naga Beyerdynamic DT-770 
  hide details  
Reply
post #104 of 263
Thread Starter 
Quote:
Originally Posted by tehwalris View Post

Ok heres my code for the first challenge
Quote:
$star='*';
$max=10;
for($i=1;$i {
$last=$last.$star;
$history[]=$last;
}
$rhistory=array_reverse($history);
$history[]=$last.$star
$whole=array_merge($history,$rhistory);
echo implode('
',$whole);
?>
I made it on my phone with codepad smile.gif
$star can be changed to another string like $ or @ or fish and $max sets the peak length.
What do you think?
If anyone wants an explanation just ask smile.gif
http://codepad.org/3pp2VO7O
(The opening php tag disapears on ocn)

Your output shows "
" instead of an actual line break (return). Just wanted to let you know.
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 #105 of 263
Thats code pad. Nally invoked it would show a new line smile.gif
Teh neon walris
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD 1090T Asus M5A99X EVO Asus 7950 2x Kingston ValueRAM DDR3 PC10600/1333MHz CL9 2GB 
Hard DriveHard DriveOptical DriveOS
WD Caviar Blue 1tb 7200rpm Corsair force 3 LiteOn iHAS424 Arch Linux 
OSMonitorMonitorKeyboard
Windows 7 23" LG (Not sure what model) Asus vs247h razer blackwidow 
CaseMouseAudio
Cooler Master Storm Scout Razer naga Beyerdynamic DT-770 
  hide details  
Reply
Teh neon walris
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD 1090T Asus M5A99X EVO Asus 7950 2x Kingston ValueRAM DDR3 PC10600/1333MHz CL9 2GB 
Hard DriveHard DriveOptical DriveOS
WD Caviar Blue 1tb 7200rpm Corsair force 3 LiteOn iHAS424 Arch Linux 
OSMonitorMonitorKeyboard
Windows 7 23" LG (Not sure what model) Asus vs247h razer blackwidow 
CaseMouseAudio
Cooler Master Storm Scout Razer naga Beyerdynamic DT-770 
  hide details  
Reply
post #106 of 263
Thread Starter 
It works if you just replace the
Code:
<br>
tag with a simple return.

Good work though!
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 #107 of 263
Quote:
Originally Posted by {Unregistered} View Post

It works if you just replace the
Code:
<br>
tag with a simple return.
Good work though!

It works fine with the <br/> tag if it's executed via a web browser (which PHP scripts typically are)
If it's executed as a shell script, then you're right that you'd need a \n in it's place
post #108 of 263
Weirdly this forum accepts HTML tags

[edit]
not all HTML tags it seems
post #109 of 263
Quote:
Originally Posted by {Unregistered} View Post

I hope to have a new challenge up in a few days.

Wooooooo. Need to get my fix while school is out tongue.gif.
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 #110 of 263
challenge 1 in C.
Code:
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv){
int i, half, line;
int size = 1;
half = 10;
for(line=0; line<half*2-1; line++){
        for(i=0; i<size; i++){
                printf("*");
        }
        printf("\n");
        if(line < half-1)
                size++;
        else
                size--; 
}
return 0;
}

http://codepad.org/ghsLvNKh
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
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