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 3

post #21 of 256
Quote:
Originally Posted by Chris++ View Post

Python here, went for simple to understand rather than fancy code, but it gets the job done.
Code:
NUMBER_OF_STARS = 5
i = 1
while i <= NUMBER_OF_STARS:
    print ('*' * i)
    i = i + 1
while i > 0:
    print ('*' * i)
    i = i - 1




Hmm weird, you don't have to declare variable types in python like int, char etc?
i7 on the cheap
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 970 Gigabyte X58A-UD7 evga GTX470 Corsair Vengence 
Hard DriveOptical DriveOSMonitor
Intel X25-M 160GB LG GBW-H20L Windows 7 Ultimate Acer GD235HZ 23.6" 120HZ 
KeyboardPowerCaseMouse
Logitech G15 Rocketfish 900W 80+ Silver Corsair Obsidian 800D Cyborg Rat 7 
  hide details  
Reply
i7 on the cheap
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 970 Gigabyte X58A-UD7 evga GTX470 Corsair Vengence 
Hard DriveOptical DriveOSMonitor
Intel X25-M 160GB LG GBW-H20L Windows 7 Ultimate Acer GD235HZ 23.6" 120HZ 
KeyboardPowerCaseMouse
Logitech G15 Rocketfish 900W 80+ Silver Corsair Obsidian 800D Cyborg Rat 7 
  hide details  
Reply
post #22 of 256
Just saw this thread and I'm currently in an intro to C++ and java class and would love to participate!
post #23 of 256
Quote:
Originally Posted by Dman View Post

Hmm weird, you don't have to declare variable types in python like int, char etc?

i havent' used python but I think it uses implicit variable declaration.
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 8 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 8 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
post #24 of 256
heres my code...it works! lol
Code:
void stars(int max){
         for(int x = 0; x <= max ; ++x){
                for(int j = 0; j < x; ++j)
                       cout << '*';
                 cout << endl;
          }
          for(int x = max - 1; x > 0; --x){
                   for(int j = 0; j < x; ++j)
                           cout << '*';
                   cout << endl;
          }
}


here it is working with a max of 40 stars

338
Edited by surfbumb - 11/22/11 at 8:18pm
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 8 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 8 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
post #25 of 256
Quote:
Originally Posted by Dman View Post

Hmm weird, you don't have to declare variable types in python like int, char etc?

Nope, Python's interpreter takes care of it based on the content and/or use of the variable, but make no mistake, they do in fact have a variable type.
Back in Black
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X4 965 BE (C3) Biostar TA790GX A3+ Sapphire HD 5770 (v2) CORSAIR XMS3 4GB DDR3 
Hard DriveOptical DriveOSMonitor
WD Caviar Black 640GB Sony Optiarc CD/DVD RW Windows 7 Ultimate x64 NEC MultiSync LCD 1960NXi 
KeyboardPowerCaseMouse
Microsoft Comfort Curve Keyboard 2000 Corsair 650TX Cooler Master Storm Scout Logitech MX 400 Laser 
  hide details  
Reply
Back in Black
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II X4 965 BE (C3) Biostar TA790GX A3+ Sapphire HD 5770 (v2) CORSAIR XMS3 4GB DDR3 
Hard DriveOptical DriveOSMonitor
WD Caviar Black 640GB Sony Optiarc CD/DVD RW Windows 7 Ultimate x64 NEC MultiSync LCD 1960NXi 
KeyboardPowerCaseMouse
Microsoft Comfort Curve Keyboard 2000 Corsair 650TX Cooler Master Storm Scout Logitech MX 400 Laser 
  hide details  
Reply
post #26 of 256
Quote:
Originally Posted by Chris++ View Post

Nope, Python's interpreter takes care of it based on the content and/or use of the variable, but make no mistake, they do in fact have a variable type.

BASIC is the same way, lots of dialects don't require you to declare variable types.
CHILZ - Lan Rig
(17 items)
 
CANARY - Main Rig
(16 items)
 
