language-agnostic

Should I unittest private/protected method

Should I unittest private/protected method Question: This is actually language agnostic. But I’ll give you context in python. I have this parent class class Mammal(object): def __init__(self): “”” do some work “”” def eat(self, food): “””Eat the food””” way_to_eat = self._eating_method() self._consume(food) def _eating_method(self): “””Template method””” def _consume(self, food): “””Template method””” Here eat is the …

Total answers: 3

Determine non-convex hull of collection of line segments

Determine non-convex hull of collection of line segments Question: I have a computational geometry problem that I feel should have a relatively simple solution, but I can’t quite figure it out. I need to determine the non-convex outline of a region defined by several line segments. I’m aware of various non-convex hull algorithms (e.g. alpha …

Total answers: 2

splitting list in chunks of balanced weight

splitting list in chunks of balanced weight Question: I need an algorithm to split a list of values into such chunks, that sum of values in every chunk is (approximately) equals (its some variation of Knapsack problem, I suppose) So, for example [1, 2, 1, 4, 10, 3, 8] => [[8, 2], [10], [1, 3, …

Total answers: 5

Code Golf: Finite-state machine!

Code Golf: Finite-state machine! Question: Finite state machine A deterministic finite state machine is a simple computation model, widely used as an introduction to automata theory in basic CS courses. It is a simple model, equivalent to regular expression, which determines of a certain input string is Accepted or Rejected. Leaving some formalities aside, A …

Total answers: 20

How can I make sense of a badly encoded message?

How can I make sense of a badly encoded message? Question: ————————— ƒGƒ‰[ ————————— ƒfƒBƒXƒvƒŒƒCƒ‚[ƒh‚ªÝ’è‚Å‚«‚Ü‚¹‚ñ. ————————— OK ————————— I get this clear error message out of Shooter’s Solitude system 4, after I feed it this version of d3drm.dll (sigh.) Here’s an hexdump for your convenience: 00000000 c6 92 66 c6 92 42 c6 92 58 …

Total answers: 3

Longest increasing subsequence

Longest increasing subsequence Question: Given an input sequence, what is the best way to find the longest (not necessarily continuous) increasing subsequence [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15] # input [1, 9, 13, 15] # an example of an increasing subsequence (not the longest) [0, …

Total answers: 13

How to generate random 'greenish' colors

How to generate random 'greenish' colors Question: Anyone have any suggestions on how to make randomized colors that are all greenish? Right now I’m generating the colors by this: color = (randint(100, 200), randint(120, 255), randint(100, 200)) That mostly works, but I get brownish colors a lot. Asked By: Echo says Reinstate Monica || Source …

Total answers: 9

Elegant ways to return multiple values from a function

Elegant ways to return multiple values from a function Question: It seems like in most mainstream programming languages, returning multiple values from a function is an extremely awkward thing. The typical solutions are to make either a struct or a plain old data class and return that, or to pass at least some of the …

Total answers: 14

In what contexts do programming languages make real use of an Infinity value?

In what contexts do programming languages make real use of an Infinity value? Question: So in Ruby there is a trick to specify infinity: 1.0/0 => Infinity I believe in Python you can do something like this float(‘inf’) These are just examples though, I’m sure most languages have infinity in some capacity. When would you …

Total answers: 24

What are "first-class" objects?

What are "first-class" objects? Question: When are objects or something else said to be "first-class" in a given programming language, and why? In what way do they differ from languages where they are not? When one says "everything is an object" (like in Python), do they indeed mean that "everything is first-class"? Asked By: Federico …

Total answers: 6