Discussion of challenges you have already solved
chiffre
Posts: 7 Joined: Fri Nov 27, 2009 2:52 pm
Post
by chiffre » Tue Dec 01, 2009 2:18 pm
This really chrashed my brain for a few hours
then i got the solution
Code: Select all
public static void main(String[] args) {
StringBuffer input = new StringBuffer();
String file = "C:\\Temp\\lorem.txt";
String eingabe;
ArrayList<Wort> array = new ArrayList<Wort>();
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String zeile = null;
while ((zeile = in.readLine()) != null) {
input.append(zeile);
}
} catch (IOException e) {
e.printStackTrace();
}
eingabe = input.toString();
StringBuffer interim = new StringBuffer();
int z = 0;
for (int a = 0; a < eingabe.length(); a++) {
if (Character.isLetter(eingabe.charAt(a))) {
interim.append(eingabe.charAt(a));
} else {
for (Wort w : array) {
if (w.getName().equals(interim.toString())) {
w.inkrement();
break;
}
z++;
}
if (z == array.size()) {
array.add(new Wort(interim.toString()));
}
z=0;
interim.delete(0, interim.length() + 1);
}
}
for (Wort w : array) {
if(w.getAnzahl()==1)
System.out.println(w.getName() + w.getAnzahl());
}
}}
teebee
Posts: 89 Joined: Mon Nov 10, 2008 3:21 pm
Location: Germany
Post
by teebee » Tue Dec 01, 2009 7:19 pm
This Perl one liner does the job:
Code: Select all
perl -ple '$x{$_}++for/(\w+)/g}{($_)=grep{$x{$_}<2}keys%x' < lorem.txt
chiffre
Posts: 7 Joined: Fri Nov 27, 2009 2:52 pm
Post
by chiffre » Tue Dec 01, 2009 7:30 pm
teebee wrote: This Perl one liner does the job:
Code: Select all
perl -ple '$x{$_}++for/(\w+)/g}{($_)=grep{$x{$_}<2}keys%x' < lorem.txt
poser
but perl looks like the perfect language for such stringsearch algorithms, isnt it?
teebee
Posts: 89 Joined: Mon Nov 10, 2008 3:21 pm
Location: Germany
Post
by teebee » Tue Dec 01, 2009 8:38 pm
LOL! Yes, it is indeed. However, it is said to be a write-only language. So, don't try to read my code.
Meelo
Posts: 9 Joined: Sat Apr 25, 2009 11:10 pm
Post
by Meelo » Thu Dec 03, 2009 11:30 pm
Not much point in writing your own at all in my opinion; why reinvent the wheel when google can give you a web page that analyzes the text for you?
tails
Posts: 191 Joined: Tue Jun 10, 2008 7:51 pm
Location: Tokyo
Post
by tails » Fri Dec 04, 2009 1:07 am
Hmm... Do you google and install every application when you can do the job with a few lines of code?
Meelo
Posts: 9 Joined: Sat Apr 25, 2009 11:10 pm
Post
by Meelo » Fri Dec 04, 2009 1:18 am
No. This one just seemed to lend itself to that though. For the whole didactic string of things, I write my own programs.
prop
Posts: 6 Joined: Tue Jun 16, 2009 4:09 pm
Post
by prop » Sat Jan 09, 2010 2:25 pm
wow yay i guessed and i got answer
(..and i know how to solve though XD)
HI!
qut
Posts: 1 Joined: Wed May 12, 2010 7:47 am
Post
by qut » Thu May 13, 2010 9:29 am
Perhaps not the shortest, but a nice solution:
from string import maketrans
text = open("lorem.txt").read()
intab = "\n.,"
outtab = " "
trantab = maketrans(intab, outtab)
text = text.translate(trantab);
worte = text.split(" ")
for w in worte:
z = text.count(w)
if z == 1:
print w+" "+str(text.count(w))
Masti6
Posts: 55 Joined: Sat May 15, 2010 12:04 pm
Location: Finland, Nurmes
Post
by Masti6 » Mon May 17, 2010 2:38 pm
http://www.wordcounter.com/
Did the trick. And so it does for many other challenges. Just checked the last word when filtered them in order of frequency.
I don't have the knowledge to make a program do this - Yet xD
Shall somone find a solution in Python, tell me asap :D
keiya
Posts: 5 Joined: Tue Jun 22, 2010 2:34 am
Post
by keiya » Tue Jun 22, 2010 6:43 am
Code: Select all
import string
lorem = '''omitted for obvious reasons'''
lorem = lorem.replace('/n',' ').replace(',',' ').replace('.',' ').replace(';',' ').upper()
loremwords = lorem.split()
wordcount = {}
for word in loremwords:
if word in wordcount:
wordcount[word] = wordcount[word] + 1
else:
wordcount[word] = 1
print [k for (k, v) in wordcount.iteritems() if v == 1]
There's probably a cleaner way to do it - I KNOW that my string of replaces up there could be cleaned up - but it works.
darthm0e
Posts: 1 Joined: Sat Jan 15, 2011 7:42 am
Post
by darthm0e » Sat Jan 15, 2011 8:42 am
i made it this way:
cat loremipsum.txt | sed 's/[^a-zA-Z]/\n/g' |sort|uniq -c| cat > list.txt
in list.txt there will be only 1 word counted as one
pedromalta
Posts: 22 Joined: Wed Apr 13, 2011 12:00 am
Location: Vila Velha
Contact:
Post
by pedromalta » Wed Apr 13, 2011 11:03 pm
Did it without programming...
Replaced all the blank spaces with a line break on kate
and then put it in alphanumeric order under openoffice.org
Then it was pretty easy to spot!
sudo apt-get a life
thewino
Posts: 5 Joined: Wed Apr 06, 2011 6:27 am
Post
by thewino » Fri Apr 15, 2011 10:56 pm
wow. i attempted with c++ but was stumped. looked online and found a site which counts words....
does anyone have a c++ solution for this so i can examine it? that would be great
pedromalta
Posts: 22 Joined: Wed Apr 13, 2011 12:00 am
Location: Vila Velha
Contact:
Post
by pedromalta » Sat Apr 16, 2011 7:20 am
I did one for the RPC 3280, wich counts the word with 9 letters that appear the most.
i guess with some tweeking it would fit this one too... but it's a terrible code, yet fast...
It's posted under the RPC 3280 on this forum
sudo apt-get a life