CADILLAC - HTPC
(14 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon X3480 Asus Maximus III Gene AMD 7950 Mushkin Redline 2133 MHz CL9 
Hard DriveHard DriveHard DriveCooling
250 GB Samsung 840 120 GB OCZ Solid 3 60 GB OCZ Vertex 2 Custom Loop 
OSMonitorKeyboardPower
Windows 8 Pro BenQ GL2450 Filco MajesTouch2 Ninja PC P&C Silencer Mk III 600 W 
CaseMouseMouse PadAudio
Spotswood Small Tech Station Tt e-Sports Saphira Monoprice XXL Yamaha R-S300 + JVC Bookshelfs 
Other
Scythe Kama-Panel 3 
CPUMotherboardGraphicsRAM
FX-8150 @ 4.6 GHz Fatal1ty 990FX Pro 9800 GTX+ 512 MB G.Skill Ripjaws X 1866 CL9 
Hard DriveHard DriveCoolingOS
120 GB OCZ Vertex 3 1 TB WD Black 5x 120mm + MCP350 + EK Supreme HF + MicroRes Windows 8 Consumer Preview 
MonitorKeyboardPowerCase
2x Dell U2212HM Logitech G110 Cooler Master 850W Silent Pro Cooler Master 690 II Adv. 
MouseMouse PadAudio
Razer Death Adder 3.5G Staples Gel Cushion Asus Xonar DG + Senn. PC333D 
CPUMotherboardGraphicsRAM
Q6600 Acer X1800 ATI 5670 2 GB Kingston 
Hard DriveOptical DriveOSMonitor
2 TB WD Green Asus BD-R Windows 7 Home Premium Sony 50" LCD 
KeyboardPowerCaseMouse
Acer Media 220 W SFF Acer X1800 Acer Optical 
Mouse PadAudio
The TV cabinet Denon 2808 7.1 AVR + Dahlquist 350W 8" Sub + Kl... 
  hide details  
Reply
CHILZ - Lan Rig
(17 items)
 
CANARY - Main Rig
(16 items)
 
CADILLAC - HTPC
(14 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon X3480 Asus Maximus III Gene AMD 7950 Mushkin Redline 2133 MHz CL9 
Hard DriveHard DriveHard DriveCooling
250 GB Samsung 840 120 GB OCZ Solid 3 60 GB OCZ Vertex 2 Custom Loop 
OSMonitorKeyboardPower
Windows 8 Pro BenQ GL2450 Filco MajesTouch2 Ninja PC P&C Silencer Mk III 600 W 
CaseMouseMouse PadAudio
Spotswood Small Tech Station Tt e-Sports Saphira Monoprice XXL Yamaha R-S300 + JVC Bookshelfs 
Other
Scythe Kama-Panel 3 
CPUMotherboardGraphicsRAM
FX-8150 @ 4.6 GHz Fatal1ty 990FX Pro 9800 GTX+ 512 MB G.Skill Ripjaws X 1866 CL9 
Hard DriveHard DriveCoolingOS
120 GB OCZ Vertex 3 1 TB WD Black 5x 120mm + MCP350 + EK Supreme HF + MicroRes Windows 8 Consumer Preview 
MonitorKeyboardPowerCase
2x Dell U2212HM Logitech G110 Cooler Master 850W Silent Pro Cooler Master 690 II Adv. 
MouseMouse PadAudio
Razer Death Adder 3.5G Staples Gel Cushion Asus Xonar DG + Senn. PC333D 
CPUMotherboardGraphicsRAM
Q6600 Acer X1800 ATI 5670 2 GB Kingston 
Hard DriveOptical DriveOSMonitor
2 TB WD Green Asus BD-R Windows 7 Home Premium Sony 50" LCD 
KeyboardPowerCaseMouse
Acer Media 220 W SFF Acer X1800 Acer Optical 
Mouse PadAudio
The TV cabinet Denon 2808 7.1 AVR + Dahlquist 350W 8" Sub + Kl... 
  hide details  
Reply
post #27 of 256
Perl (just because I haven't seen a Perl entry yet):
Code:
#!/usr/bin/perl

if (!$ARGV[0] =~ m/[0-9]+/) { die "Parameter must be an integer\n" }

my ($direction, $i) = qw(1 1);
do {
    for ($i; ($i <= $ARGV[0] && $direction == 1) || ($i > 0 && $direction == -1); $i += $direction) {
        printf "%s\n", "*"x$i;
    }
    $direction *= -1;
} while ($direction != 1)

edit: oops, outputted hashes rather than asterisks.

edit2: CLI version for instant gratification:
Code:
perl -e 'my ($d, $i) = qw(1 1); do {for ($i; ($i<=$ARGV[0] && $d==1) || ($i>0 && $d==-1); $i+=$d) {printf "%s\n", "*"x$i} $d*=-1} while ($d!=1)' 5

Edited by Plan9 - 11/23/11 at 8:05am
post #28 of 256
Thread Starter 
Hmmm... Nice work guys! thumb.gif

I've checked most of your codes and they look fine by me. (I'll be going over them again now.)

I personally did the task twice, once in Java (it looked sort of like Aximous's code) and once in Python (it looked sort of like Chris++'s code : only uselessly longer since I couldn't concentrate due to lack of sleep tongue.gif).
Python Code: (Click to show)
Code:
n = int(raw_input("Enter the max number of stars: "))
count = 0
inversecount = (2*n)

while (count+1 <= n):
    print "*" * (count + 1)
    count = count + 1

while (inversecount-1 > n):
    print "*" * (inversecount-n-1)
    inversecount = inversecount - 1

But I have just one question to ask you people: What sort of format should we have as to what happens after the results? Should we have some point-based system with a record of how people performed or should we just use these challenges as exercises to sharpen our programming skills?

I do believe that those who are enthusiastic about programming will try these exercises and want to improve but do you guys think we should continue like this or bring something new in?

Thanks for the wonderful participation.
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 #29 of 256
You could make a simple spreadsheet with the name of those who are participating and the number of challenge the manage to make.

I do the challenge because it's a good way to practice. And it's fun to see what the other have done too.
    
CPUMotherboardGraphicsRAM
AMD FX-8320 3.5Ghz @ 3.5ghz Gigabyte 990FXA-UD3 Gigabyte 6850 OC windforce 1GB GDDR5  8GB (2x4GB) G.SKILL RipjawsX F3-12800CL9D-8GBXL 
Hard DriveHard DriveHard DriveCooling
2TB Caviar Green 250GB Hitachi 64GB Crucial M4 Noctua D14 
OSMonitorMonitorMonitor
Linux + Windows 7 64Bits LG Flatron Wide 20.1" 1680x1050 LG Flatron W2442PA 24" 1080p Samsung B2430HD 24 With TV Tuner 1080p 
KeyboardPowerCaseMouse
CM Quickfire Rapid Blue Corsair TX750V2 CM 690 II Logitech G5 
Mouse PadAudio
Steelseries QCK Cloth medium Logitech x-540 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD FX-8320 3.5Ghz @ 3.5ghz Gigabyte 990FXA-UD3 Gigabyte 6850 OC windforce 1GB GDDR5  8GB (2x4GB) G.SKILL RipjawsX F3-12800CL9D-8GBXL 
Hard DriveHard DriveHard DriveCooling
2TB Caviar Green 250GB Hitachi 64GB Crucial M4 Noctua D14 
OSMonitorMonitorMonitor
Linux + Windows 7 64Bits LG Flatron Wide 20.1" 1680x1050 LG Flatron W2442PA 24" 1080p Samsung B2430HD 24 With TV Tuner 1080p 
KeyboardPowerCaseMouse
CM Quickfire Rapid Blue Corsair TX750V2 CM 690 II Logitech G5 
Mouse PadAudio
Steelseries QCK Cloth medium Logitech x-540 
  hide details  
Reply
post #30 of 256
Thread Starter 
Quote:
Originally Posted by spikexp View Post

You could make a simple spreadsheet with the name of those who are participating and the number of challenge the manage to make.
I do the challenge because it's a good way to practice. And it's fun to see what the other have done too.

Good suggestion. I was thinking of doing that but wasn't sure if anyone else would want that.

I'll make the spreadsheet soon.
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
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