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 28  

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 #271 of 306
go here for the problem http://www.overclock.net/coding-prog...l#post13906339

Here are the full test cases they used in the competition
Input
Quote:
1 999999 3 22
100
4 5 6 7 8 9 10
9999999
-1
Output
Quote:
Case 1
1
1

Case 2
999999
486
116
38
73
58
89
145
42
20
4

Case 3
3
9
81
65
61
37
58
89
145
42
20
4

Case 4
22
8
64
52
29
85
89
145
42
20
4

Case 5
100
1

Case 6
4
16
37
58
89
145
42
20
4

Case 7
5
25
29
85
89
145
42
20
4

Case 8
6
36
45
41
17
50
25
29
85
89
145
42
20
4

Case 9
7
49
97
130
10
1

Case 10
8
64
52
29
85
89
145
42
20
4

Case 11
9
81
65
61
37
58
89
145
42
20
4

Case 12
10
1

Case 13
9999999
567
110
2
4

Edited by Midpipps - 6/17/11 at 8:47am
    
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 #272 of 306
this is the first programming challenge i've done on here thanks for posting these problems, it'll help keep me sharp over summer break. here's my recursive solution in java for the Sum of Digits Squared problem.

Code:
import java.util.ArrayList;

public class sum{
public static void main(String[] args){
for(int i=0; i<args.length; i++){
int input = 0;
try{
input = Integer.parseInt(args[i]);
}
catch(NumberFormatException e){
System.err.println("Please restart the program and enter an Ingeter");
System.exit(0);
}
if(input != -1){
int caseNum = i+1;
System.out.println("Case "+caseNum);
System.out.println(input);
int unused = parseNumber(input);
System.out.println("");
}
else{
System.exit(0);
}
}
}

public static int parseNumber(int input){
ArrayList<Integer> digits = getDigitsSquared(input);
int sum = 0;
for(int i=0; i<digits.size(); i++){
sum+=digits.get(i);
}
System.out.println(sum);
if((sum==1)||(sum==4))
return sum;

return parseNumber(sum);
}

public static ArrayList<Integer> getDigitsSquared(int input){
ArrayList<Integer> digits = new ArrayList<Integer>();
    while(input > 0) {
        digits.add((input % 10)*(input % 10));
        input /= 10;
    }
    return digits;
}
}
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  
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  
post #273 of 306
Good Answer new one is acoming

Quote:
Problem 3 — Sorting by Exclusion

Professor Smith has been given a list of words to sort. However, she decided it would be easier to throw some words away so that the rest of the list (in the same relative order) will be sorted. Sadly, she can't even do this trick without help. That's why you need to do this.

INPUT SPECIFICATION: You will be given a set of input cases, each of which will begin with an unsigned decimal integer (representing the size of the list of words, no larger than 1000) followed by<EOLN>. Then will follow the list of words, consisting only of capital letters, of length not exceeding twenty, each followed by <EOLN>. The last input case will be followed by “0<EOLN>â€.

OUTPUT SPECIFICATION: The output cases should appear in the same order as the input cases. Each output case will be of the form “Case c: You only need to remove w word(s)!†(where c is the number of the input case and w is the SMALLEST number of words that can render the rest of the list sorted by their removal) followed by <EOLN>.

SAMPLE INPUT:
5<EOLN>
OH<EOLN>
THAT<EOLN>
CAT<EOLN>
IS<EOLN>
HIGH<EOLN>
5<EOLN>
A<EOLN>
B<EOLN>
C<EOLN>
D<EOLN>
E<EOLN>
0<EOLN>
<EOF>

SAMPLE OUTPUT:
Case•1:•You•only•need•to•remove•3• word(s)!<EOLN>
Case•2:•You•only•need•to•remove•0• word(s)!<EOLN>
<EOF>

