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 13

post #121 of 263
Quote:
Originally Posted by tehwalris View Post

It doesn't seem like a very efficient language for the job smile.gif

Actually Pascal is a very efficient language. In fact many Windows and MacOS apps were written in Pacal before C++ really took hold.

In fact you'll often see a correlation between more code and a program being more efficient - whether it's languages like C and Pascal, or using DirectX hooks rather than software rendering. Less code doesn't mean more efficient code.
post #122 of 263
He says the truth. High level languages use a "c/p" type of code for every expression. Some compilers change the code into serveral different languages. I saw one the other day that generates C code and then generates GNU x86 assembler, and finally assembles that. which can generate much inefficiency.
SolusIgnis
(21 items)
 
2 Watts
(6 items)
 
Huh?!
(13 items)
 
CPUCPUCPUMotherboard
i7-3820 Xeon Phi 31S1P Copressor (WIP) Xeon Phi 31S1P Copressor (WIP) ASRock X79 Extreme6 
GraphicsRAMHard DriveCooling
XFX Reference 6950 Samsung Magic RAM Crucial M4 Cosair H80 
OSMonitorMonitorMonitor
Windows 8.1 Pro HannSpree HF205 1600x900 ASUS VH239H 1920x1080 ASUS VH239H 1920x1080 
KeyboardCaseMouseMouse Pad
CMStorm Quick Fire Pro, Cherry MX Blue Thermaltake Oversoar RX-I MadCatz RAT 9 Saitek Cyborg V.5 
OtherOtherOther
Thrustmaster HOTAS Warthog TrackIR 5 Saitek Pro Combat Pedals 
CPUMotherboardRAMHard Drive
Marvell PXA510 D2Plug DDR3 
Optical DriveCooling
Pssh! Who needs optical drives Passive 
CPUOS
i386 MS-DOS 
  hide details  
Reply
SolusIgnis
(21 items)
 
2 Watts
(6 items)
 
Huh?!
(13 items)
 
CPUCPUCPUMotherboard
i7-3820 Xeon Phi 31S1P Copressor (WIP) Xeon Phi 31S1P Copressor (WIP) ASRock X79 Extreme6 
GraphicsRAMHard DriveCooling
XFX Reference 6950 Samsung Magic RAM Crucial M4 Cosair H80 
OSMonitorMonitorMonitor
Windows 8.1 Pro HannSpree HF205 1600x900 ASUS VH239H 1920x1080 ASUS VH239H 1920x1080 
KeyboardCaseMouseMouse Pad
CMStorm Quick Fire Pro, Cherry MX Blue Thermaltake Oversoar RX-I MadCatz RAT 9 Saitek Cyborg V.5 
OtherOtherOther
Thrustmaster HOTAS Warthog TrackIR 5 Saitek Pro Combat Pedals 
CPUMotherboardRAMHard Drive
Marvell PXA510 D2Plug DDR3 
Optical DriveCooling
Pssh! Who needs optical drives Passive 
CPUOS
i386 MS-DOS 
  hide details  
Reply
post #123 of 263
Bored, here is my java solution to the first challenge:
Code:
public class One implements Challenge {

        int max = 10;
        char symbol = '*';
        @Override
        public void run() {
                for(int c = 1; c < max+1; c++){
                        for(int s = 0; s < c; s++){
                                System.out.print(symbol);
                        }
                        System.out.println();
                }
                for(int c = max-1; c > 0; c--){
                        for(int s = 0; s < c; s++){
                                System.out.print(symbol);
                        }
                        System.out.println();
                }
        }
}

I created a mini program launcher, in which i will save all my challenges, This way, I can just enter a number, and it will run the corresponding program. That's why the program in is run(), instead of main()
post #124 of 263
Here is the video of it.

http://www.youtube.com/watch?v=jeF7uQjvOpQ&feature=youtu.be

Media fire is closed sorry will edit it.
Edited by Justinba1010 - 12/27/11 at 9:17pm
Dell Inspiron
(9 items)
 
  
CPUMotherboardGraphicsRAM
Intel Pentium Dell Inspiron 537 Nvidia Dell 
Hard DriveOptical DriveOSMonitor
Dell DVD+CD-RW Burner and Writer Ubuntu Oneiric, x86 Version Acer 
Keyboard
Dell Generic 
  hide details  
Reply
Dell Inspiron
(9 items)
 
  
CPUMotherboardGraphicsRAM
Intel Pentium Dell Inspiron 537 Nvidia Dell 
Hard DriveOptical DriveOSMonitor
Dell DVD+CD-RW Burner and Writer Ubuntu Oneiric, x86 Version Acer 
Keyboard
Dell Generic 
  hide details  
Reply
post #125 of 263
Here are my responses using Perl.

