Topic: Christchurch Treehouse of Awesome-Where everyone knows your name

Codex

  • Guest
Tyres were worth it

Feels amazing, like when rii waxes my balls

Reply #14000 Posted: August 18, 2012, 03:15:27 pm

Offline Bounty Hunter

  • Addicted
  • Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!
  • Posts: 8,454
there's a have a go day on at ruapuna today :( trapped at uni doing dumb C assignment.

Reply #14001 Posted: August 18, 2012, 03:21:37 pm
"We are the majority we arent the tards, the people we pick on are." -Luse_K

Offline Aloysius

  • Just settled in
  • Aloysius has no influence.
  • Posts: 673
AOS <100m from my house chilling at the Challenge station on Blighs road.
mfw.
Any idea what they doing? I ceebz rubbernecking

Reply #14002 Posted: August 18, 2012, 04:32:14 pm


Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
lol Mighty Ducks Marathon.
Ice Hockey is a wierd sport.

Also I think there's something dead under my house. Front hall smells like a rotting corpse :(

Reply #14004 Posted: August 19, 2012, 01:18:06 am
Everyone needs more Bruce Campbell.

Offline Bounty Hunter

  • Addicted
  • Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!
  • Posts: 8,454
Here comes the all nighter!

Ok I have 15 hours to write a program in C (conforming to C89) that iterates over a list of words up to 1 million entries long, counting the number of times each word occurs.

then print the words that occur at least a certain number of times.

Also no memory leaks and has to execute in less than 10 seconds so no n^2 checking.

If Input is:
10 1
abracadabra
xylophone
fnurdle
abracadabra
oxcart
xylophone
aaa
zzz
fnurdle
oxcart

Output should be:
aaa: 1
abracadabra: 2
fnurdle: 2
oxcart: 2
xylophone: 2
zzz: 1

I've already started, and I'm not feeling too bad about it, should be able to crack it out by 9am.

Watch this thead for the hilarity that is sleep deprivation!

Girlfriend bringing dinner soon (keeper)

Reply #14005 Posted: August 19, 2012, 06:09:48 pm
"We are the majority we arent the tards, the people we pick on are." -Luse_K

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
Quote from: Bounty Hunter;1499319
Here comes the all nighter!

Ok I have 15 hours to write a program in C (conforming to C89) that iterates over a list of words up to 1 million entries long, counting the number of times each word occurs.

then print the words that occur at least a certain number of times.

Also no memory leaks and has to execute in less than 10 seconds so no n^2 checking.

If Input is:
10 1
abracadabra
xylophone
fnurdle
abracadabra
oxcart
xylophone
aaa
zzz
fnurdle
oxcart

Output should be:
aaa: 1
abracadabra: 2
fnurdle: 2
oxcart: 2
xylophone: 2
zzz: 1

I've already started, and I'm not feeling too bad about it, should be able to crack it out by 9am.

Watch this thead for the hilarity that is sleep deprivation!

Girlfriend bringing dinner soon (keeper)

Oh bro. I think I had that one. Not so hard, except I didn't have all the extra (time) constraints on it.

