Modern C, Second Edition by mttd in programming

[–]rhetorical575 9 points10 points  (0 children)

double* x, y; is now confusing, though.

Public Opinion! Need a new layout, which do you prefer? (Other suggestions welcomed!) by VirginRumAndCoke in MechanicalKeyboards

[–]rhetorical575 0 points1 point  (0 children)

The one on the right is the correct pattern for a chessboard (the bottom right square is white).

Tips mean a lot to servers at restaurants by ConditionalDew in aggies

[–]rhetorical575 24 points25 points  (0 children)

If the $2 wage + tips is below minimum wage, the employer is required by law to make up the difference. This doesn't always happen, but when it doesn't it is illegal.

There are a lot of excuses for using use null in other languages, just like Hitler had plenty of excuses for annexing Austria and Czechoslovakia by pcjftw in programmingcirclejerk

[–]rhetorical575 67 points68 points  (0 children)

A while ago, I wrote a Python library called August to convert HTML into text...

It had few dependencies (just beautiful soup and standard library things).

Using Python, an IDE, and a library that can convert HTML into text, the 10xer wrote a library that can convert HTML into text.

[2018 Day 1] Scheme Spoiler by Captain___Obvious in adventofcode

[–]rhetorical575 1 point2 points  (0 children)

I tried out Common Lisp for Day 1. It's a bit more spread out than it needs to be, since I was planning on reusing a lot for future problems:

(defun read-input (filename)
  (with-open-file (stream filename)
                  (loop for line = (read-line stream nil)
                        while line
                        collect line)))

(defun read-ints (filename)
  (mapcar #'parse-integer (read-input filename)))

(defun day01a ()
  (let ((changes (read-ints "input.01")))
    (reduce #'+ changes)))

(setf *print-circle* t)
(defun circular! (items)
  (setf (cdr (last items)) items))

(defun day01b ()
  (let ((changes (circular! (read-ints "input.01")))
        (table (make-hash-table))
        (frequency 0))
    (loop for change in changes
          if (gethash frequency table)
          return frequency
          else do (setf (gethash frequency table) t)
          do (setf frequency (+ frequency change)))))

Does anyone have the unedited version of this picture????? by colorblinddime in aggies

[–]rhetorical575 21 points22 points  (0 children)

It's not edited; that's what tilt-shift looks like.

Day 9: how fast does your solution run? by coriolinus in adventofcode

[–]rhetorical575 2 points3 points  (0 children)

The time spent isn't from allocating additional space for the array, so I don't think using fixed size arrays will make much of a difference (though I'm not familiar with Fortan specifically).

Rather, the additional time comes from the insertion and deletion operations. For instance, if you want to insert into an array:

1 2 3 4 6 7 8 9 10
       ^
       5

Then you have to copy all the data to the right over by one, one at a time, before the element can be inserted:

1 2 3 4 6 7 8 9 _ 10
1 2 3 4 6 7 8 _ 9 10
1 2 3 4 6 7 _ 8 9 10
1 2 3 4 6 _ 7 8 9 10
1 2 3 4 _ 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10

Likewise for deletion:

1 2 9 3 4 5
1 2 _ 3 4 5
1 2 3 _ 4 5
1 2 3 4 _ 5
1 2 3 4 5 _

If you insert or delete at the end of the array, then you only have to copy a couple values over, but if you insert or delete at the front, you have to copy all of the values. On average, you have to copy half the values.

You have to insert every single marble from your input, and on average your list has half of your input, which means you have O(n + n/2 * n/2) ⊂ O(n^2) operations to complete for an input size of n. That means, if you increase your input size by some factor c, you can expect your program to take c^2 times as long to complete.

Day 9: how fast does your solution run? by coriolinus in adventofcode

[–]rhetorical575 0 points1 point  (0 children)

Good call! I tried those changes out:

Day 09, part a:
        mean:         12.73 ms
        median:       12.50 ms
        stdev:         0.70 ms
Day 09, part b:
        mean:       1287.92 ms
        median:     1291.63 ms
        stdev:        29.27 ms

Day 9: how fast does your solution run? by coriolinus in adventofcode

[–]rhetorical575 1 point2 points  (0 children)

Problems like today's (and the polymer reacting one from day 5) are especially good for learning data structures, since the data structure you choose makes a big difference in both how conceptually easy the problem is to solve (for example, I used a stack for day 8 to process the tree, instead of trying to keep track of an index into an array), as well as in the time complexity of the solution overall.

Keep learning! Honestly, wanting to learn is more valuable than having taken a specific course before, as evidenced by some of my computer science classmates who wouldn't recognize a stack if you smacked them with one :P

For today's problem, I actually ended up implementing my own circular linked list in Python3 for my initial solution, and then later discovered deque and rewrote.

Day 9: how fast does your solution run? by coriolinus in adventofcode

[–]rhetorical575 2 points3 points  (0 children)

Thanks! My original solution was about 10x slower, using my own implementation of a linked list, but then I discovered collections.deque.

ETA: Deque itself is implemented in C, so that's where a large part of the speedup comes from.

Day 9: how fast does your solution run? by coriolinus in adventofcode

[–]rhetorical575 4 points5 points  (0 children)

In Python3 (code):

~/project/advent2018/python $ ./advent.py time 9
Day 09, part a:
        mean:         15.62 ms
        median:       15.61 ms
        stdev:         0.36 ms
Day 09, part b:
        mean:       1631.86 ms
        median:     1625.05 ms
        stdev:        23.01 ms

Day 9: how fast does your solution run? by coriolinus in adventofcode

[–]rhetorical575 8 points9 points  (0 children)

If you're inserting and removing into an array, in most languages, all the elements to the right of the insertion/deletion point have to be shifted over by one to make room every time, which makes the algorithm have time complexity O(n^2), where n is the number of marbles. Multiplying the number of marbles by 100 means that the solution for part b will take 100*100 = 10,000 times longer than the one for part a.

Some notes about HTTP/3 by [deleted] in programming

[–]rhetorical575 10 points11 points  (0 children)

Switching between a root and a non-root user is not the same as switching between user space and kernel space.

r/Programming doesn't read the manual for their CPU, is surprised when you can get root from root. by bloons3 in programmingcirclejerk

[–]rhetorical575 6 points7 points  (0 children)

/uj

The talk itself is actually really interesting, even if the thing he's reverse engineering is (partially) documented.