Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge (Out-of-Date)
New Posts  All Forums:Forum Nav:

Programming Challenge (Out-of-Date) - Page 21  

Poll Results: Are you interested in participating in and/or helping organise and post these programming challenges?

 
  • 100% (2)
    I want to participate.
  • 0% (0)
    I want to contribute by helping posting and organise these challenges.
  • 0% (0)
    I'll only take part if other people are willing to participate.
  • 0% (0)
    I can help and participate - I love programming!
  • 0% (0)
    I do not wish to participate or help.
2 Total Votes  
post #201 of 306
I'm new to this (and not an experienced programmer), but here's what I got. I'm sure it's not the most efficient or best way, but it seems to work.

Code:
import java.util.ArrayList;
import java.util.Scanner;

public class Sums
{

    public static int getSum(ArrayList<Integer> arr, int size, int base)
    {
        int sum = 0;
        for (int i = 0; i < size; i++)
        {
            sum += arr.get(base + i);
        }
        return sum;
    }


    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        ArrayList<Integer> arr = new ArrayList<Integer>();
        int maxSum = 0;
        int testSum = 0;
        
        System.out.println("Enter the numbers, terminating character is a /.");
        String str = in.next();
        while (!str.equals("/"))
        {
            arr.add(Integer.parseInt(str));
            str = in.next();
        }
        
        
        for (int size = 1; size <= arr.size(); size++)
        {
            for (int base = 0; base + size <= arr.size(); base++)
            {
                testSum = getSum(arr, size, base);
                if (testSum > maxSum)
                {
                    maxSum = testSum;
                }
                testSum = 0;
            }            
        }
        System.out.println("Max Sum: " + maxSum);
        
    }
}

Edited by Waffleboy - 1/13/11 at 11:17am
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
post #202 of 306
Quote:
Originally Posted by Waffleboy View Post
I'm new to this (and not an experienced programmer), but here's what I got. I'm sure it's not the most efficient or best way, but it seems to work.

Code:
his code go up and look at it :)
I like it. Works on all the test cases. That is basically what we did for the competition in Wisconsin.
only 1 issue if all numbers are negative it chooses the highest negative number when technicality it should choose 0. I know it is weird but that is actually the way the writeup was written. You can choose not to add anything to your starting number of 0 which such as in the case of -1 -1 would be 0. But awesome job.

Also welcome to the programming challenge glad to have you. Hope to see more code from you when the next question gets posted.
Edited by Midpipps - 1/12/11 at 10:30am
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #203 of 306
Rather easy challenge

Code:
package challenges.maxcontiguoussum;


public class MaxContiguousSum {

public static void main(String[] args) {
long largest = 0;
long temptotal;
for(int i = 0;  i < args.length; i++) {
temptotal = Long.parseLong(args[i]);
if(temptotal > largest)
largest = temptotal;
for(int j = (i+1); j < args.length; j++) {
if((temptotal += Long.parseLong(args[j])) > largest)
largest = temptotal;
}
}
System.out.println(largest);
}
}

Edited by xtascox - 1/12/11 at 10:23pm
post #204 of 306
here it is in C# I really tried to think of a different algorithm for this but it seems I am drawing a blank on anything other then the two pointer method

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OCNTest
{
    class Program
    {
        static void Main(string[] args)
        {
            int highestNumber = 0;
            int tempNumber = 0;
            List<Int32> numbers = new List<Int32>();
            foreach (String s in args)
                numbers.Add(Int32.Parse(s));

            tempNumber = numbers.Max();
            if (tempNumber > highestNumber)
                highestNumber = tempNumber;

            for (int i = 0; i < numbers.Count; i++)
            {
                tempNumber = 0;
                numbers.GetRange(i, numbers.Count - i).ForEach(delegate(Int32 newNumber)
                {
                    tempNumber += newNumber;
                    if (tempNumber > highestNumber)
                        highestNumber = tempNumber;
                });
            }

            Console.WriteLine(highestNumber);
                
        }
    }
}
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #205 of 306
Quote:
Originally Posted by Midpipps View Post
here it is in C# I really tried to think of a different algorithm for this but it seems I am drawing a blank on anything other then the two pointer method
Yea I think this is probably the best algorithm. Although I'm sure there are far worse and far slower algorithms.
post #206 of 306
Quote:
Originally Posted by Midpipps View Post
I like it. Works on all the test cases. That is basically what we did for the competition in Wisconsin.
only 1 issue if all numbers are negative it chooses the highest negative number when technicality it should choose 0. I know it is weird but that is actually the way the writeup was written. You can choose not to add anything to your starting number of 0 which such as in the case of -1 -1 would be 0. But awesome job.

Also welcome to the programming challenge glad to have you. Hope to see more code from you when the next question gets posted.
Thanks, I forgot about the zero thing lol, so I just set 0 as the initial value for the maxSum instead of the MIN_VALUE constant. Thanks for the tip and the welcome, I'll probably try these every week now
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
post #207 of 306
I did it a little differently. I get a list of all of the positive numbers and then only do sums of positive number A to positive number B.

Code:
class MaxSeq {

 
}

object MaxSeq {

def sumAB(lst:List[Tuple2[Int,Int]], st: Int, end:Int): Int = {

var sum:Int = 0;
lst.slice(st, end).foreach{x => sum+=x._1 };
if(sum < 0) { 0}
else { return sum; }
}

def main(args : Array[String]) : Unit = {


val intList: List[Int] = args.toList.map(x => x.toInt)
val indList = intList.zipWithIndex;

//get all positive peaks
var posIndex = indList.filter(x => x._1 >= 0)
var working = posIndex
var maxSum = 0
while(working.size > 0)
{
var ent = working(0)
working = working.tail
if(working.size > 0)
        {
val sumList = for(a<- working) yield sumAB(indList, ent._2, a._2+1);
if(sumList.max > 0 && sumList.max > maxSum)
{
maxSum = sumList.max

}
}
}

println(maxSum);

}

}
post #208 of 306
Quote:
Originally Posted by impatient View Post
I did it a little differently. I get a list of all of the positive numbers and then only do sums of positive number A to positive number B.

Code:
CODE HERE
I like it especially that it is different then the rest
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #209 of 306
I cant find the challenge?
also can we use coldfusion?
Roof Ski
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 950 @4ghz HT on 1v XFX X58I SLi 295's 12GB OCZ Obsidian 1600mhz 
Hard DriveOptical DriveOSMonitor
ocz agility 3 + 4TB Drives Samsung DVD-RW Win 7 Ultimate x64 2x Samsung 24"s + DELL E248WFP 
KeyboardPowerCaseMouse
G11 Sleeved corsair ax850 800D Sidewinder 
  hide details  
Roof Ski
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 950 @4ghz HT on 1v XFX X58I SLi 295's 12GB OCZ Obsidian 1600mhz 
Hard DriveOptical DriveOSMonitor
ocz agility 3 + 4TB Drives Samsung DVD-RW Win 7 Ultimate x64 2x Samsung 24"s + DELL E248WFP 
KeyboardPowerCaseMouse
G11 Sleeved corsair ax850 800D Sidewinder 
  hide details  
post #210 of 306
Quote:
Originally Posted by SKl View Post
I cant find the challenge?
also can we use coldfusion?
Sorry the new challenge will go up later today when I get some time to post it up. The latest challenge is always linked in my sig. Yes you can use coldfusion or any other programming language you would like.
Edited by Midpipps - 1/19/11 at 8:17am
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
This thread is locked  
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge (Out-of-Date)