Edited by Midpipps - 6/23/11 at 11:23am
    
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 #274 of 306
C#
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Word_Remover
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            if (args.Length != 1)
                p.Go();
            else p.Go(args[0]);
            Console.ReadLine();
        }

        private void Go()
        {
            List<string[]> wordLists = new List<string[]>();
            while (true)
            {
                Console.Write("Number of words: ");
                int numWords;
                string input = Console.ReadLine();
                if (input == "")
                    break;
                if (!int.TryParse(input, out numWords))
                {
                    Console.WriteLine("Error: please enter an integer");
                    continue;
                }
                if (numWords == 0)
                    break;
                string[] words = new string[numWords];
                Console.WriteLine("Please enter words");
                for (int i = 0; i < numWords; i++)
                {
                    words[i] = Console.ReadLine();
                    if (string.IsNullOrEmpty(words[i]))
                    {
                        Console.WriteLine("You must enter a word: ");
                        i--;
                    }
                }
                wordLists.Add(words);
            }
            for(int i = 0; i < wordLists.Count; i++)
            {
                Remove(wordLists[i], i+1);
            }
        }

        private void Go(string filename)
        {
        }

        private void Remove(string[] words, int Case)
        {
            string[] sorted = (string[])words.Clone();
            Array.Sort(sorted);
            int removed = 0;
            int SP = 0, WP = 0;
            while(WP < words.Length && SP < sorted.Length)
            {
                if(words[WP] == sorted[SP])
                    SP++;
                else removed++;
                WP++;
            }
            Console.WriteLine("Case {0}: You only need to remove {1} words!", Case, removed);

        }
    }
}
It works interactively, don't really feel like finishing up the reading from file component.
    
CPUMotherboardOSMonitor
2500k P8P67 Windows 7 Ultimate x64 22" phillips 
KeyboardPowerMouseMouse Pad
Cheap Logitech Antec Earthwatts 650W Razer Deathadder Razer eXactMat 
  hide details  
    
CPUMotherboardOSMonitor
2500k P8P67 Windows 7 Ultimate x64 22" phillips 
KeyboardPowerMouseMouse Pad
Cheap Logitech Antec Earthwatts 650W Razer Deathadder Razer eXactMat 
  hide details  
post #275 of 306
I have a pretty good challenge that I would like to post. I had to do it to get my current job. Should I post it in a week when Midpipps challenge is over or get two going?
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 970 B1 EVGA X58 SLI (E758) Gigabyte GTX 970 Gaming Crucial Ballistix Tactical 12GB 
Hard DriveOSMonitorKeyboard
Intel X25-M 80GB, WD Caviar Black 1TB, WD CG 2TB Windows 7 x64 Ultimate Asus 24", ViewSonic 22" Saitek Cyborg 
PowerCaseMouseMouse Pad
CORSAIR TX850 HAF 932 Logitech G500 OCZ Behemoth 
  hide details  
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 970 B1 EVGA X58 SLI (E758) Gigabyte GTX 970 Gaming Crucial Ballistix Tactical 12GB 
Hard DriveOSMonitorKeyboard
Intel X25-M 80GB, WD Caviar Black 1TB, WD CG 2TB Windows 7 x64 Ultimate Asus 24", ViewSonic 22" Saitek Cyborg 
PowerCaseMouseMouse Pad
CORSAIR TX850 HAF 932 Logitech G500 OCZ Behemoth 
  hide details  
post #276 of 306
I think he's trying to get it going every Wednesday, so people know when to come back. If you pm him, he will probably just not put one out if you want to do yours on Wednesday.

That said.. here's my broken implementation of the last one. It removes the ones not sorted.. it doesn't end up with the longest, since ZABC would only return Z, instead of the longer sorted ABC. Just haven't had time to fix it.

Code:
val s = io.Source.fromFile("input.txt").getLines.map(x => x.trim).toList

//val s ="5<EOLN>OH<EOLN>THAT<EOLN>CAT<EOLN>IS<EOLN>HIGH<EOLN>5<EOLN>A<EOLN>B<EOLN>C<EOLN>D<EOLN>E<EOLN>0<EOLN><EOF>"
var workArray = s.toList.reverse.tail.reverse //hhah

def excludeUnordered(uo:List[String], ord:List[String]):List[String] =
{

  val filtr = uo.takeWhile{i:String => /*println("A: " + i + " B:" + ord.head);*/ i >= ord.head}
  if(filtr.length == 0) { return ord.reverse; }
  return excludeUnordered(filtr.tail, filtr.head :: ord);
}

while(workArray.nonEmpty)
{
   var toSort = workArray.tail.takeWhile{i:String => !(('0' to '9') contains (i(0).toChar))}
   workArray = workArray.drop(1 + toSort.length)
   if(toSort.nonEmpty)
   { val ordered = excludeUnordered(toSort.tail, List(toSort.head));
     println("Change is " + (toSort.length - ordered.length) );
   }
 }
