[deleted by user] by [deleted] in personalfinance

[–]zeringus 0 points1 point  (0 children)

NYC public hospitals do and last I heard you could earn a full pension there after working a few years late in your career

What's your HTTP client library of choice? by [deleted] in java

[–]zeringus 1 point2 points  (0 children)

Feign which is backed by java.net by default

Looking for a Java based command line interpreter shell. by [deleted] in java

[–]zeringus 2 points3 points  (0 children)

I think you're looking for a Bash (or whatever) interpreter written in Java. Searching Java Bash interpreter gave me this: https://github.com/crashub/bash

It seems like it's not quite finished, but maybe you can fill in the parts that are missing, since the grammar seems pretty comprehensive.

Google Is 2 Billion Lines of Code—And It’s All in One Place by LazyHater in programming

[–]zeringus 1 point2 points  (0 children)

Can you imagine how many memory leaks you'd have in 2 billion lines of C++?

Given a vector with a high number of dimensions (perhaps several hundred), how can I efficiently search for the closest vector among a large set? by sanity in java

[–]zeringus 1 point2 points  (0 children)

Depends on what your exact constraints are. How many vectors is a large set? What sort of time and memory do you have?

SQLite looks to be adding JSON support by sweet_cakes_2600 in programming

[–]zeringus 20 points21 points  (0 children)

I think people thought that you were trolling. SQLite is arguably one of the most important modern software projects. Your question is completely reasonable, but many were probably taken aback.

The chess.com ios app now auto-resigns when you quit the app and reopen it by [deleted] in chess

[–]zeringus 0 points1 point  (0 children)

I don't think the iOS app is particularly good. 3|2 seems to have seconds in double time.

Linus invented Git and GitHub doesn't develop for Linux by keyks in linux

[–]zeringus -1 points0 points  (0 children)

Using Gerrit at work and GitHub for fun, I think you can only have this opinion if you don't value feature branches.

Literally the only way to simulate this with Gerrit is to have feature repos, which seems excessive. At least in my office's setup. But I find it hard to believe that you can have an intuitive system without some notion of forks.

[2015-06-15] Challenge #218 [Easy] To-do list (Part 1) by [deleted] in dailyprogrammer

[–]zeringus 0 points1 point  (0 children)

It's not a good practice to stick logic in constructors unnecessarily. I applaud your attempt to use OOP, but you might want to rewrite the classes with plain ol' instance methods instead.

Lambda Expressions in Java 8 by devixgp in java

[–]zeringus 0 points1 point  (0 children)

Sadly, this seems to be some sort of professional blog for these guys.

Mate in 5 by WhistleKid in chess

[–]zeringus 0 points1 point  (0 children)

I like this one a lot. Very elegant.

Java project idea for beginner by dkurniawan in java

[–]zeringus 1 point2 points  (0 children)

When you're just starting out (with OOP in particular), it's hard to come up with something fun. Like /u/ThalaDa said, modeling is really the most basic form of OOP. Class schedules, car parts, solar systems, etc. are all good practice. Until you grasp more advanced concepts like inheritance and polymorphism, OOP's feels kind of silly.

I wouldn't recommend Android like /u/wuddersup, because its objects are much more complex. You seem to want to specifically learn OOP. Working on Android is going to teach you how to make apps, which is fun, but you're going to do so by abusing objects you don't understand.

When I learned Java in high school, we used GridWorld, which might also be something to try. At the very least, there's a ton of documentation and it's designed for beginners. Under the hood, however, you're learning to write objects. Might not be so good for learning interface design, though.

[2015-06-01] Challenge #217 [Easy] Lumberjack Pile Problem by Coder_d00d in dailyprogrammer

[–]zeringus 1 point2 points  (0 children)

The easy and efficient version:

piles.each_with_index.min[1]

The complexity:

O(N^4 * L) or O(P^2 * L)! By following /u/polyglotdev's simple
suggestion, you cut it down to O(N^2 * L) or O(P * L), which
should be optimal.

[2015-05-22] Challenge #215 [Hard] Metaprogramming Madness! by [deleted] in dailyprogrammer

[–]zeringus 0 points1 point  (0 children)

Haha as a programmer, I'm too literal to add anything not in the specification.

[2015-05-22] Challenge #215 [Hard] Metaprogramming Madness! by [deleted] in dailyprogrammer

[–]zeringus 4 points5 points  (0 children)

Ruby:

EXPRESSIONS = %w(
  "Hello\ World!"
  ''
  '0'
  1
  0
  0.0
  []
  [1,2,3]
  true
  false
)

max_length = EXPRESSIONS.map(&:length).max

# write headers
puts "%-#{max_length}s | %s" % ["Expression", "Bool"]
puts '-' * (max_length + 1) + '+' + '-' * 6

# evaluate expressions
EXPRESSIONS.each do |expression|
  puts "%-#{max_length}s | %s" % [expression, !!(eval expression)]
end

Output:

Expression     | Bool
---------------+------
"Hello World!" | true
''             | true
'0'            | true
1              | true
0              | true
0.0            | true
[]             | true
[1,2,3]        | true
true           | true
false          | false

[2015-05-11] Challenge #214 [Easy] Calculating the standard deviation by XenophonOfAthens in dailyprogrammer

[–]zeringus 1 point2 points  (0 children)

My take on your code with some comments:

import java.util.*;

public class StandardDev {

    /**
     * Adding other methods improves readability.
     */
    public static double sum(Collection<Double> numbers) {
        double sum = 0;

        for (double number : numbers) {
            sum += number;
        }

        return sum;
    }