Challenge 1 must be run with command line arguments, e.g.: perl FILENAME 5 *
Code:
# check args to be a number and non-empty char/string or kill script with message
$ARGV[0] =~ /^\d+$/ && $ARGV[1] =~ /^.+$/
        || die "File must be run with an integer followed by a character as arguments";
# size grows while current size is less than first arg
while ($size <= $ARGV[0]) {
        # print second arg as multiple of current size and increment size
        print $ARGV[1] x $size++ . "\n";      
}
# size shrinks while current size is greater than 0
while ($size > 0) { 
        # print second arg as multiple of current size and decrement size 
        print $ARGV[1] x $size-- . "\n"; 
}

Challenge 2 populates the array from interactive user input
Code:
my (@row, @arr) = ();
my $sum, $row; 

print "Enter number to sum or leave blank when done\n";

do {
        # read numbers from standard input
        while(<STDIN>) {
                chop;
                # if input is a number add to row, else break
                $_ =~ /\d/ ? push @row, $_ : last;
        }
        
        # add row of numbers to array of rows
        push @arr, [@row]; 
        # reset row array
        @row = (); 
        
        # prompt for entry of another row
        print "Enter numbers for new sum? (y/n)";
        chop ($_ = <STDIN>); 
} while ($_ =~ /y(es)?/i); # loop while answer is yes

$row = 1;
for (@arr) {
        $sum = 0; 
        # loop through row array
        for (@$_) { 
                $sum += $_;
        }
        print "Sum of row " . $row++ . " : $sum\n";
}

Edited by ChaoticKinesis - 12/27/11 at 4:09pm
     
CPUMotherboardGraphicsRAM
Intel Core i7-4770K Gigabyte G1.Sniper M5 EVGA GTX 780 SC Crucial Ballistix Sport 2 x 8GB 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 Pro 256GB Seagate Barracuda 3TB Seagate Barracuda 4TB Asus BD-ROM 
CoolingOSMonitorKeyboard
Noctua NH-D14 Windows 8 Pro Dell U2713HM Ducky YOTD (MX Brown) 
PowerCaseMouseMouse Pad
SeaSonic SS-760XP2 Fractal Design Arc Mini Roccat Savu SteelSeries 9HD 
Audio
Beyerdynamic DT990 250 Ohm 
CPUMotherboardGraphicsRAM
AMD A6-3500 Asrock A75M HD 6530D Samsung 4GB DDR3 1600  
Hard DriveHard DriveHard DriveOptical Drive
Intel 320 80GB Samsung Spinpoint F4 2TB WD Caviar Green 3TB Sony BD-Rom 
CoolingOSMonitorKeyboard
Noctua NH-C12P SE14 Win 7 Professional 64-bit Samsung LN46C600 Lenovo N5902 
PowerCaseOther
Corsair CX430 Antec Veris Fusion HDHomeRun Prime 
CPUMotherboardGraphicsRAM
AMD Phenom II X3 B55 Asus M5A99X EVO Sapphire HD 7950 G.Skill 8GB DDR3 
Hard DriveOptical DriveCoolingMonitor
Samsung F3 1TB LG DVD-RW CM Hyper 212 Plus Dell U2312HM 
KeyboardPowerCaseMouse
Pink KBT Race (MX Blue) Lepa G700-MA Corsair 500R Razer Abyssus 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
     
CPUMotherboardGraphicsRAM
Intel Core i7-4770K Gigabyte G1.Sniper M5 EVGA GTX 780 SC Crucial Ballistix Sport 2 x 8GB 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 Pro 256GB Seagate Barracuda 3TB Seagate Barracuda 4TB Asus BD-ROM 
CoolingOSMonitorKeyboard
Noctua NH-D14 Windows 8 Pro Dell U2713HM Ducky YOTD (MX Brown) 
PowerCaseMouseMouse Pad
SeaSonic SS-760XP2 Fractal Design Arc Mini Roccat Savu SteelSeries 9HD 
Audio
Beyerdynamic DT990 250 Ohm 
CPUMotherboardGraphicsRAM
AMD A6-3500 Asrock A75M HD 6530D Samsung 4GB DDR3 1600  
Hard DriveHard DriveHard DriveOptical Drive
Intel 320 80GB Samsung Spinpoint F4 2TB WD Caviar Green 3TB Sony BD-Rom 
CoolingOSMonitorKeyboard
Noctua NH-C12P SE14 Win 7 Professional 64-bit Samsung LN46C600 Lenovo N5902 
PowerCaseOther
Corsair CX430 Antec Veris Fusion HDHomeRun Prime 
CPUMotherboardGraphicsRAM
AMD Phenom II X3 B55 Asus M5A99X EVO Sapphire HD 7950 G.Skill 8GB DDR3 
Hard DriveOptical DriveCoolingMonitor
Samsung F3 1TB LG DVD-RW CM Hyper 212 Plus Dell U2312HM 
KeyboardPowerCaseMouse
Pink KBT Race (MX Blue) Lepa G700-MA Corsair 500R Razer Abyssus 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
post #126 of 263
This is my attempt at the challenge. It looks quite long but is over half comments. Both the character to display and the number of characters are entered on the command line. I program in Linux, but this should compile OK in Windows. I called the program stars but you can name it anything that suits you.