post #277 of 306
C++
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;

int getint (const string &str) {
stringstream ss(str);
int n;
ss >> n;
return n;
}

int main ()
{
  int length=1,c,w,max,current;
  int* values;
  string line;
  istringstream buffer;
  ifstream in;
  ofstream out;
  in.open("prob3in.txt");
  out.open("prob3out.txt");
  while(!in.eof()&& length != 0)
  {
      c++;
      getline (in,line);
      length = getint(line);
      values = new (nothrow) int[length];
      for(int i=0;i<length;i++)
      {
          getline (in,line);
          values[i] = (int)line[0];
      }
      for(int i=0;i<length;i++)
      {
          current = values[i];
          for(int x=i;x<length;x++)
          {
              if(current<values[x])
              {
                  w++;
                  current = values[x];
              }
              if(w>max) max = w;
          }
          w=1;
      }
      max = length - max;
      out << "Case " << c << ": You only need to remove " << max << " word(s)!\
";
      delete[] values;
      max = 0;
   }
   in.close();
   out.close();
   return 0;
}
my semi working code.
right now the code looks for the longest string of sequential numbers (letters). the problem is that if there's a larger number and like three smaller ones the program ignores them since they're lower than the one we just got. so for example QWERTYUIOP is 81,87,69,82,84,89,85,73,79,80. so when looking for a string of numbers it takes 81 then 87 then ignores 69,82,84 sin they're all smaller then gets 89 and again ignores 85,73,79,80 since they're all lower than 89. now if we remove 87 then the string would be 81,82,84,89. now if there was a 86,87,88 etc.. after 85 then again we wouldn't reach those since 89 would be blocking them.
tl;dr: no idea how to solve this.
Edited by newbie1911 - 6/28/11 at 11:46am
Pepe Silvia
(13 items)
 
  
CPUMotherboardGraphicsRAM
255 @ 4 Ghz MSI 870-C45 GT 520 @ 1Ghz Crucial Rendition 4GB DDR3 
Hard DriveOSMonitorPower
Hitachi 1TB Win 7 19" 420W 
  hide details  
Pepe Silvia
(13 items)
 
  
CPUMotherboardGraphicsRAM
255 @ 4 Ghz MSI 870-C45 GT 520 @ 1Ghz Crucial Rendition 4GB DDR3 
Hard DriveOSMonitorPower
Hitachi 1TB Win 7 19" 420W 
  hide details  
post #278 of 306
Hey guys, please include what language you're using when you post the code. Like newbie1911 above should put C++ above the code block. That would be great, thanks.
post #279 of 306
Well Wednesday is here and as promised I will post this weeks challenge. As stated before this is a challenge that I was given as a test to get my current job, as such it is a scanned image rather than text like previous posts. But anyways, I will post mine in a few days after a few people post theirs.

My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 970 B1 EVGA X58 SLI (E758) Gigabyte GTX 970 Gaming Crucial Ballistix Tactical 12GB 
Hard DriveOSMonitorKeyboard
Intel X25-M 80GB, WD Caviar Black 1TB, WD CG 2TB Windows 7 x64 Ultimate Asus 24", ViewSonic 22" Saitek Cyborg 
PowerCaseMouseMouse Pad
CORSAIR TX850 HAF 932 Logitech G500 OCZ Behemoth 
  hide details  
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 970 B1 EVGA X58 SLI (E758) Gigabyte GTX 970 Gaming Crucial Ballistix Tactical 12GB 
Hard DriveOSMonitorKeyboard
Intel X25-M 80GB, WD Caviar Black 1TB, WD CG 2TB Windows 7 x64 Ultimate Asus 24", ViewSonic 22" Saitek Cyborg 
PowerCaseMouseMouse Pad
CORSAIR TX850 HAF 932 Logitech G500 OCZ Behemoth 
  hide details  
post #280 of 306
Quote:
Originally Posted by austinb324 View Post
Well Wednesday is here and as promised I will post this weeks challenge. As stated before this is a challenge that I was given as a test to get my current job, as such it is a scanned image rather than text like previous posts. But anyways, I will post mine in a few days after a few people post theirs.

http://i925.photobucket.com/albums/a...gChallenge.png
Is that current job with IBM?
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)