Jump to content


  • Content count

  • Joined

  • Last visited

Community Reputation

534 Excellent

1 Follower

About Mapa

  • Rank
    Advanced Member

Personal Information

  • Species

Instant Message

  • Discord

Recent Profile Visitors

1415 profile views
  1. General Chat/Time-Waster Thread

    Wow this place still exists. A while back I went to "phoenixed.corvidae.net" and thought the forums were gone, although I guess they might as well be at this point. I'm special.
  2. Things that you hate! v2

    These are the only two sections that exist for this class next semester. It's not even like the more reasonable times filled up -- there just... aren't any. Also have another class that's only offered nights MWF. College is gonna be a blast.
  3. Back in August, I needed an extra class to complete my schedule. I figured, then, since I like programming and am already pretty familiar with Java, that I should take AP Computer Science online! I get to have a bit of fun writing some programs on the side and get grades for them! Sounds fun, right? Not even close. For a recent assignment, I had to use merge sort to sort a list of movies by title, year, and studio, in both ascending and descending order. Looking at this, then, I decided that it would benefit me to rub a couple brain cells together and write one method to handle all of the cases, rather than writing the same god damn thing six different times to achieve essentially the same result. Of course, the actual implementation of the sorting algorithm would be basically the same, so my teacher shouldn't have any issue assessing my understanding of how the sorting algorithm works. Here is the result: /** * Sorts a list using merge sort with a comparator based on a key extraction function * @param ts List to sort * @param key Key extraction function * @param descending Whether or not to sort in descending order * @param <T> Type of list to sort * @param <U> Type of the key to be extracted -- must be Comparable * @return The sorted list */ public static <T, U extends Comparable<? super U>> T[] mergeSort(T[] ts, Function<? super T, ? extends U> key, boolean descending) { Comparator<T> comp = Comparator.comparing(key); return mergeSort(ts, descending ? comp.reversed() : comp ); } /** * Merge sort with custom comparator * @param ts The list to sort * @param comp Comparator to sort with * @param <T> Type of the list to be sorted * @return The sorted (modified) list */ public static <T> T[] mergeSort(T[] ts, Comparator<? super T> comp) { return mergeSort(ts, comp, 0, ts.length - 1); } /** * Merge sort with custom comparator (recursive call) * @param ts List to sort * @param comp Comparator to sort with * @param low The low index of the section of the list to merge sort * @param <T> Type of list that is sorted * @return A new (i.e. separate reference) sorted list */ public static <T> T[] mergeSort(T[] ts, Comparator<? super T> comp, int low, int high) { if(low == high) return ts; int mid = (high + low) / 2; mergeSort(ts, comp, low, mid); mergeSort(ts, comp, mid+1, high); merge(ts, comp, low, mid, high); return ts; } /** * Merges two sections of a list together in order base on a comparator * @param ts The list to merge * @param comp The comparator to use while merging * @param low The lower bound of the section to merge * @param mid The end of the lower section -- used to divide the list into two sections to merge * @param high The high end of the higher section * @param <T> Type of the list to merge */ public static <T> void merge(T[] ts, Comparator<? super T> comp, int low, int mid, int high) { T[] temp = Arrays.copyOf(ts, high - low + 1); int l = low; int r = mid+1; int n = 0; while(l <= mid || r <= high) { if(l > mid) { temp[n] = ts[r]; r++; } else if(r > high) { temp[n] = ts[l]; l++; } else if(comp.compare(ts[l], ts[r]) > 0) { temp[n] = ts[r]; r++; } else { temp[n] = ts[l]; l++; } n++; } System.arraycopy(temp, 0, ts, low, high-low+1); } Seems like a bit much for a relatively simple task, but here's the code that demonstrates the algorithm: System.out.println("Unsorted"); printMovies(movies); System.out.println("Title, Ascending"); printMovies(mergeSort(movies, Movie::getTitle, false)); System.out.println("Title, Descending"); printMovies(mergeSort(movies, Movie::getTitle, true)); System.out.println("Year, Ascending"); printMovies(mergeSort(movies, Movie::getYear, false)); System.out.println("Year, Descending"); printMovies(mergeSort(movies, Movie::getYear, true)); System.out.println("Studio, Ascending"); printMovies(mergeSort(movies, Movie::getStudio, false)); System.out.println("Studio, Descending"); printMovies(mergeSort(movies, Movie::getStudio, true)); The very essence of Don't Repeat Yourself philosophy. Hell, you can practically read it like it's English! Dr K's going to be thrilled to mark such beautiful code! The verdict? I don't really have to explain much for you to understand why that's completely ridiculous. The algorithm is actually nearly identical to the one taught in the lessons, except that the comparisons of elements use a generic comparator rather than using their specific comparators explicitly, so there's no doubt I've, in essence, successfully implemented merge sort as he wanted it. Now I have to go back and murder my program so I can move on in the course, because of course he's going to hold the exam passwords hostage until I "fix" my program, even though my grade is still an A by a pretty decent margin. Oh yeah, and he told me the same thing for two other assignments I completed implementing search algorithms. Contemporary education in action, folks. Being punished for being creative going above and beyond. What a waste of time.
  4. Things that you hate! v2

    One time I cut the roof of my mouth with the corner of a cheez-it. IT hurt to exist the next couple of days.
  5. Things that you hate! v2

    Coming out. There's just no easy way to do it, and both times when I came out separately to each of my parents in the past week, I just wanted to throw myself into a hole afterwards. They're not exactly okay with it, but they still support me and are not getting in my way at all, so I'm lucky for that. I just wish being gay weren't something that had to be given any special attention, and as tempting as it is to act that way, it just isn't practical in a lot of situations. Does it get any easier?
  6. Things that you hate! v2

    When I'm listening to music and doing homework but I can't focus on my homework because the music is so fucking good
  7. General Chat/Time-Waster Thread

    I got into Georgia Tech!!! I'll probably end up going to school in my home state instead if I can't get enough in scholarships, but it's still pretty exciting.
  8. ITT: Flaunt your Fabulous Fursona

    Boyfriend drew a me for Christmas and I actually can't
  9. Things that you love! v2

    I love getting lost in whatever it is I'm doing for hours on end. I just spent a good few hours trying to figure out how to set up a Minecraft server for my friends with my house's oddball network setup, and I ended up learning a bit about networking in the process. The solution is obvious in retrospect (literally just had to port forward from router 1 -> router 2 -> computer), but I honestly feel more accomplished than frustrated.
  10. The Name Change Thread

    Could I get my name changed to Mapa please? Thanks
  11. Watcha Playing, Phoenix?

    Just got Mario Odyssey and I'm loving it. The movement is a freaking blast.
  12. Me IRL

    Already on it. Thanks, FLVS Personal Fitness!
  13. hit paste

  14. Things that you hate! v2

    I was talking about something involving a friend with my dad, and when I said "his boyfriend," he stopped me right in my tracks. My dad isn't a bad person by any means, but I really thought he would be above that.
  15. Things That You Don't Understand!

    My high school's new website design. Before: After: Dear god. Tried to hide most identifying information, but yeh, you get the point. Not sure what the hell they're doing lol. It's been like this for over a month. Looks like it's been taken over by one of the freshman web design classes or something.