language-agnostic

What's the correct algorithm to determine number of user-perceived-characters?

≡放荡痞女 提交于 2019-12-22 03:32:22
问题 I have the task of counting the number of perceived characters in an input. The input is a group of ints (we can think of it as an int[] ) which represents Unicode code points. java.text.BreakIterator.getCharacterInstance() is not allowed. (I mean their formula is allowed and is what I wanted, but weaving through their source code and state tables got me nowhere >.<) I was wondering what's the correct algorithm to count the number of grapheme-clusters given some code points? Initially, I'd

Any reason to use SecureZeroMemory() instead of memset() or ZeroMemory() when security is not an issue?

前提是你 提交于 2019-12-22 03:25:24
问题 This MSND article says SecureZeroMemory() is good for cases when sensitive data stored in memory for a while should be for sure overwritten as soon as possible when no longer needed. Answers to this SO question explain why this can make a difference. Now is there any sence in using SecureZeroMemory() for initializing just every memory block? For example in one project I see code like the following: ICONINFO ii; ::SecureZeroMemory(&ii, sizeof(ICONINFO)); if (::GetIconInfo(hIcon, &ii)) { //do

Calculate distance on a grid between 2 points

空扰寡人 提交于 2019-12-22 03:15:44
问题 I need to calculate the distance on a grid between 2 points. The movement allowed is horizontal and vertical as well diagonal to the next neighbor (so 45 degree rotations). So Manhattan distance is not an option. Also Euclidean distance is not an option cause then it does not move correct along the grid which can result in a to low value (as in the red line). I'm looking to get the distance as in the green line where it moves from cell to cell. It's preferred that the formula is fast. 回答1:

How can I modify .xfdl files? (Update #1)

蹲街弑〆低调 提交于 2019-12-22 01:44:56
问题 The .XFDL file extension identifies XFDL Formatted Document files. These belong to the XML-based document and template formatting standard. This format is exactly like the XML file format however, contains a level of encryption for use in secure communications. I know how to view XFDL files using a file viewer I found here. I can also modify and save these files by doing File:Save/Save As. I'd like, however, to modify these files on the fly. Any suggestions? Is this even possible? Update #1:

Minimizing the number of boxes that cover a given set of intervals

大憨熊 提交于 2019-12-22 00:25:57
问题 this is a question for the algorithms gurus out there :-) Let S be a set of intervals of the natural numbers that might overlap and b a box size. Assume that for each interval, the range is strictly less than b . I want to find the minimum set of intervals of size b (let's call it M ) so all the intervals in S are contained in the intervals of M . Trivial example: S = {[1..4], [2..7], [3..5], [8..15], [9..13]} b = 10 M = {[1..10], [8..18]} // so ([1..4], [2..7], [3..5]) are inside [1..10] and

What are your best practices when using an MVC-based web framework?

淺唱寂寞╮ 提交于 2019-12-21 22:56:01
问题 A few general questions to those who are well-versed in developing web-based applications. Question 1: How do you avoid the problem of "dependency carrying"? From what I understand, the first point of object retrieval should happen in your controller's action method. From there, you can use a variety of models, classes, services, and components that can require certain objects. How do you avoid the need to pass an object to another just because an object it uses requires it? I'd like to avoid

Regular expression which matches at least two words from a list

扶醉桌前 提交于 2019-12-21 22:21:06
问题 I have a list of words - "foo" , "bar" , "baz" - and I want to write a regexp which would match strings which contain at least 2 of them. E.g., "foo baz" should match while "ba foo z" should not. The obvious solution "(foo|bar|baz).*(foo|bar|baz)" works, but I find it unsatisfactory because it lists the words twice . What if I have 25 words instead of just 3? What if I am looking for strings which contain at least 4 given words instead of just 2? 回答1: It didn't sound like you were looking for

Algorithm: Find peak in a circle

微笑、不失礼 提交于 2019-12-21 21:39:47
问题 Given n integers, arranged in a circle, show an efficient algorithm that can find one peak. A peak is a number that is not less than the two numbers next to it. One way is to go through all the integers and check each one to see whether it is a peak. That yields O(n) time. It seems like there should be some way to divide and conquer to be more efficient though. 回答1: Here's a recursive O(log n) algorithm. Suppose we have an array of numbers, and we know that the middle number of that segment

Figuring out where to add punctuation in bad user generated content?

独自空忆成欢 提交于 2019-12-21 20:05:48
问题 Is there a way to use NLP or an existing library to add missing punctuation to bad user generated content? For example, this string: Today is Tuesday I went to work on Monday Friday was off would become: Today is Tuesday. I went to work on Monday. Friday was off. 回答1: I think this problem falls under sentence boundary disambiguation http://en.wikipedia.org/wiki/Sentence_boundary_disambiguation. I have used OpenNLP variant and was satisfied with the results. 回答2: I've played briefly with this

Generating a list of colors, blue through red, 0% through 100%

喜欢而已 提交于 2019-12-21 19:57:02
问题 I want to create a list of colors, red-yellow-green-blue, and blend into each other across a span of 100. Anyone have experience in this sort of thing? Edit: Well, RGB actually. Any language will do. I just need the algorithm. 回答1: A simple nested RGB loop would not generate your red-yellow-green-blue gradient. If that is really what you specifically want then you should know a bit about the color wheel: red | magenta__ | __yellow \|/ __/|\__ blue | green | cyan This is actually a HSV color