Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Having trouble with an asignment
New Posts  All Forums:Forum Nav:

Having trouble with an asignment

post #1 of 14
Thread Starter 
I was wondering could anyone help me with this. We were given this asignment with no background info or lecture on this. Im not asking you for the solution but just rather with the methods to use. Im in first year computer science btw.

Here it is.

"Design, implement and demonstrate a program capable of identifying, and counting, palindromes in a file presented as input. For full marks you may limit yourself to finding palindromic words. For a stronger challenge, attempt to find palindromic phrases.

A test file will be provided to you on the day of the lab to demonstrate your system operating. It will contain words without punctuation. You will be asked to execute your system, which should process the file and output details of the count of palindromic words (and phrases if you so choose)."
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k 4.7ghz Gigabyte GA-Z68X-UD3 2x msi 6950 twin frozer 16g corsair vengance 1600mhz 
Hard DriveCoolingOSMonitor
samsung spinpoint 1tb Corsair H-80 Windows 7 64 bit samsung SA550 
KeyboardPowerCaseMouse
razer arctosa corsair TX850 Xigmatek cyborg rat5 
  hide details  
Reply
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k 4.7ghz Gigabyte GA-Z68X-UD3 2x msi 6950 twin frozer 16g corsair vengance 1600mhz 
Hard DriveCoolingOSMonitor
samsung spinpoint 1tb Corsair H-80 Windows 7 64 bit samsung SA550 
KeyboardPowerCaseMouse
razer arctosa corsair TX850 Xigmatek cyborg rat5 
  hide details  
Reply
post #2 of 14
Well that seems quiet straight forward, just don't dive right in to code, think of how to do it in pseudo code first.

So you want to put all the words in to an array (arraylist if you have cover them) and then scan through the array seeing if its a palindrome. If it is add it to and set*(or just an array list but you will have to search it every time you find a palindrome) and then tally it in another array list. might be best makeing a wrapper for it maybe, and then searching through.


Set http://download.oracle.com/javase/1..../util/Set.html
Edited by andrewmchugh - 10/18/11 at 12:27pm
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
post #3 of 14
you're going to be looking @ instances of strings being reversed then, no?

Palindromic Black Sabbath album: Live Evil
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 Asus Lappy GeForce GT520M 4096 
Hard DriveOptical DriveOSMonitor
500GB LG W7=64 ult + Slackware13.1_64 + MineOS HP w2207h 
KeyboardCaseMouse
logitech G11 Fugly, lol logitech mx518 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 Asus Lappy GeForce GT520M 4096 
Hard DriveOptical DriveOSMonitor
500GB LG W7=64 ult + Slackware13.1_64 + MineOS HP w2207h 
KeyboardCaseMouse
logitech G11 Fugly, lol logitech mx518 
  hide details  
Reply
post #4 of 14
Thread Starter 
Quote:
Originally Posted by newphase View Post
you're going to be looking @ instances of strings being reversed then, no?

Palindromic Black Sabbath album: Live Evil
Ye thats exactly what im trying to do

The thing is we are supposed to be able to demonstrate it in a lab and already have the code written and they will give us the text and it will read it and identify the words and phrases.
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k 4.7ghz Gigabyte GA-Z68X-UD3 2x msi 6950 twin frozer 16g corsair vengance 1600mhz 
Hard DriveCoolingOSMonitor
samsung spinpoint 1tb Corsair H-80 Windows 7 64 bit samsung SA550 
KeyboardPowerCaseMouse
razer arctosa corsair TX850 Xigmatek cyborg rat5 
  hide details  
Reply
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k 4.7ghz Gigabyte GA-Z68X-UD3 2x msi 6950 twin frozer 16g corsair vengance 1600mhz 
Hard DriveCoolingOSMonitor
samsung spinpoint 1tb Corsair H-80 Windows 7 64 bit samsung SA550 
KeyboardPowerCaseMouse
razer arctosa corsair TX850 Xigmatek cyborg rat5 
  hide details  
