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 14

post #131 of 263
Code:
package sum;

import java.util.Random;

public class Main {

    public static void main(String[] args) {
        // Create array
        int[][] array = generateArray();
        // Iterate through the array
        for(int y = 0; y < array.length; y++){
            int sum = 0;
            for(int x = 0; x < array[y].length; x++){
                // Add the values in each row
                sum += array[y][x];
                // Print each valid number
                if(array[y][x] != 0)
                    System.out.print(array[y][x] + " ");
            }
            // If the row was seeded print the sum
            if(sum != 0)
                System.out.print("\nSum: " + sum + "\n\n");
        }
    }

    public static int[][] generateArray(){
        // Create a max 10 x 10 array
        int[][] array = new int[10][10];
        Random randomGenerator = new Random();
        // Randomly seed up to 10 rows
        int length = randomGenerator.nextInt(10);
        for(int y = 0; y < length; y++){
            // Fill a row with atleast 1 up to 10 values
            int width = randomGenerator.nextInt(10) + 1;
            for(int x = 0; x < width; x++){
                array[y][x] = randomGenerator.nextInt(50);
            }
        }
        return array;
    }

}

Here is my submission for challenge #2. I don't know if this qualifies, what I did was seed an array of up to 10 rows with up to 10 values between 0-50. I print each value that was entered and then the sum. I did this over generating my own array of a given size. The X and Y bounds of the array size could easily be changed in addition to the values being put into them.

I have screen shots if needed!
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 #132 of 263
Quote:
Originally Posted by ChaoticKinesis View Post

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.

I appreciate that, but I wouldn't define verbose languages as less efficient languages due to the code volume. As I said before, you often find that more efficient code (in terms of code execution) that's less efficient (in terms of code length) so the term becomes confusing if you apply it to both instances. Therefore I think the scientific usage applies rather than the linguistics, given that software development is more a science than it is literacy.

I will concede that this is just a view point though smile.gif
post #133 of 263
Just saw this thread and decided that it needed a little Fortran (yes it is still widely used in scientific computing).
Here is challenge #1.
Code:
program chall1

 Implicit None
 integer, parameter :: N = 5
 integer :: i,j,k
 integer :: Nt=N*2
 character, dimension(N) :: chstr = "*****"

 do i=1,Nt-1
    if (i .le. Nt/2) then
       write(*,*) chstr(1:i)
    else
       k = Nt-i
       write(*,*) chstr(1:k)
    end if
 end do

end program chall1
 
HTPC
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7-3930k MSI X79MA-GD45 Powercolor 7950 G Skill 
Hard DriveCoolingCoolingCooling
Samsung 830 Swiftech Apogee XT Rev. 1 EK-FC HWLabs Black Ice GTX 240 and a Koolance HX-CU72... 
CoolingCoolingOSOS
MCP 35X and a MCP 350 Koolance 401x2 Opensuse 12.1 Windows 7 
KeyboardPowerCase
Ducky OCN with cherry blues Antec True Power New 650W Cooler Master CM690 II 
CPUMotherboardGraphicsRAM
i5-750 Gigabyte p55-ud2 GTX 430 G Skill 
Hard DriveOSPowerCase
Samsung HD204UI Fedora 15 Corsair CX-430 Silverstone GC04 
  hide details  
Reply
 
HTPC
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7-3930k MSI X79MA-GD45 Powercolor 7950 G Skill 
Hard DriveCoolingCoolingCooling
Samsung 830 Swiftech Apogee XT Rev. 1 EK-FC HWLabs Black Ice GTX 240 and a Koolance HX-CU72... 
CoolingCoolingOSOS
MCP 35X and a MCP 350 Koolance 401x2 Opensuse 12.1 Windows 7 
KeyboardPowerCase
Ducky OCN with cherry blues Antec True Power New 650W Cooler Master CM690 II 
CPUMotherboardGraphicsRAM
i5-750 Gigabyte p55-ud2 GTX 430 G Skill 
Hard DriveOSPowerCase
Samsung HD204UI Fedora 15 Corsair CX-430 Silverstone GC04 
  hide details  
Reply
post #134 of 263
Quote:
Originally Posted by Plan9 View Post


