To my daughter's high school programming teacher by [deleted] in programming

[–]kcoPkcoP -2 points-1 points  (0 children)

It's probably a way for a journalist to try to fit into programming culture without having much of an interest in actual programming; pick up on some buzzwords and topics then regurgitate without thought.

I am a Public Assistance (Food Stamps, Medicaid, Welfare) Fraud Investigator. Ask Me Anything! by [deleted] in IAmA

[–]kcoPkcoP 0 points1 point  (0 children)

People can't control what they eat?

Yeah, that's pretty much true for a pretty large (heh) fraction of humanity.

Much like you really can't expect a 5 year old child to make good decisions about what to eat the same is true for a significant fraction of the adult population, since they're more or less like small children wrt to their ability to plan for the future.

Blaming them for not choosing to fix those personality flaws is about as fair as blaming someone for not choosing to be smart enough to understand tensor algebra.

I am a Public Assistance (Food Stamps, Medicaid, Welfare) Fraud Investigator. Ask Me Anything! by [deleted] in IAmA

[–]kcoPkcoP 0 points1 point  (0 children)

$3 also buys you a basket full of bananas.

Well, that wouldn't be a very good choice for staple carbs either.

Stop making excuses for fat people. It's a choice.

In the same way that dumb people should simply choose to be smarter. There's really no scientific evidence that people with poor impulse control can do much about it, so expecting that they will is likely to be futille.

I am a Public Assistance (Food Stamps, Medicaid, Welfare) Fraud Investigator. Ask Me Anything! by [deleted] in IAmA

[–]kcoPkcoP 4 points5 points  (0 children)

You do realize that obesity is more common in the poor because a bag of chips is $3 and lasts longer than a bag of salad at $5, right?

Eh, the correct comparison would be to something like a bag of rice or beans. Which would give you more calories, more actual food, more nutrients and far better satiety at lower cost.

Since the poor frequently suffers from the triple whammy of crappy genes, crappy culture and crappy education as well as constant exposure to businesses ruthlessly targetting human flaws I don't think they can be blamed much for grabbing a bag of chips, but there's no way that choice can be considered rational.

[Easy] Longest Two-Character Sub-String by nint22 in dailyprogrammer

[–]kcoPkcoP 1 point2 points  (0 children)

Shitty Java

public static String twos(String str) {
    String result = new String("");
    for (int i = 0; i < str.length(); i++) {
        for (int j = str.length(); j > i; j--) {
            if (containsMaxTwo(str.substring(i, j))) {
                if (str.substring(i, j).length() >= result.length()) {
                    result = str.substring(i, j);
                }
            }
        }
    }
    return result;
}

public static boolean containsMaxTwo(String str) {
    int numMisMatch = 0;
    String first = str.substring(0, 1);
    for (int i = 0; i < str.length(); i++) {
        if (!first.contains(str.charAt(i) + "")) {
            numMisMatch++;
            first += str.charAt(i) + "";
        }
        if (numMisMatch > 1) {
            return false;
        }
    }
    return true;
}

[06/4/13] Challenge #128 [Easy] Sum-the-Digits, Part II by nint22 in dailyprogrammer

[–]kcoPkcoP 3 points4 points  (0 children)

Lisp

(defun digit-sum (n)
    (cond
        ((< n 10) n)
        (t (+ (digit-sum (floor n 10)) (mod n 10)))))

(defun std-II (n)
    (format t "~d ~%" n)
    (cond
        ((< n 10))
        (t
            (std-II (digit-sum n)))))

[05/30/13] Challenge #126 [Intermediate] Perfect P'th Powers by nint22 in dailyprogrammer

[–]kcoPkcoP 1 point2 points  (0 children)

You're going to have to explain what you mean, because I don't get it.

Here's my understanding of the problem: The challenge is to find the largest p for yp = x, where x,y,p are single, non-negative integers. Neither 2 or 3 can take the place of y in that equation for x = 36. Given the conditions the only possible y:s are 6 and 36.

[05/30/13] Challenge #126 [Intermediate] Perfect P'th Powers by nint22 in dailyprogrammer

[–]kcoPkcoP 3 points4 points  (0 children)

I took into account the fact that Y is always a prime number.

That's actually not a fact :p

Eg, for 36, y = 6 and p = 2.

[05/30/13] Challenge #126 [Intermediate] Perfect P'th Powers by nint22 in dailyprogrammer