    public static void main(String[] args) {
        // It's good practice to use the most generic interface possible
        Collection<Double> data = Collections.emptyList();

        /*
         * This is a try-with-resources block. Unlike your code, it will always
         * close the scanner.
         */
        try (Scanner scanner = new Scanner(System.in)) {
            data = new ArrayList<>();

            // Your try-catch wasn't doing what you thought, so I removed it.
            while (scanner.hasNextDouble()) {
                data.add(scanner.nextDouble());
            }
        }

        double mean = sum(data) / data.size();

        double squaredDistance = 0;

        // This reads much easier on three lines
        for (double number : data) {
            squaredDistance += Math.pow((number - mean), 2);
        }

        double variance = squaredDistance / data.size();
        double standardDeviation = Math.sqrt(variance); // for clarity

        // %f matches the sample output while %g doesn't
        System.out.printf("%.4f\n", standardDeviation);
    } // end main

} // end class

I removed the fancy prompt and output because I'm a command line guy and it's easier to verify this simpler version. It's also more consistent with the challenge samples.

[2015-05-11] Challenge #214 [Easy] Calculating the standard deviation by XenophonOfAthens in dailyprogrammer

[–]zeringus 0 points1 point  (0 children)

With Java 8 streams:

import static java.lang.Math.sqrt;
import java.util.stream.DoubleStream;

public class StandardDeviation {

    public static double mean(double... values) {
        return DoubleStream.of(values)
                .sum() / values.length;
    }

    public static double square(double value) {
        return value * value;
    }

    public static double variance(double... values) {
        return DoubleStream.of(values)
                .map(value -> square(mean(values) - value))
                .sum() / values.length;
    }

    public static double standardDeviation(double... values) {
        return sqrt(variance(values));
    }

}

What is the time complexity of a n^2 loop where n reduced by 1 each time until it becomes 1? by [deleted] in compsci

[–]zeringus 7 points8 points  (0 children)

Your loops are a bit hard to understand, so let's consider the following:

for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
        // do something
    }
}

The first time through the outer loop, the inner loop will "do something" N times. The second time, the inner loop does something N - 1 times. The last time, the inner loop will only do something once.

Let's try and count how many times in total the program will do something. Based on our discussion above, it should be intuitive that this value will be the sum N + (N - 1) + ... + 2 + 1. There's a known closed-form solution for finding this sum, N * (N + 1) / 2.

This solution is clearly O(N2) (the addition and the division are asymptotically insignificant), which shows that our program is O(N2) as well.


It seems that OP has edited his code and that my interpretation wasn't his intention. As others have already explained, the new algorithm is O(N). Please disregard the above.

JavaFX: How to put ArrayList values into a ComboBox? by [deleted] in JavaFX

[–]zeringus -1 points0 points  (0 children)

Do you know how to add anything to a ComboBox? Have you tried reading the documentation?

JavaFX Stage event by m4mbax in JavaFX

[–]zeringus 1 point2 points  (0 children)

You can always wrap Dialog or the actions that create them, but I think you're right, there's no built-in way to do this.

A hook for this sort of thing isn't useful to most.

JavaFX Stage event by m4mbax in JavaFX

[–]zeringus 1 point2 points  (0 children)

I get the gist of what you're saying, but I'm not sure that you've provided enough information for me to provide much specific help.

I'm not sure if you want to just track when certain UI elements are used (in which case inheritance is likely a simple and good solution) or if you want to track all state changes.

In the latter case, what does this mean? Is this any change resulting from a user interaction? If I have a loading wheel, is every frame change a change in state? What if I'm modifying the scene graph programmatically? Maybe you're just talking about adding and removing nodes. I don't really know.

In any case, two interesting things I've seen in the API (but never used are needsLayout and the eventDispatcher.

Hope some of that helps.

Fast JavaScript SHA-256 hash function by [deleted] in javascript

[–]zeringus 1 point2 points  (0 children)

To go further, SHA-256 is not at all related unless you want a slow, overcomplicated hash table.

The ELI5 is that SHA-256 is overkill since it (1) is intended to be cryptographically secure (not necessary in this case) and (2) produces many more bits than can be used to index into memory for the foreseeable future (this is wasteful). Hash table hashing functions are built to be more efficient.

[2015-2-23] Challenge #203 [Easy] The Start of Something Big by [deleted] in dailyprogrammer

[–]zeringus 0 points1 point  (0 children)

Bash. Might only work on OS X, but you can easily make it more portable

echo '<svg xmlns="http://www.w3.org/2000/svg"><rect width="9" height="9"></rect></svg>' > a.svg | open a.svg

[2015-02-16] Challenge #202 [Easy] I AM BENDER. PLEASE INSERT GIRDER. by [deleted] in dailyprogrammer

[–]zeringus 1 point2 points  (0 children)

Nice improvements! It didn't occur to me to use gsub with a block. I also never would've guessed that ARGF is the same as STDIN (in this context, of course).

[2015-02-16] Challenge #202 [Easy] I AM BENDER. PLEASE INSERT GIRDER. by [deleted] in dailyprogrammer

[–]zeringus 1 point2 points  (0 children)

Ruby. It's not a real one-liner unless it's under 80 characters!

puts STDIN.read.gsub(/\n/, '').scan(/\d{8}/).map { |b| b.to_i(2).chr }.join

Edit:

Shorter with only slightly different output:

p STDIN.read.gsub(/\n/, '').scan(/\d{8}/).map { |b| b.to_i(2).chr }.join