language-agnostic

If a word is made up of two valid words

空扰寡人 提交于 2019-12-23 03:39:34
问题 Given a dictionary find out if given word can be made by two words in dictionary. For eg. given "newspaper" you have to find if it can be made by two words. (news and paper in this case). Only thing i can think of is starting from beginning and checking if current string is a word. In this case checking n, ne, new, news..... check for the remaining part if current string is a valid word. Also how do you generalize it for k(means if a word is made up of k words) ? Any thoughts? 回答1: Starting

String length limitation for Rich Text Editor

百般思念 提交于 2019-12-23 03:13:32
问题 I'm using rich text editors (tiny_mce) pretty widely in a web application I'm developing. An issue I can't seem to get my head around is how to limit user input so that the length of generated content fits in my database field. Character counters, which I would normally use for non rich-text content, are pretty useless because the user does not see (or know or care about) the HTML being generated behind the scenes. i.e. If I limit the input to 100 characters and the user types 99 characters

Matching optional capture groups in any order

淺唱寂寞╮ 提交于 2019-12-23 03:12:24
问题 There are many situations in parsing user input where the user has the opportunity to add several optional flags to the input which should be accepted in any order. How can this be parsed with regex so that each flag will be in it's own capture group if it is present? For example: There is a required token a , and then 3 optional tokens which can come in any order b , c , and d . Some acceptable inputs would be: a a b a c a b c a c b a b c d a d b c a c d b The capture groups should always

fast thread ordering algorithm without atomic CAS

不羁的心 提交于 2019-12-23 02:54:23
问题 I am looking for an approach that will let me assign ordinal numbers 0..(N-1) to N O/S threads, such that the threads are in numeric order. That is, the thread that gets will have a lower O/S thread ID than the thread with ordinal 1. In order to carry this out, the threads communicate via a shared memory space. The memory ordering model is such that writes will be atomic (if two concurrent threads write a memory location at the same time, the result will be one or the other). The platform

fast thread ordering algorithm without atomic CAS

左心房为你撑大大i 提交于 2019-12-23 02:54:06
问题 I am looking for an approach that will let me assign ordinal numbers 0..(N-1) to N O/S threads, such that the threads are in numeric order. That is, the thread that gets will have a lower O/S thread ID than the thread with ordinal 1. In order to carry this out, the threads communicate via a shared memory space. The memory ordering model is such that writes will be atomic (if two concurrent threads write a memory location at the same time, the result will be one or the other). The platform

How to get the coordinates of the pixels inside an ellipse? (screenshot)

陌路散爱 提交于 2019-12-23 02:34:33
问题 I need to get the coordinates of all the pixels inside this particular region of an ellipse. I know the size of the grid, the center of the elipse and the vertical_radix and horizontal_radix. I searched on the math forums but couldn't find anything useful. So for the next example the grid is 26 by 26. Center of the ellipse is at (13, 7) and vertical_radix is 7 and horizontal_radix = 13. Knowing this I need the coordinates (pair of x and y) of all the grey pixels. I just need like a function

Dependency Injection with Non-Classes

♀尐吖头ヾ 提交于 2019-12-22 18:35:15
问题 I am somewhat new to Dependency Injection. I have set it up for some classes that pass in their dependencies as parameters in the constructor, but I have some constructors that take primitives like String or boolean . Obviously these need to be removed from the constructor if I am to use Dependency Injection for that class. For a case like this, what is a "best" practice? Make the constructor just take the dependencies and provide a setter method for all of the primitives that the class

Find if a string can be obtained from a matrix of characters

我是研究僧i 提交于 2019-12-22 12:36:38
问题 Given a matrix of characters and a string, find whether the string can be obtained from the matrix. From each character in the matrix, we can move up/down/right/left. For example, if the matrix[3][4] is: o f a s l l q w z o w k and the string is follow , then the function should return true. The only approach I can think of is a backtracking algorithm that searches whether the word is possible or not. Is there any other faster algorithm to approach this problem? And suppose I have a lot of

How can I eliminate left recursion in the following grammar?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 12:28:13
问题 Here's the grammar, which is supposed to describe a language of nested braces with commas as delimiters: L ::= {L} | L,L | A few more examples of strings I'd expect the grammar to accept and reject: Accept: {,{,,{,}},,{,}} {{{{}}}} {,{}} Reject: {}{} {,{}{}} {{},{} 回答1: Done by hand: L ::= { L } | { L } , | , L | ε Or, instead of just winging it we could use a more systematic approach and apply the algorithm from Wikipedia on removing immediate left recursion: L ::= { L } L 1 | L 1 L 1 ::= ε

Collision detection between ball & bricks in brick breaker game [closed]

萝らか妹 提交于 2019-12-22 12:22:53
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . How do you detect a collision between ball & bricks in a brick breaker game? 回答1: Bounding Box Collision That should get you started, and give you some terms to search for. Essentially you treat each brick as a bounding box. Based on the ball position you should be able to