I appreciate that, but I wouldn't define verbose languages as less efficient languages due to the code volume. As I said before, you often find that more efficient code (in terms of code execution) that's less efficient (in terms of code length) so the term becomes confusing if you apply it to both instances. Therefore I think the scientific usage applies rather than the linguistics, given that software development is more a science than it is literacy.

I will concede that this is just a view point though smile.gif

You are correct to point out that verbosity is not the same as a lack of efficiency but I was simply pointing out what I believe was the intention of that comment about the "efficiency" of the language for the particular application. I suspect the intended meaning was that it was not practical for the task at hand. Then again, I don't think any of these challenges are meant to be practical and the more languages that are demonstrated, the better. I, for one, have not used Pascal so it was nice to see it in use. smile.gif
     
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 #135 of 263
Ok so here is challenge #2:
Code:
program chall2

 Implicit None
 integer, parameter :: N = 3
 integer, parameter :: M = 4
 integer, dimension(N,M) :: V
 integer, dimension(N)   :: smV  
 integer :: i,j
 character, dimension(50) :: strout
 !Put the values into the array to have a missing value use -999 as the value
 V(1,:) = (/-999,5,12,2/)
 V(2,:) = (/1,10,3,6/)
 V(3,:) = (/5,3,4,9/)
 smV = 0
 do i=1,N
     smV(i) = sum(V(i,:),MASK=V(i,:) /= -999)
    write(*,*)  "The sum of row ",i," is ",smV(i)
 end do

end program chall2

The output is
Code:
 The sum of row            1  is           19
 The sum of row            2  is           20
 The sum of row            3  is           21

Note values of -999 are ignored and not used to calc the sum.
 
HTPC
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7-3930k MSI X79MA-GD45 Powercolor 7950 G Skill 
Hard DriveCoolingCoolingCooling
Samsung 830 Swiftech Apogee XT Rev. 1 EK-FC HWLabs Black Ice GTX 240 and a Koolance HX-CU72... 
CoolingCoolingOSOS
MCP 35X and a MCP 350 Koolance 401x2 Opensuse 12.1 Windows 7 
KeyboardPowerCase
Ducky OCN with cherry blues Antec True Power New 650W Cooler Master CM690 II 
CPUMotherboardGraphicsRAM
i5-750 Gigabyte p55-ud2 GTX 430 G Skill 
Hard DriveOSPowerCase
Samsung HD204UI Fedora 15 Corsair CX-430 Silverstone GC04 
  hide details  
Reply
 
HTPC
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7-3930k MSI X79MA-GD45 Powercolor 7950 G Skill 
Hard DriveCoolingCoolingCooling
Samsung 830 Swiftech Apogee XT Rev. 1 EK-FC HWLabs Black Ice GTX 240 and a Koolance HX-CU72... 
CoolingCoolingOSOS
MCP 35X and a MCP 350 Koolance 401x2 Opensuse 12.1 Windows 7 
KeyboardPowerCase
Ducky OCN with cherry blues Antec True Power New 650W Cooler Master CM690 II 
CPUMotherboardGraphicsRAM
i5-750 Gigabyte p55-ud2 GTX 430 G Skill 
Hard DriveOSPowerCase
Samsung HD204UI Fedora 15 Corsair CX-430 Silverstone GC04 
  hide details  
Reply
post #136 of 263
Quote:
Originally Posted by mdatmo View Post

Just saw this thread and decided that it needed a little Fortran (yes it is still widely used in scientific computing).

O_O. I was working on a flight simulator at an internship last summer and a lot of the programming was done in Fortran/Ada. It was interesting to say the least.
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 #137 of 263
Glad to have found this thread! Will be posting up my own submissions soon enough.
Wind Tunnel
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i5 3570K ASUS P8Z77-V LK ASUS AMD Radeon HD 7970 Diamond AMD Radeon HD 7970 
RAMHard DriveHard DriveHard Drive
8 Gb G.Skill Ripjaws 120Gb OCZ Vertex 2 620gb WD Caviar Black 2x 1Tb WD Caviar Black  
Optical DriveCoolingOSMonitor
2x DVD Drive Zalman CNPS9700 Windows 7 Ultimate 64-Bit Alienware Optx AW2310 
KeyboardPowerCaseMouse
Das Model S Professional Rosewill Lightning 1300W Antec 1200 Logitech G500 
Mouse PadAudioOther
Mionix Propus 380 Creative Sound Blaster X-Fi Titanium HD Audio-Technica ATH-A900X 
  hide details  