Reply
post #5 of 14
well, just make yourself a file with a few palin's and a few randoms and use it as test-input? Or am I missing something?
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 Asus Lappy GeForce GT520M 4096 
Hard DriveOptical DriveOSMonitor
500GB LG W7=64 ult + Slackware13.1_64 + MineOS HP w2207h 
KeyboardCaseMouse
logitech G11 Fugly, lol logitech mx518 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 Asus Lappy GeForce GT520M 4096 
Hard DriveOptical DriveOSMonitor
500GB LG W7=64 ult + Slackware13.1_64 + MineOS HP w2207h 
KeyboardCaseMouse
logitech G11 Fugly, lol logitech mx518 
  hide details  
Reply
post #6 of 14
Thread Starter 
Ye ok i missread the first reply so i get what your saying now. Thanks very much for your help guys. Much appreciated.
Edited by byrnetree - 10/18/11 at 12:46pm
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k 4.7ghz Gigabyte GA-Z68X-UD3 2x msi 6950 twin frozer 16g corsair vengance 1600mhz 
Hard DriveCoolingOSMonitor
samsung spinpoint 1tb Corsair H-80 Windows 7 64 bit samsung SA550 
KeyboardPowerCaseMouse
razer arctosa corsair TX850 Xigmatek cyborg rat5 
  hide details  
Reply
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600k 4.7ghz Gigabyte GA-Z68X-UD3 2x msi 6950 twin frozer 16g corsair vengance 1600mhz 
Hard DriveCoolingOSMonitor
samsung spinpoint 1tb Corsair H-80 Windows 7 64 bit samsung SA550 
KeyboardPowerCaseMouse
razer arctosa corsair TX850 Xigmatek cyborg rat5 
  hide details  
Reply
post #7 of 14
Quote:
Originally Posted by byrnetree View Post
Ye ok i missread the first reply so i get what your saying now. Thanks very much for your help guys. Much appreciated.
Yea sorry, Im really bad at explaining, been dyslexic and all
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
^3
(11 items)
 
   
CPUMotherboardGraphicsRAM
Intel Core i7 5930K  EVGA x99 Micro EVGA GTX 980 SC ACX 16GB Corsair DDR4 Vengeance LPX Black PC4-21300 
Hard DriveCoolingOSMonitor
500GB Samsung 840 EVO H105 Win 10 ASUS ROG PG279 
KeyboardPowerCase
Ducky Shine 1 MX-Red Corsair AX 860i  Fractal Design Node 804 Black 
CPUGraphicsRAMHard Drive
Core i7 @ 2.6  GT650 16GB of 1600 MHz DDR3L SDRAM 256GB SSD 
OSMonitorKeyboard
Mac OSX Lion Retina Display US layout 
  hide details  
Reply
post #8 of 14
First I would learn how to tokenize the input and save each word into an array of strings. To do this in java you would use the tokenizer, and the scanner class.

next I would first make a compare method that will check if any two strings inserted as input to the compare method are palindromes, basically checking if the two inputed strings are the same just one of then the reversed version of the other. If they are palindromes then we want to save that. The easiest way might be to have a couple public variables, one that is another array that holds all the strings which are palindromes, and another which is an integer counter which gets incremented each time the compare method proves the word to be true. Finally all you got to do is call the compare method for every possible two combinations of words within the string and check for palidromes, make sure if you input the same two words in a different order that you only count them once as they are the same palindrome. There are many ways of doing this, but if this is your first year so efficiency should not be your main focus. Maybe just a 2D for loop, but this is inefficient and you'll learn alternatives in the future if you can't figure them out yet. Finally you just want to print out your results the array that holds the palindromes and the counter value.
Edited by julabask - 10/18/11 at 1:02pm
my system
(13 items)
 
  
CPUMotherboardGraphicsRAM
intel q9450 @ 3.72 ghz evga 750i a1 ftw two evga superclocked gtx 470's in sli gskill 4gb ddr2 1200 5-5-5-15-2T 
Hard DriveOptical DriveOSMonitor
2x western digital black 1tb raid 0 random dvd-rw/cd-rw 22x which somehow uses ata windows 7 64 + linux ubuntu spectre 24inch 
PowerCase
silverstone op1000-e (1000 watts) Silverstone Raven 2 
  hide details  
