language-agnostic

How do I write a function to compare and rank many sets of boolean (true/false) answers?

帅比萌擦擦* 提交于 2021-02-08 17:02:00
问题 I've embarked on a project that is proving considerably more complicated than I'd first imagined. I'm trying to plan a system that is based around boolean (true/false) questions and answers. Users on the system can answer any questions from a large set of boolean (true/false) questions and be presented with a list showing the most similar users (in order of similarity) based on their answers. I've Googled far and wide but still not come up with much, so I was hoping somebody could point me in

How does a copying garbage collector ensure objects are not accessed while copied?

痴心易碎 提交于 2021-02-07 05:25:07
问题 On collection, the garbage collector copies all live objects into another memory space, thus discarding all garbage objects in the process. A forward pointer to the copied object in new space is installed into the 'old' version of an object to ensure the collector updates all remaining references to the object correctly and doesn't erroneously copy the same object twice. This obviously works quite well for stop-the-world-collectors. However, since pause times are long with stop-the-world,

How can I write an ISO 8601 date with a timezone but no time component

感情迁移 提交于 2021-02-06 12:56:05
问题 An ISO 8601 datetime with a timezone is formatted like this: 2018-09-07T05:28:42Z However, I need to represent some dates in my system where the precision is days, not seconds, which means that it would be an ISO 8601 calendar date. Calendar dates are formatted like this: 2018-09-07 In the Wikipedia article about the standard (I don't have access to the standard itself, as you have to pay for that privilege), there is no mention of timezone when discussing dates. It does talk about omitting

What is an efficient way to get the max concurrency in a list of tuples?

有些话、适合烂在心里 提交于 2021-02-04 20:38:30
问题 I have been trying to solve this problem in an efficient way. The problem is: Problem Statement Given a list of tuples in the form [(start1, end1), (start2, end2), (start3, end3)....(startn, endn)] where start and end are positive integers. Each tuple is to represent a time window, for example: [(1, 3), (73, 80)...] . Find the time (integer) where max concurrency occurs and get the tuples where max concurrency occurs. Constraints: start and end are integers of time and are between 0 to n For

What is an efficient way to get the max concurrency in a list of tuples?

浪子不回头ぞ 提交于 2021-02-04 20:37:05
问题 I have been trying to solve this problem in an efficient way. The problem is: Problem Statement Given a list of tuples in the form [(start1, end1), (start2, end2), (start3, end3)....(startn, endn)] where start and end are positive integers. Each tuple is to represent a time window, for example: [(1, 3), (73, 80)...] . Find the time (integer) where max concurrency occurs and get the tuples where max concurrency occurs. Constraints: start and end are integers of time and are between 0 to n For

Tarjan's strongly-connected components algorithm - why index in the back edge?

无人久伴 提交于 2021-02-04 18:08:11
问题 I'm studying Tarjan's algorithm for strongly-connected components and the way it works is clear to me. Anyway there's a line I don't understand: // Consider successors of v for each (v, w) in E do if (w.index is undefined) then // Successor w has not yet been visited; recurse on it strongconnect(w) v.lowlink := min(v.lowlink, w.lowlink) else if (w.onStack) then // Successor w is in stack S and hence in the current SCC v.lowlink := min(v.lowlink, w.index) // ************* end if end for I

Tarjan's strongly-connected components algorithm - why index in the back edge?

随声附和 提交于 2021-02-04 18:05:48
问题 I'm studying Tarjan's algorithm for strongly-connected components and the way it works is clear to me. Anyway there's a line I don't understand: // Consider successors of v for each (v, w) in E do if (w.index is undefined) then // Successor w has not yet been visited; recurse on it strongconnect(w) v.lowlink := min(v.lowlink, w.lowlink) else if (w.onStack) then // Successor w is in stack S and hence in the current SCC v.lowlink := min(v.lowlink, w.index) // ************* end if end for I

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

旧巷老猫 提交于 2021-02-04 10:17:20
问题 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 actually use this construct in the real world? Why would using it in a range be better than just using a boolean expression? For instance (0..1.0/0).include?(number) == (number >= 0) # True for all values of number => true To summarize, what I'm looking for is a

Numerical stability of point-in-triangle test with barycentric coordinates

耗尽温柔 提交于 2021-02-03 17:31:59
问题 While looking at various methods for point-in-triangle testing (2D case), I found that the method which uses barycentric coordinates is the most used one. Here is a StackOverflow answer which explains it. Why is this method the most preferred one? It probably has to do with doing less calculations, but what about numerical stability? Is this algorithm better suited than say, the "same side" technique, for cases in which the point is particularly near the border? 回答1: If you solve it: p = p0 +

Numerical stability of point-in-triangle test with barycentric coordinates

半腔热情 提交于 2021-02-03 17:30:21
问题 While looking at various methods for point-in-triangle testing (2D case), I found that the method which uses barycentric coordinates is the most used one. Here is a StackOverflow answer which explains it. Why is this method the most preferred one? It probably has to do with doing less calculations, but what about numerical stability? Is this algorithm better suited than say, the "same side" technique, for cases in which the point is particularly near the border? 回答1: If you solve it: p = p0 +