Reply
Wind Tunnel
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i5 3570K ASUS P8Z77-V LK ASUS AMD Radeon HD 7970 Diamond AMD Radeon HD 7970 
RAMHard DriveHard DriveHard Drive
8 Gb G.Skill Ripjaws 120Gb OCZ Vertex 2 620gb WD Caviar Black 2x 1Tb WD Caviar Black  
Optical DriveCoolingOSMonitor
2x DVD Drive Zalman CNPS9700 Windows 7 Ultimate 64-Bit Alienware Optx AW2310 
KeyboardPowerCaseMouse
Das Model S Professional Rosewill Lightning 1300W Antec 1200 Logitech G500 
Mouse PadAudioOther
Mionix Propus 380 Creative Sound Blaster X-Fi Titanium HD Audio-Technica ATH-A900X 
  hide details  
Reply
post #138 of 263
Here's my submission for Challenge #1, written in C:
Code:

#include <stdio.h>

int main() {
  int maxStars, i, j;
  int offset = 1;

  scanf("%d", %maxStars);

  for (i = 1; i < maxStars * 2; i++) {
    if (i > maxStars)
      offset += 2;
    for (j = 1; j <= i - offset; j++) {
      if (j == i - offset) {
        printf("*\n");
      } else {
        printf("*");
      }
    }
  }

  return 0;
}


Edited by Leeeeeeeeee - 12/28/11 at 3:43pm
Wind Tunnel
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i5 3570K ASUS P8Z77-V LK ASUS AMD Radeon HD 7970 Diamond AMD Radeon HD 7970 
RAMHard DriveHard DriveHard Drive
8 Gb G.Skill Ripjaws 120Gb OCZ Vertex 2 620gb WD Caviar Black 2x 1Tb WD Caviar Black  
Optical DriveCoolingOSMonitor
2x DVD Drive Zalman CNPS9700 Windows 7 Ultimate 64-Bit Alienware Optx AW2310 
KeyboardPowerCaseMouse
Das Model S Professional Rosewill Lightning 1300W Antec 1200 Logitech G500 
Mouse PadAudioOther
Mionix Propus 380 Creative Sound Blaster X-Fi Titanium HD Audio-Technica ATH-A900X 
  hide details  
Reply
Wind Tunnel
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i5 3570K ASUS P8Z77-V LK ASUS AMD Radeon HD 7970 Diamond AMD Radeon HD 7970 
RAMHard DriveHard DriveHard Drive
8 Gb G.Skill Ripjaws 120Gb OCZ Vertex 2 620gb WD Caviar Black 2x 1Tb WD Caviar Black  
Optical DriveCoolingOSMonitor
2x DVD Drive Zalman CNPS9700 Windows 7 Ultimate 64-Bit Alienware Optx AW2310 
KeyboardPowerCaseMouse
Das Model S Professional Rosewill Lightning 1300W Antec 1200 Logitech G500 
Mouse PadAudioOther
Mionix Propus 380 Creative Sound Blaster X-Fi Titanium HD Audio-Technica ATH-A900X 
  hide details  
Reply
post #139 of 263
Quote:
Originally Posted by ChaoticKinesis View Post

You are correct to point out that verbosity is not the same as a lack of efficiency but I was simply pointing out what I believe was the intention of that comment about the "efficiency" of the language for the particular application. I suspect the intended meaning was that it was not practical for the task at hand. Then again, I don't think any of these challenges are meant to be practical and the more languages that are demonstrated, the better. I, for one, have not used Pascal so it was nice to see it in use. smile.gif

Again, I think most people could realise that he meant code length. The reason I made my comment was because those who are unfamiliar with Pascal likely assumed it was yet another scripting / bytecode language when it is not. Hence my point about it being very efficient.

Pascal is a great language - I miss it frown.gif
post #140 of 263
Quote:
Originally Posted by ChaoticKinesis View Post

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.

Yeah, for this job, the ammount of time taken writing the code could be considered as being the efficiency.
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
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