Reply
my system
(13 items)
 
  
CPUMotherboardGraphicsRAM
intel q9450 @ 3.72 ghz evga 750i a1 ftw two evga superclocked gtx 470's in sli gskill 4gb ddr2 1200 5-5-5-15-2T 
Hard DriveOptical DriveOSMonitor
2x western digital black 1tb raid 0 random dvd-rw/cd-rw 22x which somehow uses ata windows 7 64 + linux ubuntu spectre 24inch 
PowerCase
silverstone op1000-e (1000 watts) Silverstone Raven 2 
  hide details  
Reply
post #9 of 14
Not being terribly gifted with programming or terribly proficient in any one language it seems that the simplest method would be a single method instead of to compile some large array of palindromes to search through with a single palindrome.

That single method being one that would take the characters of a word and swap their positions(i.e. racecar {first letter to last position second to second to last, so on and so forth}). Then to compare the new combination of letters to the old user inputted word. If there is a match you obviously have a palindrome. If not you have a word that is not a palindrome ("sack" becomes "kcas" 'kcas' != 'sack').

I'm not sure how difficult it would be to actually write and implement something like that mentioned above but it seems that it would be a more efficient way to catch every palindrome instead of just the ones you compiled into a list.
My SB Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
2500k Asus P8P67 GTX 470 4GB Gksill 1600mhz 
Hard DriveHard DriveOptical DriveCooling
Kingston SSDNow 1TB Samsung F3 Asus DVD Rom Heatkiller 3.0 CPU WaterBlock 
CoolingCoolingOSMonitor
EK GTX 470 Waterblock XSPC RX 360 Radiator Windows 7 Ultimate 64bit Acer 23" 
KeyboardPowerCaseMouse
Steelseries Shift Ultra x3 1000w HAF 932 Modded('UHAF') Razer Deathadder 
Mouse Pad
Razer ExactMat X 
  hide details  
Reply
My SB Build
(17 items)
 
  
CPUMotherboardGraphicsRAM
2500k Asus P8P67 GTX 470 4GB Gksill 1600mhz 
Hard DriveHard DriveOptical DriveCooling
Kingston SSDNow 1TB Samsung F3 Asus DVD Rom Heatkiller 3.0 CPU WaterBlock 
CoolingCoolingOSMonitor
EK GTX 470 Waterblock XSPC RX 360 Radiator Windows 7 Ultimate 64bit Acer 23" 
KeyboardPowerCaseMouse
Steelseries Shift Ultra x3 1000w HAF 932 Modded('UHAF') Razer Deathadder 
Mouse Pad
Razer ExactMat X 
  hide details  
Reply
post #10 of 14
For whatever extra marks...
Find a text file dictionnary
Use same process to find all palindromes.

Also, JCPoint has the simplest strategy, which I also thought of.
Java seems like a complicated language to use for this
Edited by dmanstasiu - 10/18/11 at 2:42pm
Feed The Dada
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7-2600k Asrock Z77e-itx MSI 7970 Samsung 30nm 8GB 
Hard DriveCoolingCoolingOS
Samsung 840 250GB SSD H100 w/ 2x SP120 Antec Kuhler 920 w/ 1x SP120 Linux Ubuntu 10.10 
PowerCaseAudioAudio
Seasonic X650 Bitfenix Prodigy E07K HFI-580 
  hide details  
Reply
Feed The Dada
(12 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7-2600k Asrock Z77e-itx MSI 7970 Samsung 30nm 8GB 
Hard DriveCoolingCoolingOS
Samsung 840 250GB SSD H100 w/ 2x SP120 Antec Kuhler 920 w/ 1x SP120 Linux Ubuntu 10.10 
PowerCaseAudioAudio
Seasonic X650 Bitfenix Prodigy E07K HFI-580 
  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 › Having trouble with an asignment