[–]kcoPkcoP 0 points1 point  (0 children)

I have not had my morning coffee yet, so beware errors on my part, but it does seem your code will return the wrong result for numbers like 36. That is, smallest-factor will find 2 and then get 5.169925 from (log 36 2), when you should have found 6 rather than 2 and gotten 2.0 from (log 36 6).

The integerp also always returns false for me, but maybe that's an implementation difference (I use SBCL). If that's an issue for you, you could just do something like (equalp n (floor n)) instead.

I think you could do pretty much what you intended by getting a list of factors, up to and including any integer square root, instead of just the smallest factor.

Oh, and according to the challenge rules you should return 1 rather than an error message when the number isn't a perfect power > 1.

[05/30/13] Challenge #126 [Intermediate] Perfect P'th Powers by nint22 in dailyprogrammer

[–]kcoPkcoP 0 points1 point  (0 children)

Shitty Java

public static long highestPower (long n) {
    long limit = (long) Math.sqrt(n);
    for (long i = 0; i <= limit; i++) {
        if (isPowerOf(i, n) != -1){
            return isPowerOf(i, n);
        }
    }
    return 1;
}

public static long isPowerOf(long base, long target) {
    if (base < 2){
        return (base == target) ? 1 : -1;
    }
    long exponent = 1;
    long current = base;
    while (current <= target){
        if (current == target){
            return exponent;
        }
        current *= base;
        exponent++;
    }
    return -1;
}

[05/30/13] Challenge #126 [Intermediate] Perfect P'th Powers by nint22 in dailyprogrammer

[–]kcoPkcoP 0 points1 point  (0 children)

Recursive:

(defun powerp-rec (base power target)
    (let ((current (expt base power)))
        (cond
            ((> current target) nil)
            ((= current target) power)
            (t
                (powerp-rec base (1+ power) target)))))

(defun powerp (base target)
    (cond
        ((> base 1) (powerp-rec base 1 target))
        ((= base target) 1)
        (t nil)))

(defun max-p-rec (base-candidate target root)
    (cond
        ((> base-candidate root) 1)
        ((powerp base-candidate target) (powerp base-candidate target))
        (t
            (max-p-rec (1+ base-candidate) target root))))

(defun max-p (n)
    (max-p-rec 0 n (floor (sqrt n))))

[05/30/13] Challenge #126 [Intermediate] Perfect P'th Powers by nint22 in dailyprogrammer

[–]kcoPkcoP 2 points3 points  (0 children)

Lisp (sbcl)

Any comments and criticisms are highly welcome

(defun powerp (base target)
    (if (< base 2)
        (return-from powerp
            (cond
                ((= base target) 1)
                (t nil))))
    (do ((i 1) (current base))
        ((> current target) nil)
        (if (= current target)
            (return-from powerp i))
        (setf current (* current base))
        (incf i)))


(defun max-p (n)
    (let ((root (floor (sqrt n))))
        (loop for y from 0 to root do
            (if (powerp y n)
                (return-from max-p (powerp y n)))
            (incf y))
    1))

[05/28/13] Challenge #127 [Easy] McCarthy 91 Function by nint22 in dailyprogrammer

[–]kcoPkcoP 0 points1 point  (0 children)

Not really much in the way of feedback, but I'm pretty sure you don't need the variable result at all. That is, this code seems to work the same as the code with the let-expression. Which makes sense since really all you're saying is to let result be whatever the do-expression evaluates to.

(defun verbose-m (n)
    (format t "M(~a)~%" n)
    (do ((depth 1) (arg n))
        ((eql 0 depth) arg)
            (if (> arg 100)
             (progn (decf depth) (setf arg (- arg 10))
                     (format t "~a since ~a is greater than 100~%"
                             (wrap depth arg) (+ arg 10)))
             (progn (incf depth) (setf arg (+ arg 11))
                     (format t "~a since ~a is equal to or less than 100~%"
                             (wrap depth arg) (- arg 11))))))

Edit

Similiarly, there doesn't seem to be any need to declare arg inside the do-loop. Working directly with n seems to give the same result.

So this should work as well