/*
*/
#include
#include
/*
*/
/* Create increasing and decreasing rows of stars or ??
* input the character to display and the maximum row length
* stars <'char'> */

int main(int argc, char **argv)
{
int x, y, ch, num;

if (argc != 3) {
/* most characters will display properly but because the */
/* asterisk has a special meaning to the shell if you want it to display */
/* properly it should be enclosed in single quotes or escaped (\*) on the command line */
printf("\nInvalid input. Must be stars <'char to display'> \n");
exit(1);
}
/* argv[0] is the name of the program */
/* argv[1] is the character to display. Since argv is a pointer to a pointer we need to use */
/* what is pointed to. */
ch = *argv[1];
/* argv[2] is the number of characters to print entered as a string which must be converted to an */
/* integer. atoi expects a pointer as its argument so we DO NOT use *argv[2] */
num = atoi(argv[2]);
/* x is the number of characters in each row */
for (x = 0; x < num; x++) {
/* y is the loop counter to print each character */
for (y = 0; y < x; y++)
printf("%c", ch);
printf("\n");
}
/* x is equal to one more than the longest row so we need to finish printing when x is equal to 1 */
for (; x > 0; x--) {
for (y = 0; y < x; y++)
printf("%c", ch);
printf("\n");
}
return(0);
}

/*
*/
post #127 of 263
It seems I don't know how to enter code on this site, but the includes are stdio.h and stdlib.h and the command line is stars 'char' number_of _chars.
Roy
post #128 of 263
Quote:
Originally Posted by Roy Strachan View Post

It seems I don't know how to enter code on this site, but the includes are stdio.h and stdlib.h and the command line is stars 'char' number_of _chars.
Roy

Use the:
Code:
[ code ] [ \ code ]
Remove the spaces, I couldnt get it to display right without the spaces.
Edited by FiX - 12/27/11 at 9:41pm
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
FX-8350 Asus Crosshair V MSI GTX460 Hawk 1gb MSI GTX460 Hawk 1gb 
RAMHard DriveHard DriveHard Drive
Kingston HyperX 8gb (2x4gb) Crucial M4 64GB Samsung F3 1TB Western Digital 320GB 
CoolingOSMonitorMonitor
Custom WC Windows 7 Ultimate X64 Dell E2311H Dell E2311H 
MonitorKeyboardPowerCase
LH 23EN43 Ducky Year of the Dragon 2012 SilverStone Strider 1000W-P Corsair 800D 
Audio
Asus Xonar Essence STX 
  hide details  
Reply
post #129 of 263
Code:
package starDraw;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Number of Rows: ");
        int stars = input.nextInt();
        System.out.print("\n");
        for(int y = 0; y < stars; y++){
            for(int x = 0; x < y+1; x++){
                System.out.print('*');
            }
            System.out.print("\n");
        }
        for(int y = stars-1; y > 0; y--){
            for(int x = 0; x < y; x++){
                System.out.print('*');
            }
            System.out.print("\n");
        }
    }
}