PS. C89 is the business. Anything younger is full of shit.
Pretty much 2 simple rules:
  • Declare your variables before any logic.
  • No inline comments (//)
Though to be fair though I probably couldn't do it these days, as I've become far too pussywhipped by interpreted languages that have loose type checking, so most of that shit is inbuilt.
Build a hash tree manually and you'll be fine (what most modern languages do automagically).

PPS. Such a keeper.

PPPS. Especially if she clears up afterwards too...
Last Edit: August 20, 2012, 12:03:58 am by Pyromanik

Reply #14006 Posted: August 19, 2012, 11:56:56 pm
Everyone needs more Bruce Campbell.

Offline Bounty Hunter

  • Addicted
  • Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!Bounty Hunter is awe-inspiring!
  • Posts: 8,454
Quote from: Pyromanik;1499356
Oh bro. I think I had that one. Not so hard, except I didn't have all the extra (time) constraints on it.

PS. C89 is the business. Anything younger is full of shit.
Pretty much 2 simple rules:
  • Declare your variables before any logic.
  • No inline comments (//)
Though to be fair though I probably couldn't do it these days, as I've become far too pussywhipped by interpreted languages that have loose type checking, so most of that shit is inbuilt.
Build a hash tree manually and you'll be fine (what most modern languages do automagically).

PPS. Such a keeper.

PPPS. Especially if she clears up afterwards too...

got 2 out of 2 for this question, 97.5% overall for the quiz, just waiting on style marks now

Code: [Select]
/* Questions 4 and 5 for Assignment Quiz 4 *
 * Takes a list of words from standard input and prints the number of times each word
 * appears above the given threshold.
 *
 * 20/8/2012 */


#include <stdio.h>
#include <string.h>
#include <malloc.h>


#define MAX_LINE_LENGTH 22


typedef struct word Word;


struct word {
    char *wrd;
    int count;
    Word *left;
    Word *right;
};


/*As in Lab 6, with StructExample4 the char array needs to be free'd seperately */
void freeWord(Word *wrd){
    free(wrd->wrd);
    free(wrd);
}




/* newWord is effectively the node, housing the count and the pointers to the left
 * and right
 *
 * Returns a word */
Word *newWord(const char *wrd){
   
    size_t wrdLength = strlen(wrd);
    Word *word = malloc(sizeof(Word));
    if (word != NULL && (word->wrd = malloc(wrdLength + 1)) != NULL){
        strncpy(word->wrd, wrd, wrdLength + 1);
        word->left = NULL;
        word->right = NULL;
        word->count = 1; /* If you're calling it then it exists */
    }
    return word;
}


/* insert tests whether to insert the node, or to 1 up it's existing value
 *
 * returns the top of the binary tree */
Word *insert(Word *wrd, Word *tree){

     return tree;
}


/* Reads one line, finds the newline character and clobbers it
 *
 * returns a single word */


Word *readWord(){
   
    Word *sp = NULL;
   
    int wordLength = 0;
   
    char buff[MAX_LINE_LENGTH] = {'\0'};
   
    char *cp = fgets(buff, MAX_LINE_LENGTH, stdin);
    if(cp != NULL){
        wordLength = strcspn(buff, &quot;\n&quot;);
        buff[wordLength] = '\0';
        sp = newWord(buff);


    }
    return sp;
}




/* Sets the first word in the binary tree
 *
 * returns the first word */
Word *readWords(){


    Word *first = NULL;




    Word *sp = readWord();
    while(sp != NULL){
        if(first == NULL){
            first = sp;
        }


        else{
            first = insert(sp, first);
        }
        sp = readWord();
    }
    return first;
}




/* Recursion method of printing each node, also note, half the memory is free'd up here*/
void printWords(Word *wrd, int threshold){

    }




}


/* Gathers information and makes required calls */


void processInput(){


    int wordNum = 0;
    int threshold = 0;


    scanf(&quot;%d %d\n&quot;, &wordNum, &threshold); /* WordNum not used */
   
    Word *wordList = readWords();
   
    printWords(wordList, threshold);
}


int main() {
    int allocatedBlocks = 0;
    int leakedBlocks = 0;


    allocatedBlocks = mallinfo().uordblks + mallinfo().hblkhd;
    processInput();
    leakedBlocks = mallinfo().uordblks + mallinfo().hblkhd - allocatedBlocks;
    if (leakedBlocks != 0) {
        printf(&quot;Memory leak of %d bytes detected!\n&quot;, leakedBlocks);
    }
    return 0;
}

On second thoughts, the quiz is still running for some people, so I probably shouldn't paste my solution to the internet lololol
Last Edit: August 20, 2012, 05:09:36 am by Bounty Hunter

Reply #14007 Posted: August 20, 2012, 04:27:18 am
"We are the majority we arent the tards, the people we pick on are." -Luse_K

Offline Retardobot

  • Admin Of This Place

  • Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!
  • Posts: 23,563
Took a pre-workout supp. last night.

Shit was awesome.

Except now I feel like a zombie. 3hrs sleep.

Braiiiinnnnnnnzzzzzzz.

Reply #14008 Posted: August 20, 2012, 09:06:00 am



Offline Goldo

  • Hero Member
  • Goldo has no influence.
  • Posts: 11,050

Reply #14009 Posted: August 20, 2012, 09:41:36 am

Offline Tandoori

  • Addicted
  • Tandoori is a force to reckon with.Tandoori is a force to reckon with.Tandoori is a force to reckon with.Tandoori is a force to reckon with.Tandoori is a force to reckon with.Tandoori is a force to reckon with.Tandoori is a force to reckon with.Tandoori is a force to reckon with.
  • Posts: 4,482

Reply #14010 Posted: August 20, 2012, 12:30:30 pm

Codex

  • Guest
Quote from: Retardobot;1499369
Took a pre-workout supp. last night.

Shit was awesome.

Except now I feel like a zombie. 3hrs sleep.

Braiiiinnnnnnnzzzzzzz.


Lol today heaps of people are sick from work, i've pumped up on drugs to get me through the day as I'm sick too, it's like a ghost town <_<

Reply #14011 Posted: August 20, 2012, 12:59:59 pm

Offline Apostrophe Spacemonkey

  • Fuck this title in particular.

  • Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!
  • Posts: 19,050
I've havn't been sick this year yet. Hope I can keep it going.

Lots of other people at work have been sick, but clealry I have become immortal and immune from all diseases.

Reply #14012 Posted: August 20, 2012, 01:10:56 pm

Offline Retardobot

  • Admin Of This Place

  • Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!
  • Posts: 23,563
By rights I should take a sick day, or some kind of day off.

When at my last job, in the year and a half I worked there I only took 2 sick days and 2 leave days off. And some of the weeks I was there I worked weekends. I went straight from that job to Massey.

So exhausted.

Reply #14013 Posted: August 20, 2012, 01:24:01 pm



Offline Speakman

  • Hero Member
  • Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!
  • Posts: 12,562
I finish my current job this week, get a whole week off before I start my new job.


I'll probably kill myself from boredom next week

Reply #14014 Posted: August 20, 2012, 01:53:23 pm
Quote from: Mellcor
i had kinda hope speakman had died, what a pity

Offline Emrico1

  • Hero Member
  • Emrico1 is a rising star!Emrico1 is a rising star!Emrico1 is a rising star!Emrico1 is a rising star!Emrico1 is a rising star!Emrico1 is a rising star!
  • Posts: 13,891

Reply #14015 Posted: August 20, 2012, 02:13:07 pm

Offline Retardobot

  • Admin Of This Place

  • Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!Retardobot is awe-inspiring!
  • Posts: 23,563
Quote from: Speakman;1499420
I finish my current job this week, get a whole week off before I start my new job.


I'll probably kill myself from boredom next week

Lucky slut.

Reply #14016 Posted: August 20, 2012, 02:27:34 pm



Offline Speakman

  • Hero Member
  • Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!
  • Posts: 12,562
I had originally planned to work until wednesday next week and only have two days off, but i changed my mind

Reply #14017 Posted: August 20, 2012, 02:32:14 pm
Quote from: Mellcor
i had kinda hope speakman had died, what a pity

Offline Growler

  • Hero Member
  • Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!
  • Posts: 14,590

Reply #14018 Posted: August 20, 2012, 02:35:44 pm
Think of me like Yoda,
but instead of being little and green,
I wear suits and I'm awesome.
I'm your bro - I'm Broda!

Codex

  • Guest

Reply #14019 Posted: August 20, 2012, 03:02:11 pm

Offline Speakman

  • Hero Member
  • Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!
  • Posts: 12,562

Reply #14020 Posted: August 20, 2012, 03:11:40 pm
Quote from: Mellcor
i had kinda hope speakman had died, what a pity

Offline Emrico1

  • Hero Member
  • Emrico1 is a rising star!Emrico1 is a rising star!Emrico1 is a rising star!Emrico1 is a rising star!Emrico1 is a rising star!Emrico1 is a rising star!
  • Posts: 13,891

Reply #14021 Posted: August 20, 2012, 03:20:01 pm

Offline Growler

  • Hero Member
  • Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!Growler is awe-inspiring!
  • Posts: 14,590

Reply #14022 Posted: August 20, 2012, 03:20:16 pm
Think of me like Yoda,
but instead of being little and green,
I wear suits and I'm awesome.
I'm your bro - I'm Broda!

Offline Apostrophe Spacemonkey

  • Fuck this title in particular.

  • Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!
  • Posts: 19,050
How well does it pay?


Is it per hour, or a base salary with an end of year bonus?

Reply #14023 Posted: August 20, 2012, 04:08:16 pm

Offline Speakman

  • Hero Member
  • Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!
  • Posts: 12,562
get paid at the end of each shift, plus salty bonuses

Reply #14024 Posted: August 20, 2012, 04:13:00 pm
Quote from: Mellcor
i had kinda hope speakman had died, what a pity