computer-science

Shortest path in a maze with health loss

杀马特。学长 韩版系。学妹 提交于 2020-01-04 09:24:09
问题 Suppose you have a dungeon, represented by a 2D matrix. You have a start point S (x1,y1) and an end point E (x2, y2). Along the way, some cells have a number in them, which subtract from your health score. Other cells are obstacles that you can't go through. You start with 5 health points, and you need to find the shortest path from S to E where you don't die on the way. I know that Dijikstra is used to find shortest paths. But in this case the shortest path might be one in which you die

Shortest path in a maze with health loss

眉间皱痕 提交于 2020-01-04 09:23:07
问题 Suppose you have a dungeon, represented by a 2D matrix. You have a start point S (x1,y1) and an end point E (x2, y2). Along the way, some cells have a number in them, which subtract from your health score. Other cells are obstacles that you can't go through. You start with 5 health points, and you need to find the shortest path from S to E where you don't die on the way. I know that Dijikstra is used to find shortest paths. But in this case the shortest path might be one in which you die

Solving a recurrence: T(n)=3T(n/2)+n

混江龙づ霸主 提交于 2020-01-04 05:52:27
问题 I need to Find the solution of the recurrence for n, a power of two if T(n)=3T(n/2)+n for n>1 and T(n)=1 otherwise. using substitution of n=2^m,S(m)=T(2^(m-1)) I can get down to: S(m)=2^m+3*2^(m-1)+3^2*2^(m-2)+⋯+3^(m-1) 2^1+3^m But I have no idea how to simply that. 回答1: These types of recurrences are most easily solved by Master Theorem for analysis of algorithms which is explained as follows: Let a be an integer greater than or equal to 1, b be a real number greater than 1, and c be a

Technique to track and detect missing data in a series (e.g. Security Log data)

孤街浪徒 提交于 2020-01-04 05:35:59
问题 I have a datastream that sends me data with an ever-increasing index (n++). It is possible for some of that data to be sent out of order, lost or otherwise need to be retransmitted. Example Assume I have a security log file that is monitored by my app. It is possible for a bad guy to suppress or prevent transmission of a few entries. I want to be alerted to this fact. Also assume that this data may be sent to the log recorder out of order. It seems this logic is everywhere I don't want to

Way to go from recursion to iteration

我只是一个虾纸丫 提交于 2020-01-03 05:55:11
问题 I've used recursion quite a lot on my many years of programming to solve simple problems, but I'm fully aware that sometimes you need iteration due to memory/speed problems. So, sometime in the very far past I went to try and find if there existed any "pattern" or text-book way of transforming a common recursion approach to iteration and found nothing. Or at least nothing that I can remember it would help. Are there general rules? Is there a "pattern"? 回答1: Usually, I replace a recursive

GCC couldn't vectorize 64-bit multiplication. Can 64-bit x 64-bit -> 128-bit widening multiplication be vectorized on AVX2?

感情迁移 提交于 2020-01-02 05:17:28
问题 I try to vectorize a CBRNG which uses 64bit widening multiplication. static __inline__ uint64_t mulhilo64(uint64_t a, uint64_t b, uint64_t* hip) { __uint128_t product = ((__uint128_t)a)*((__uint128_t)b); *hip = product>>64; return (uint64_t)product; } Is such a multiplication exists in a vectorized form in AVX2? 回答1: No. There's no 64 x 64 -> 128 bit arithmetic as a vector instruction. Nor is there a vector mulhi type instruction (high word result of multiply). [V]PMULUDQ can do 32 x 32 -> 64

Bin-packing (or knapsack?) problem

橙三吉。 提交于 2020-01-02 05:08:09
问题 I have a collection of 43 to 50 numbers ranging from 0.133 to 0.005 (but mostly on the small side). I would like to find, if possible, all combinations that have a sum between L and R, which are very close together.* The brute-force method takes 2 43 to 2 50 steps, which isn't feasible. What's a good method to use here? Edit: The combinations will be used in a calculation and discarded. (If you're writing code, you can assume they're simply output; I'll modify as needed.) The number of

Bin-packing (or knapsack?) problem

我们两清 提交于 2020-01-02 05:08:05
问题 I have a collection of 43 to 50 numbers ranging from 0.133 to 0.005 (but mostly on the small side). I would like to find, if possible, all combinations that have a sum between L and R, which are very close together.* The brute-force method takes 2 43 to 2 50 steps, which isn't feasible. What's a good method to use here? Edit: The combinations will be used in a calculation and discarded. (If you're writing code, you can assume they're simply output; I'll modify as needed.) The number of

What is the mathematical significance of “all (==1) [1,1..]” not terminating?

∥☆過路亽.° 提交于 2020-01-02 01:12:08
问题 Intuitively, I would expect the "mathematical" answer to all (==1) [1,1..] to be True because all of the elements in a list that only contains 1s are equal to 1. However I understand that "computationally", the process of evaluating the infinite list in order to check that each element does in fact equal 1 will never terminate, therefore the expression instead "evaluates" to bottom or ⊥ . I find this result counter-intuitive and a little unnerving. I think the fact that the list is an

What symbols are used after base 36

夙愿已清 提交于 2020-01-01 23:32:29
问题 Since Hex (base 16) uses 0-9A-F, and (I'm assuming here) Base 17 uses 0-9A-G and so on. What symbols are used once 0-9A-Z are all used up. 回答1: There is no standard answer for your question. "Base 36" is coincidentally convenient to talk about because: Hexadecimal conventionally uses 0-9a-f, so it's "obvious" to keep going through the alphabet. The Roman/ASCII alphabet runs out of steam at 'z'. Base 36 (regardless of how you represent it) is mildly interesting from a Mathematical perspective