Here is my first challenge submission. Gonna go look at the second challenge now.
Sokar
(20 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 @ 3.75 GHz EVGA x58 3x SLI EVGA 670 4GB 12GB Samsung PC3 12800 
Hard DriveHard DriveHard DriveHard Drive
Cruical M4 WD Caviar Black WD Caviar Black Seagate 
CoolingOSMonitorKeyboard
Custom WC Loop Windows 7 x64 x3 Dell U2312HM I-ROCKS KR-6820E-BK 
PowerCaseMouseMouse Pad
Ultra x3 1000w Danger Den Torture Rack Razer Deathadder Black Razer Goliathis 
AudioAudioAudio
Inifitity P153 Speakers Lepai TA202A Amp Asus Xonar DG 
  hide details  
Reply
Sokar
(20 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 @ 3.75 GHz EVGA x58 3x SLI EVGA 670 4GB 12GB Samsung PC3 12800 
Hard DriveHard DriveHard DriveHard Drive
Cruical M4 WD Caviar Black WD Caviar Black Seagate 
CoolingOSMonitorKeyboard
Custom WC Loop Windows 7 x64 x3 Dell U2312HM I-ROCKS KR-6820E-BK 
PowerCaseMouseMouse Pad
Ultra x3 1000w Danger Den Torture Rack Razer Deathadder Black Razer Goliathis 
AudioAudioAudio
Inifitity P153 Speakers Lepai TA202A Amp Asus Xonar DG 
  hide details  
Reply
post #130 of 263
Quote:
Originally Posted by Plan9 View Post

Quote:
Originally Posted by tehwalris View Post

It doesn't seem like a very efficient language for the job smile.gif

Actually Pascal is a very efficient language. In fact many Windows and MacOS apps were written in Pacal before C++ really took hold.

In fact you'll often see a correlation between more code and a program being more efficient - whether it's languages like C and Pascal, or using DirectX hooks rather than software rendering. Less code doesn't mean more efficient code.

Not to comment on what is or is not efficient, but he did mention "for the job," and for any given task runtime efficiency must be weighed against coding efficiency. For simpler tasks such as these, we need not concern ourselves even if a high-level language is 100 times slower than C.

Were we writing for a high-performance environment, that may change depending on the complexity of the program. But I'm sure this has nothing to do with the later response concerning Pascal.
     
CPUMotherboardGraphicsRAM
Intel Core i7-4770K Gigabyte G1.Sniper M5 EVGA GTX 780 SC Crucial Ballistix Sport 2 x 8GB 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 Pro 256GB Seagate Barracuda 3TB Seagate Barracuda 4TB Asus BD-ROM 
CoolingOSMonitorKeyboard
Noctua NH-D14 Windows 8 Pro Dell U2713HM Ducky YOTD (MX Brown) 
PowerCaseMouseMouse Pad
SeaSonic SS-760XP2 Fractal Design Arc Mini Roccat Savu SteelSeries 9HD 
Audio
Beyerdynamic DT990 250 Ohm 
CPUMotherboardGraphicsRAM
AMD A6-3500 Asrock A75M HD 6530D Samsung 4GB DDR3 1600  
Hard DriveHard DriveHard DriveOptical Drive
Intel 320 80GB Samsung Spinpoint F4 2TB WD Caviar Green 3TB Sony BD-Rom 
CoolingOSMonitorKeyboard
Noctua NH-C12P SE14 Win 7 Professional 64-bit Samsung LN46C600 Lenovo N5902 
PowerCaseOther
Corsair CX430 Antec Veris Fusion HDHomeRun Prime 
CPUMotherboardGraphicsRAM
AMD Phenom II X3 B55 Asus M5A99X EVO Sapphire HD 7950 G.Skill 8GB DDR3 
Hard DriveOptical DriveCoolingMonitor
Samsung F3 1TB LG DVD-RW CM Hyper 212 Plus Dell U2312HM 
KeyboardPowerCaseMouse
Pink KBT Race (MX Blue) Lepa G700-MA Corsair 500R Razer Abyssus 
Mouse Pad
Razer Goliathus Speed 
  hide details  
Reply
     
CPUMotherboardGraphicsRAM
Intel Core i7-4770K Gigabyte G1.Sniper M5 EVGA GTX 780 SC Crucial Ballistix Sport 2 x 8GB 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 Pro 256GB Seagate Barracuda 3TB Seagate Barracuda 4TB Asus BD-ROM 
CoolingOSMonitorKeyboard
Noctua NH-D14 Windows 8 Pro Dell U2713HM Ducky YOTD (MX Brown) 
PowerCaseMouseMouse Pad
SeaSonic SS-760XP2 Fractal Design Arc Mini Roccat Savu SteelSeries 9HD 
Audio
Beyerdynamic DT990 250 Ohm 
CPUMotherboardGraphicsRAM
AMD A6-3500 Asrock A75M HD 6530D Samsung 4GB DDR3 1600  
Hard DriveHard DriveHard DriveOptical Drive
Intel 320 80GB Samsung Spinpoint F4 2TB WD Caviar Green 3TB Sony BD-Rom 
CoolingOSMonitorKeyboard
Noctua NH-C12P SE14 Win 7 Professional 64-bit Samsung LN46C600 Lenovo N5902 
PowerCaseOther
Corsair CX430 Antec Veris Fusion HDHomeRun Prime 
CPUMotherboardGraphicsRAM
AMD Phenom II X3 B55 Asus M5A99X EVO Sapphire HD 7950 G.Skill 8GB DDR3 
Hard DriveOptical DriveCoolingMonitor
Samsung F3 1TB LG DVD-RW CM Hyper 212 Plus Dell U2312HM 
KeyboardPowerCaseMouse
Pink KBT Race (MX Blue) Lepa G700-MA Corsair 500R Razer Abyssus 
Mouse Pad
Razer Goliathus Speed 
  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