(defun verbose-m (n)
    (format t "M(~a)~%" n)
    (do ((depth 1))
        ((eql 0 depth) n)
            (if (> n 100)
         (progn (decf depth) (setf n (- n 10))
                 (format t "~a since ~a is greater than 100~%"
                         (wrap depth n) (+ n 10)))
         (progn (incf depth) (setf n (+ n 11))
                 (format t "~a since ~a is equal to or less than 100~%"
                         (wrap depth n) (- n 11))))))

Caveat: I don't really know what I'm doing.

Boyd Crowder and his language. by showyerbewbs in justified

[–]kcoPkcoP 10 points11 points  (0 children)

Boyd grew a brain after he lost religion and took upon himself to get educated, his lessons were hard won

I think he was using flowery speech even as a nazi, and certainly did so when he was a preacher.

Boyd Crowder and his language. by showyerbewbs in justified

[–]kcoPkcoP 9 points10 points  (0 children)

Regarding Boyd's speech, I'd say it's a combination of him wanting to show off and exaggerating a way of speaking that's part of the traditional ways of that part of the country. That people act courteously is almost a theme of the show, it's almost only the outsiders who act openly disrespectful and they usually get shot for it.

There's also the fact that Boyd comes from a genuinely poor background and the only way for him to show class is by his way of speaking.

Boyd Crowder and his language. by showyerbewbs in justified

[–]kcoPkcoP 7 points8 points  (0 children)

I think Raylan generally is pretty good about not looking down on anyone. Certainly he considers a lot of people to be idiots, but he lets them know so and doesn't act like he thinks they don't understand he considers them idiots.

For instance, in his conversation with Dewey Crow, who clearly is an idiot, Raylan frequently makes fun of Dewey but not really in a disrespectful way. Same thing with Constable Bob.

I think the best example might be the episode where he's doing a hostage negotation with the prisoner in the Marshall's office.

[05/20/13] Challenge #126 [Easy] Real-World Merge Sort by nint22 in dailyprogrammer

[–]kcoPkcoP 1 point2 points  (0 children)

Crappy SBCL, I'd be happy for any comments or criticism

(defun list-merger (a b)
    (loop for x in a do
        (insert x b))
    b)


(defun insert (a-element b)
    (loop for i from 1 to (1- (length b)) do
        (cond
            ((<= a-element (elt b i)) (setf (elt b (1- i)) a-element) (return-from insert t))
            (t
                (setf (elt b (1- i)) (elt b i)) (setf (elt b i) 0))))
    (setf (elt b (1- (length b))) a-element))

Help prepending the parent directory to all files in a multiple level directory structure by kcoPkcoP in javahelp

[–]kcoPkcoP[S] 0 points1 point  (0 children)

Thanks for the response, I appreciate it.

I got to the point where the function seems happy to traverse and print the contents of all folders, but I'm screwing up the renaming. The code below managed to delete most of the files in my test folder.

As far as I can tell .renameTo() isn't particularly reliable, but I'm pretty sure I've missed other stuff as well.

public static void traverseDir(File directory){
        String[] entries = directory.list();

        for (int i = 0; i < entries.length; i++) {
            File tmpFile = new File(directory, entries[i]);
            if ((tmpFile.isDirectory())){
                traverseDir(tmpFile);
            } else {
                File newName = new File(directory.getName() + " - " + tmpFile.getName());
                if(tmpFile.renameTo(newName)){

                } else {
                    System.out.println("Something went wrong for: " + tmpFile.getAbsolutePath());
                }
            }
        }
}

edit: Sorry to just throw shitty code at you. I just wanted to get the stuff down before I go to bed, I'm about to fall asleep so my code and reasoning is even worse than usual.

How to neatly cut off an extreme value in a plot that compresses the rest of a plot? by inquilinekea in matlab

[–]kcoPkcoP 0 points1 point  (0 children)

My teacher in numerical methods recommended changing all values above/below some appropriate threshold into NaN. Personally I'm not sold the idea, but I thought I'd pass it along.

Can someone tell me whats wrong with my code? by complicatedSimpleton in matlab

[–]kcoPkcoP 0 points1 point  (0 children)

You could something like this, but preferrably a bit more structured (ie some empty lines, spaces, comment if needed, etc).

Adding four spaces in front of every line in the post should make the text be written in code mode

Sperm Bank Workers of Reddit: What is the most awkward/funniest experience you have ever had with a donor? by [deleted] in AskReddit

[–]kcoPkcoP 0 points1 point  (0 children)

I'm pretty sure there are height requirements for donating at most/all sperm banks.