3280
-
- Posts: 22
- Joined: Wed Apr 13, 2011 12:00 am
- Location: Vila Velha
- Contact:
3280
Anyone did it in a better way?!?! SUre you did!
Hi guys, this is pretty much my first post here! Found this site yesterday, and made a lot of the challenge in some hours!
I did the RFC 2280 one like that:
On KDE Kate i replaced all spaces for break lines, and got a line by line text file, then removed all the garbage, like " / , . ; : { } and others, then put it all in lowercase, easy stuff, i made this for the other ones befores this challenge as well
Then i made this "MacGyver Oriented Program", it don't accurate count the times(as i tested it with cat wordlist | grep -c answer), but it gave the answer, that's what i needed, so i'll think why it don't give the accurate count later, or you could point it to me!
Well... here it is.. MacGyver Style C programming!
(I'm brazilian, sorry if the variables/comments don't make any sense...)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 100
#define MAXPALAVRA 99000
//alterar esses defines abaixo para o seu uso
#define ARQUIVO "wordlist" //o nome do arquivo, tem que estar na mesma pasta
#define TAMPALAVRA 9 //define o tamanho em caracteres da palavra
typedef struct
{
char palavra[SIZE];
int count;
}WORD;
void criaPalavra(WORD *novaPal, char* word)
{
strcpy(novaPal->palavra, word);
novaPal->count=0;
}
//cria uma lista com a palavra e um contador
typedef struct
{
WORD lista[MAXPALAVRA];
int len;
}LISTADEPALAVRAS;
void addPalavra(LISTADEPALAVRAS *list, WORD pal, int posi)
{
list->lista[posi] = pal;
list->len = 0;
}
void maisAparece(LISTADEPALAVRAS *list)
{
WORD atual, comparada, maisAparece;
int i = 0,
j = 0;
while (i < list->len)
{
atual = list->lista;
j = i + 1;
while(j < list->len)
{
comparada=list->lista[j];
if (!strcmp(atual.palavra,comparada.palavra))
{
list->lista[j].count++;
}
j++;
}
i++;
}
maisAparece = list->lista[0];
i = 1;
while (i < list->len)
{
atual = list->lista;
if (atual.count > maisAparece.count)
{
maisAparece = atual;
}
i++;
}
printf("%d - %s",maisAparece.count,maisAparece.palavra);
}
//cria uma lista com a lista anterior
main()
{
FILE *arquivo;
int index = 0;
LISTADEPALAVRAS listap;
arquivo=fopen(ARQUIVO,"r");
while (!feof(arquivo))
{
char lida[100] = "";
fscanf(arquivo, "%s\n", &lida);
if(strlen(lida) == TAMPALAVRA)
{
WORD pal;
criaPalavra(&pal, lida);
addPalavra(&listap, pal, index);
//printf("%d - %s\n",index, listap.lista[index].palavra);
index++;
}
}
listap.len = --index;
maisAparece(&listap);
//printf("%d",index);
}
Hi guys, this is pretty much my first post here! Found this site yesterday, and made a lot of the challenge in some hours!
I did the RFC 2280 one like that:
On KDE Kate i replaced all spaces for break lines, and got a line by line text file, then removed all the garbage, like " / , . ; : { } and others, then put it all in lowercase, easy stuff, i made this for the other ones befores this challenge as well
Then i made this "MacGyver Oriented Program", it don't accurate count the times(as i tested it with cat wordlist | grep -c answer), but it gave the answer, that's what i needed, so i'll think why it don't give the accurate count later, or you could point it to me!
Well... here it is.. MacGyver Style C programming!
(I'm brazilian, sorry if the variables/comments don't make any sense...)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 100
#define MAXPALAVRA 99000
//alterar esses defines abaixo para o seu uso
#define ARQUIVO "wordlist" //o nome do arquivo, tem que estar na mesma pasta
#define TAMPALAVRA 9 //define o tamanho em caracteres da palavra
typedef struct
{
char palavra[SIZE];
int count;
}WORD;
void criaPalavra(WORD *novaPal, char* word)
{
strcpy(novaPal->palavra, word);
novaPal->count=0;
}
//cria uma lista com a palavra e um contador
typedef struct
{
WORD lista[MAXPALAVRA];
int len;
}LISTADEPALAVRAS;
void addPalavra(LISTADEPALAVRAS *list, WORD pal, int posi)
{
list->lista[posi] = pal;
list->len = 0;
}
void maisAparece(LISTADEPALAVRAS *list)
{
WORD atual, comparada, maisAparece;
int i = 0,
j = 0;
while (i < list->len)
{
atual = list->lista;
j = i + 1;
while(j < list->len)
{
comparada=list->lista[j];
if (!strcmp(atual.palavra,comparada.palavra))
{
list->lista[j].count++;
}
j++;
}
i++;
}
maisAparece = list->lista[0];
i = 1;
while (i < list->len)
{
atual = list->lista;
if (atual.count > maisAparece.count)
{
maisAparece = atual;
}
i++;
}
printf("%d - %s",maisAparece.count,maisAparece.palavra);
}
//cria uma lista com a lista anterior
main()
{
FILE *arquivo;
int index = 0;
LISTADEPALAVRAS listap;
arquivo=fopen(ARQUIVO,"r");
while (!feof(arquivo))
{
char lida[100] = "";
fscanf(arquivo, "%s\n", &lida);
if(strlen(lida) == TAMPALAVRA)
{
WORD pal;
criaPalavra(&pal, lida);
addPalavra(&listap, pal, index);
//printf("%d - %s\n",index, listap.lista[index].palavra);
index++;
}
}
listap.len = --index;
maisAparece(&listap);
//printf("%d",index);
}
sudo apt-get a life
-
- Posts: 9
- Joined: Thu Mar 05, 2009 7:27 pm
There is always more than one way to do things Here is mine:
59.pl:
Followed by bash & co:
59.pl:
Code: Select all
#!/usr/bin/perl
open (IN,"rfc3280.txt");
my $i;
while (<IN>){
@arr = split / /, $_;
for ($i=0;$i<=scalar(@arr);$i++) {
if ($arr[$i] =~ /^\w{9}$/) {
print $arr[$i]."\n";
}
}
}
close (IN);
Code: Select all
perl 59.pl|sort|uniq -c | sort -n|tail -n1
-
- Posts: 22
- Joined: Wed Apr 13, 2011 12:00 am
- Location: Vila Velha
- Contact:
Nice, i don't know a thing of pearl, but i've seen such little codes when applyed to strings, must be a great language for those ocasions!
but very unreadable for the normal people too!
Sure i'll learn it someday!
Thanks for posting your aproach!
now i see theres a "Code" option here... perharps ill post my code again with that
but very unreadable for the normal people too!
Sure i'll learn it someday!
Thanks for posting your aproach!
now i see theres a "Code" option here... perharps ill post my code again with that
sudo apt-get a life
-
- Posts: 22
- Joined: Wed Apr 13, 2011 12:00 am
- Location: Vila Velha
- Contact:
Since i couldn't edit the first post...
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#define SIZE 100
#define MAXPALAVRA 99000
//alterar esses defines abaixo para o seu uso
#define ARQUIVO "wordlist" //o nome do arquivo, tem que estar na mesma pasta
#define TAMPALAVRA 9 //define o tamanho em caracteres da palavra
typedef struct
{
char palavra[SIZE];
int count;
}WORD;
void criaPalavra(WORD *novaPal, char* word)
{
strcpy(novaPal->palavra, word);
novaPal->count=0;
}
//cria uma lista com a palavra e um contador
typedef struct
{
WORD lista[MAXPALAVRA];
int len;
}LISTADEPALAVRAS;
void addPalavra(LISTADEPALAVRAS *list, WORD pal, int posi)
{
list->lista[posi] = pal;
list->len = 0;
}
void maisAparece(LISTADEPALAVRAS *list)
{
WORD atual, comparada, maisAparece;
int i = 0,
j = 0;
while (i < list->len)
{
atual = list->lista[i];
j = i + 1;
while(j < list->len)
{
comparada=list->lista[j];
if (!strcmp(atual.palavra,comparada.palavra))
{
list->lista[j].count++;
}
j++;
}
i++;
}
maisAparece = list->lista[0];
i = 1;
while (i < list->len)
{
atual = list->lista[i];
if (atual.count > maisAparece.count)
{
maisAparece = atual;
}
i++;
}
printf("%d - %s",maisAparece.count,maisAparece.palavra);
}
//cria uma lista com a lista anterior
main()
{
FILE *arquivo;
int index = 0;
LISTADEPALAVRAS listap;
arquivo=fopen(ARQUIVO,"r");
while (!feof(arquivo))
{
char lida[100] = "";
fscanf(arquivo, "%s\n", &lida);
if(strlen(lida) == TAMPALAVRA)
{
WORD pal;
criaPalavra(&pal, lida);
addPalavra(&listap, pal, index);
//printf("%d - %s\n",index, listap.lista[index].palavra);
index++;
}
}
listap.len = --index;
maisAparece(&listap);
//printf("%d",index);
}
sudo apt-get a life
My solution in Groovy:
I think you could improve the last 4 lines, but it works.
Code: Select all
def words = new File("rfc3280.txt").getText().split()
def wordSet = words as Set
wordSet = wordSet.findAll { w -> w.size() == 9 }
def textMap = [:]
wordSet.each { textMap.put(it, words.count(it)) }
def result = textMap.values().max()
println textMap.findAll { it.value == result }
-
- Posts: 1
- Joined: Fri May 06, 2011 7:00 am
I used this Site:
http://elmar-eigner.de/word-count.html
Then, I put the result in Excel and sorted it by length.
http://elmar-eigner.de/word-count.html
Then, I put the result in Excel and sorted it by length.
...
I finally got it, without any code
There are many way to get answer. I use a regex software and excel to find max
Hope all of you can solve it easily
There are many way to get answer. I use a regex software and excel to find max
Hope all of you can solve it easily
@Lori: it's a nice way. You're a talented man .L0RI wrote:I used this Site:
http://elmar-eigner.de/word-count.html
Then, I put the result in Excel and sorted it by length.
Go Mathematica
Commonest[
Select[StringCases[Import["http://www.ietf.org/rfc/rfc3280.txt"], WordCharacter ..], StringLength[#] == 9 &]]
Commonest[
Select[StringCases[Import["http://www.ietf.org/rfc/rfc3280.txt"], WordCharacter ..], StringLength[#] == 9 &]]
There is no spoon.
-
- Posts: 2
- Joined: Wed Feb 23, 2011 3:01 pm
Code: Select all
import java.io.*;
import org.apache.commons.lang3.StringUtils;
public class tan {
private static int words, countPrevious, countNow = 0;
private static String line, stringOfWords, mostFrequentWord = " ";
private static String[] linesplit = new String[2000];
public static void countWords() {
linesplit = line.split(" ");
for (int i = 0; i < linesplit.length; i++) {
if (linesplit[i].length() == 9) {
words++;
stringOfWords = stringOfWords + " " + linesplit[i];
}
}
}
public static void searchFrequent() {
System.out.println(stringOfWords);
String[] arrayOfWords = stringOfWords.split(" ");
for (int i = 0; i < arrayOfWords.length; i++) {
String searchword = arrayOfWords[i];
countNow = 0;
countNow = StringUtils.countMatches(stringOfWords, searchword);
if (countNow >= countPrevious) {
countPrevious = countNow;
mostFrequentWord = searchword;
System.out.println("Word: " + mostFrequentWord + " prev: "
+ countPrevious + " now: " + countNow);
}
}
}
public static void main(String[] args) {
try {
FileReader input = new FileReader(
"C:\\Users\\Daniel\\Documents\\Studie\\CODA\\Practicum\\server\\RFC.txt");
BufferedReader bufRead = new BufferedReader(input);
line = bufRead.readLine();
while (line != null) {
countWords();
line = bufRead.readLine();
}
searchFrequent();
System.out.println("This document has " + words
+ " words of nine characters long.");
System.out.println("According to this sucky program, the word "
+ mostFrequentWord + " is most frequent, ");
System.out.println("occurring " + countPrevious + " times.");
bufRead.close();
} catch (ArrayIndexOutOfBoundsException e) {
/*
* If no file was passed on the command line, this exception is
* generated. A message indicating how to the class should be called
* is displayed
*/
System.out.println("Usage: java tan filename\n");
} catch (IOException e) {
// If another exception is generated, print a stack trace
e.printStackTrace();
}
}
}
Those tiny grep and pearl programmes make me feel bad...
-
- Posts: 3
- Joined: Fri Oct 07, 2011 12:27 pm
Here my solution in python:
[/quote]
Code: Select all
text = open('rfc3280.txt').read().lower().replace('.', '').replace(',', '')
textlist = text.split()
niner_list = []
niner_dic = {}
for word in textlist:
if len(word) == 9:
niner_list.append(word)
for word in niner_list:
niner_dic[niner_list.count(word)] = word
print niner_dic[max(niner_dic.keys())]
My solution in ruby:
Code: Select all
file = File.new("rfc3280.txt", "r")
dict = Hash.new(0)
while (line = file.gets)
line.scan(/[^\w]([\w]{9})[^\w]/) { |match|
dict.store(match, dict[match].succ)
}
end
puts dict.index(dict.values.max)
file.close
Another Ruby solution:
Code: Select all
words = {}
File.open('file', 'r').readlines.each do |line|
line.split.each do |word|
if word.size == 9
if words[word]==nil
words.merge!(Hash[word=>0])
else
words[word]+=1
end
end
end
end
puts words.max_by{|k,v|v}
Code: Select all
#! python
from collection import Counter
data = open('rfc3280').read()
print Counter(i for i in data.split() if len(i)==9).most_common(1)[0][0]
-
- Posts: 1
- Joined: Mon Dec 16, 2013 4:27 pm