language-agnostic

Algorithm to generate a segment maze

独自空忆成欢 提交于 2019-12-30 02:20:05
问题 I want to generate a maze that looks like this: That is, it consists of paths in one direction that are then connected. I have looked for an algorithm to generate mazes like this without success. Specifically, I don't want a maze like this: because it doesn't "run" in only one direction. Also, it would be nice if the solution of this maze required the player to "backtrack" -- i.e. not just move upwards all the time. 回答1: create a random path between point A and B randomly add walls as long as

Greatest product of five consecutive digits in a 1000-digit number

拥有回忆 提交于 2019-12-29 18:19:44
问题 I am working through the problems on project Euler and am not too certain if my understanding of the question is correct. Problem 8 is as follows: Find the greatest product of five consecutive digits in the 1000-digit number. I have taken this to mean the following: I need to find any five numbers that run consecutively in the 1000 digit number and then add these up to get the total. I am assuming that the size of the numbers could be anything, i.e. 1,2,3 or 12,13,14 or 123,124,124 or 1234

Greatest product of five consecutive digits in a 1000-digit number

流过昼夜 提交于 2019-12-29 18:19:10
问题 I am working through the problems on project Euler and am not too certain if my understanding of the question is correct. Problem 8 is as follows: Find the greatest product of five consecutive digits in the 1000-digit number. I have taken this to mean the following: I need to find any five numbers that run consecutively in the 1000 digit number and then add these up to get the total. I am assuming that the size of the numbers could be anything, i.e. 1,2,3 or 12,13,14 or 123,124,124 or 1234

Extract the fields of a C struct

喜夏-厌秋 提交于 2019-12-29 17:53:07
问题 I often have to write code in other languages that interact with C structs. Most typically this involves writing Python code with the struct or ctypes modules. So I'll have a .h file full of struct definitions, and I have to manually read through them and duplicate those definitions in my Python code. This is time consuming and error-prone, and it's difficult to keep the two definitions in sync when they change frequently. Is there some tool or library in any language (doesn't have to be C or

Algorithm to create fair / evenly matched teams based on player rankings

牧云@^-^@ 提交于 2019-12-29 14:33:02
问题 I have a data set of players' skill ranking, age and sex and would like to create evenly matched teams. Teams will have the same number of players (currently 8 teams of 12 players). Teams should have the same or similar male to female ratio. Teams should have similar age curve/distribution. I would like to try this in Haskell but the choice of coding language is the least important aspect of this problem. 回答1: This is a bin packing problem, or a multi-dimensional knapsack problem. Björn B.

Algorithm to create fair / evenly matched teams based on player rankings

我与影子孤独终老i 提交于 2019-12-29 14:30:32
问题 I have a data set of players' skill ranking, age and sex and would like to create evenly matched teams. Teams will have the same number of players (currently 8 teams of 12 players). Teams should have the same or similar male to female ratio. Teams should have similar age curve/distribution. I would like to try this in Haskell but the choice of coding language is the least important aspect of this problem. 回答1: This is a bin packing problem, or a multi-dimensional knapsack problem. Björn B.

How do libraries in different programming languages handle Date & Time, Timestamps & Durations, Leapseconds & -years, DSTs & Timezones, …?

浪尽此生 提交于 2019-12-29 14:16:50
问题 Is there a standard body or a specific normative way how time-related things should be implemented in practice (like ICU for Unicode-related tasks) or is this currently a "best-effort", depending on how much effort, time and money language and library implementers want to spend? Is there a specific and complete implementation which could serve as a example for how time-related things should be handled? Which existing library would you consider as a bad, a decent or a good example? 回答1: I'll

What is the difference between bucket sort and radix sort?

早过忘川 提交于 2019-12-29 12:13:09
问题 Bucket sort and radix sort are close cousins; bucket sort goes from MSD to LSD, while radix sort can go in both "directions" (LSD or MSD). How do both algorithms work, and in particular how do they differ? 回答1: The initial pass of both RadixSort and BucketSort is exactly the same. The elements are put in buckets (or bins ) of incremental ranges (e.g. 0-10, 11-20, ... 90-100), depending on the number of digits in the largest number. In the next pass, however, BucketSort orders up these

What is the difference between bucket sort and radix sort?

不羁的心 提交于 2019-12-29 12:13:08
问题 Bucket sort and radix sort are close cousins; bucket sort goes from MSD to LSD, while radix sort can go in both "directions" (LSD or MSD). How do both algorithms work, and in particular how do they differ? 回答1: The initial pass of both RadixSort and BucketSort is exactly the same. The elements are put in buckets (or bins ) of incremental ranges (e.g. 0-10, 11-20, ... 90-100), depending on the number of digits in the largest number. In the next pass, however, BucketSort orders up these

When does Big-O notation fail?

孤者浪人 提交于 2019-12-29 11:35:13
问题 What are some examples where Big-O notation[1] fails in practice? That is to say: when will the Big-O running time of algorithms predict algorithm A to be faster than algorithm B, yet in practice algorithm B is faster when you run it? Slightly broader: when do theoretical predictions about algorithm performance mismatch observed running times? A non-Big-O prediction might be based on the average/expected number of rotations in a search tree, or the number of comparisons in a sorting algorithm