Page 2 of 6 FirstFirst 1234 ... LastLast
Results 26 to 50 of 142
Like Tree22Likes

Thread: The Code Marathon.

  1. #26
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,667
    Rep Power
    5

    Re: The Code Marathon.

    I have a solution but its wayyyyyyyy to long. It involves sorting the array an then finding the middle term. (I havn't done sorting before so maybe thats why im so bad at it)

  2. #27
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by Flop21 View Post
    You are confused by 'linked lists'? Or something else? Because it's understandable if you're confused with linked lists if you haven't been taught that concept yet.

    It's a way of storing data, you point to a 'node' which stores the value and the pointer to the next node... so on until it reaches the end (points to nothing/NULL).
    yeah I haven't done Linked lists yet
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  3. #28
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by Drsoccerball View Post
    I have a solution but its wayyyyyyyy to long. It involves sorting the array an then finding the middle term. (I havn't done sorting before so maybe thats why im so bad at it)
    use a sorting algorithm
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  4. #29
    Rambling Spirit
    Join Date
    Dec 2010
    HSC
    N/A
    Gender
    Female
    Posts
    6,969
    Rep Power
    10

    Re: The Code Marathon.

    Quote Originally Posted by Drsoccerball View Post
    I have a solution but its wayyyyyyyy to long. It involves sorting the array an then finding the middle term. (I havn't done sorting before so maybe thats why im so bad at it)
    That's understandable sorting is 2nd semester work. This is a solution, however this isn't the optimal one.

  5. #30
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,667
    Rep Power
    5

    Re: The Code Marathon.

    Quote Originally Posted by leehuan View Post
    turntaker goes to UoW.
    How is this related?

  6. #31
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,667
    Rep Power
    5

    Re: The Code Marathon.

    Quote Originally Posted by SpiralFlex View Post
    That's understandable sorting is 2nd semester work. This is a solution, however this isn't the optimal one.
    Is there a simple 1st sem solution

  7. #32
    Rambling Spirit
    Join Date
    Dec 2010
    HSC
    N/A
    Gender
    Female
    Posts
    6,969
    Rep Power
    10

    Re: The Code Marathon.

    Quote Originally Posted by Drsoccerball View Post
    Is there a simple 1st sem solution
    The naive solution most 1917 student's would give would probably be sort it then take the median as you are doing. Just bare in mind in computing it is never the first solution that comes in mind that is the most efficient, you will learn this if you take further comp courses in unsw.

  8. #33
    Senior Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    990
    Rep Power
    2

    Re: The Code Marathon.

    Unless your sorting algorithm is better than O(nlogn) you're better off using Arrays#sort (in Java, at least)
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

  9. #34
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by Drsoccerball View Post
    How is this related?
    he probably implies that I may have covered sorting algorithms, which I have.
    leehuan likes this.
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  10. #35
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by KingOfActing View Post
    Unless your sorting algorithm is better than O(nlogn) you're better off using Array#sort (in Java, at least)
    yea, but I think thats kinda cheating lol (since C probably doesn't have a method that sorts)
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  11. #36
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Alright I should take a break from this since I have an exam tomorrow and I haven't really studied for it.
    But I will be back after exams
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  12. #37
    Senior Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    990
    Rep Power
    2

    Re: The Code Marathon.

    Quote Originally Posted by turntaker View Post
    yea, but I think thats kinda cheating lol (since C probably doesn't have a method that sorts)
    Why rewrite code that already exists? Besides, C has qsort that's basically the same thing
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

  13. #38
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by KingOfActing View Post
    Why rewrite code that already exists? Besides, C has qsort that's basically the same thing
    On yeah true haha
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  14. #39
    not actually a porcupine porcupinetree's Avatar
    Join Date
    Dec 2014
    HSC
    2015
    Gender
    Male
    Posts
    661
    Rep Power
    3

    Re: The Code Marathon.

    Ooooh this is a good idea for a thread
    Bachelor of Science (Advanced Mathematics) @ USYD

  15. #40
    Loquacious One Drsoccerball's Avatar
    Join Date
    May 2014
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,667
    Rep Power
    5

    Re: The Code Marathon.

    Quote Originally Posted by porcupinetree View Post
    Ooooh this is a good idea for a thread
    Waiting for the rep

  16. #41
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by Drsoccerball View Post
    Waiting for the rep
    he is shouting HSP so its ok if he doesn't rep
    ml125 likes this.
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  17. #42
    Senior Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    990
    Rep Power
    2

    Re: The Code Marathon.

    Quote Originally Posted by parad0xica View Post
    Question 2: write a program that finds the median of an unsorted array of 10 integer elements. You can generate the array however you wish, e.g. via command-line arguments, STDIN, looping.
    Java:
    Code:
    public static double median(int[] a)
    {
    	PriorityQueue<Integer> queue = new PriorityQueue<>(5);
    	for(int i : a)
    	{
    		queue.offer(i);
    		if(queue.size() > 5)
    		{
    			queue.poll();
    		}
    	}
    	return (queue.poll()+queue.poll())/2D;
    }
    Runs in O(n) complexity. Can easily be changed to any sized array by changing the 5 to depend on array size.
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

  18. #43
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by KingOfActing View Post
    Java:
    Code:
    public static double median(int[] a)
    {
    	PriorityQueue<Integer> queue = new PriorityQueue<>(5);
    	for(int i : a)
    	{
    		queue.offer(i);
    		if(queue.size() > 5)
    		{
    			queue.poll();
    		}
    	}
    	return (queue.poll()+queue.poll())/2D;
    }
    Runs in O(n) complexity. Can easily be changed to any sized array by changing the 5 to depend on array size.
    nice, neve4r seen Priority Queue before
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  19. #44
    Senior Member KingOfActing's Avatar
    Join Date
    Oct 2015
    HSC
    2016
    Gender
    Male
    Location
    Sydney
    Posts
    990
    Rep Power
    2

    Re: The Code Marathon.

    Quote Originally Posted by turntaker View Post
    nice, neve4r seen Priority Queue before
    Cheeky heapsort

    Quote Originally Posted by SpiralFlex View Post
    1. Given a linked list, find the k-th element from the end, using only ONE single pass.

    For example, 1->2->3->4->5->X, the 0th element from the end is 5, 1st element from the end is 4 etc.
    Java:
    Code:
    public static <T> T nthFromEnd(LinkedList<T> list, int n)
    {
    	if(n < 0 || n > list.size()) throw new IllegalArgumentException("Invalid value of n - " + n + " for list of size " + list.size());
    	Iterator<T> iterator = list.descendingIterator();
    	for(int i = 0; i < n; i++)
    	{
    		iterator.next();
    	}
    	return iterator.next();
    }
    Question 4: Given a sentence in the format of a String, find the vowel/total-letter ratio for each word. Your output should be given with one word per line, as a percentage rounded up to 2 decimal places. Input can consist of letters (A-Z,a-z), spaces, and these 5 punctuation symbols: (, ' ? ! . )

    Example input:
    Code:
    This is an awesome question, don't you agree?
    Expected output:
    Code:
    This 25.00%
    is 50.00%
    an 50.00%
    awesome 57.14%
    question, 50.00%
    don't 25.00%
    you 66.67%
    agree? 60.00%

    Hint: Regular expressions will make your code much easier to write but aren't necessary
    Last edited by KingOfActing; 17 Jun 2016 at 8:20 PM.
    2015 HSC
    Mathematics 2U
    2016 HSC
    Advanced English, Drama, Maths 3U, Maths 4U, Music 2, Extension Music, Chemistry, Software Design & Development
    Currently studying
    Advanced Mathematics (Hons)/Computer Science @ UNSW (2017– )

  20. #45
    New Member
    Join Date
    May 2016
    HSC
    2015
    Gender
    Male
    Posts
    12
    Rep Power
    2

    Re: The Code Marathon.

    Wow, this is AWESOME! Write a program that takes a list of numbers as input (can be a string of space or comma separated ints entered by user or can be a file), converts the input into an array (or linked list depending on language) of numbers (must also deal with negative numbers) and outputs which number is the most recurring. If there are no recurring numbers, i.e. all unique numbers, then the output should be the maximum number.

    Examples:

    If input is "1 2 -21 3 3 7 7 7 3 7 7 -123 7 7 9 -7" then the output should be 7.
    If the input is "1 -123 7 2 8 -2 9 4 5 6 3 -7" then the output should be 9.
    If input is "" output should be an error message.
    Last edited by UNSWStudent; 16 Jun 2016 at 5:48 AM.

  21. #46
    Executive Member Rhinoz8142's Avatar
    Join Date
    Jul 2013
    HSC
    2014
    Uni Grad
    2018
    Gender
    Male
    Location
    Sydney
    Posts
    1,355
    Rep Power
    4

    Re: The Code Marathon.

    Isn't there two ways to sort array of numbers; Bubble and Selection ?

    Quote Originally Posted by Oer View Post
    I am grateful for Rhino's existence

  22. #47
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by Rhinoz8142 View Post
    Isn't there two ways to sort array of numbers; Bubble and Selection ?
    There is bucket as well lol
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  23. #48
    Executive Member Rhinoz8142's Avatar
    Join Date
    Jul 2013
    HSC
    2014
    Uni Grad
    2018
    Gender
    Male
    Location
    Sydney
    Posts
    1,355
    Rep Power
    4

    Re: The Code Marathon.

    I hope I learn something here, being an IT student I kinda suck at coding lel.

    Quote Originally Posted by Oer View Post
    I am grateful for Rhino's existence

  24. #49
    Loquacious One turntaker's Avatar
    Join Date
    May 2013
    HSC
    2015
    Gender
    Undisclosed
    Posts
    3,961
    Rep Power
    6

    Re: The Code Marathon.

    Quote Originally Posted by Rhinoz8142 View Post
    I hope I learn something here, being an IT student I kinda suck at coding lel.
    you should try the first challenge
    "I have crippling depression" -Mahatma Gandhi
    Quote Originally Posted by Katsumi View Post
    lol

  25. #50
    Executive Member Rhinoz8142's Avatar
    Join Date
    Jul 2013
    HSC
    2014
    Uni Grad
    2018
    Gender
    Male
    Location
    Sydney
    Posts
    1,355
    Rep Power
    4

    Re: The Code Marathon.

    nah

    Quote Originally Posted by Oer View Post
    I am grateful for Rhino's existence

Page 2 of 6 FirstFirst 1234 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •