language-agnostic

What is the definition of a “true” multidimensional array and what languages support them?

浪子不回头ぞ 提交于 2019-12-23 08:54:05
问题 Most of the programming books I have ever read, have the following line: "X language does not support true multidimensional arrays, but you can simulate (approximate) them with arrays of arrays." Since most of my experience has been with C-based languages, i.e. C++, Java, JavaScript, php, etc., I'm not sure of what a "true" multidimensional array is. What is the definition of a true multidimensional array and what languages support it? Also, please show an example of a true multidimensional

RFC3986 - which pchars need to be percent-encoded?

谁都会走 提交于 2019-12-23 07:20:08
问题 I need to generate a href to a URI. All easy with the exception when it comes to reserved characters which need percent-encoding, e.g. link to /some/path;element should appear as <a href="/some/path%3Belement"> (I know that path;element represents a single entity). Initially I was looking for a Java library that does this but I ended up writing something myself (look below for what failed with Java, as this question isn't Java-specific ). So, RFC 3986 does suggest when NOT to encode. This

Displaying 100 Floating Cubes Using DirectX OR OpenGL

独自空忆成欢 提交于 2019-12-23 06:56:46
问题 I'd like to display 100 floating cubes using DirectX or OpenGL . I'm looking for either some sample source code, or a description of the technique. I have trouble getting more one cube to display correctly. I've combed the net for a good series of tutorials and although they talk about how to do 3D primitives, what I can't find is information on how to do large numbers of 3D primitives - cubes , spheres , pyramids , and so forth. 回答1: You say you have enough trouble getting one cube to

Displaying 100 Floating Cubes Using DirectX OR OpenGL

。_饼干妹妹 提交于 2019-12-23 06:56:15
问题 I'd like to display 100 floating cubes using DirectX or OpenGL . I'm looking for either some sample source code, or a description of the technique. I have trouble getting more one cube to display correctly. I've combed the net for a good series of tutorials and although they talk about how to do 3D primitives, what I can't find is information on how to do large numbers of 3D primitives - cubes , spheres , pyramids , and so forth. 回答1: You say you have enough trouble getting one cube to

Are fixed-width integers distributive over multiplication?

不问归期 提交于 2019-12-23 06:53:33
问题 For three n-bit signed integers a , b , and c (such as 32-bit), is it always true that a * (b + c) == (a * b) + (a * c) , taking into account integer overflow? I think this is language-independent, but if it's not, I'm specifically interested in the answer for Java. 回答1: Yes, it holds, because integer arithmetic is modulo arithmetic over finite rings. You can see some theoretical discussion here: https://math.stackexchange.com/questions/27336/associativity-commutativity-and-distributivity-of

Are fixed-width integers distributive over multiplication?

回眸只為那壹抹淺笑 提交于 2019-12-23 06:52:06
问题 For three n-bit signed integers a , b , and c (such as 32-bit), is it always true that a * (b + c) == (a * b) + (a * c) , taking into account integer overflow? I think this is language-independent, but if it's not, I'm specifically interested in the answer for Java. 回答1: Yes, it holds, because integer arithmetic is modulo arithmetic over finite rings. You can see some theoretical discussion here: https://math.stackexchange.com/questions/27336/associativity-commutativity-and-distributivity-of

2s compliment general form

ⅰ亾dé卋堺 提交于 2019-12-23 05:51:19
问题 Suppose I have a system that has integers that work in mod n . So with my integers adding one to n-1 is actually equal to zero. Suppose further that you define the twos compliment of a number to be the number when added to itself is equal to zero. That is: x + C(x) = 0 (here C(x) is the twos compliment of x) What in general should I do to get the twos compliment of x? The real problem: If x is a number in binary I could just invert all of the the bits of x and then add one to that number.

How do you write code that is both 32 bit and 64 bit compatible?

我与影子孤独终老i 提交于 2019-12-23 05:25:51
问题 What considerations do I need to make if I want my code to run correctly on both 32bit and 64bit platforms ? EDIT: What kind of areas do I need to take care in, e.g. printing strings/characters or using structures ? 回答1: Options: Code it in some language with a Virtual Machine (such as Java) Code it in .NET and don't target any specific architecture. The .NET JIT compiler will compile it for you to the right architecture before running it. 回答2: One solution would be to target a virtual

Median of large amount of numbers for each sets of given size

不羁岁月 提交于 2019-12-23 03:52:07
问题 The question is : find median of a large data(n numbers) in fixed size (k) of numbers What i thought is : maintain 2 heaps , maximum heap for numbers less than current median and minimum heap for numbers greater than current median . The main concept is to FIND the 1st element of previous set in one of the heap (depending on it is < or > current median), and replace it with the new element we encounter . Now modify such as to make |size(heap1) - size(heap2)| = 1 or 0 because median is avg. of

How can you walk through an integer range in an unpredictable order?

耗尽温柔 提交于 2019-12-23 03:42:12
问题 How can you loop over a fixed range of integers (say 100000-999999) in a difficult-to-predict order? assume the range may be large enough that it would be impractical to store every possible integer in an array or keep an array of every element you've found so far. you must hit every number in the range once and only once, and be able to tell when you've finished, i.e. there are no numbers left I.e. I'd like something more elegant than just A) pick a random number and then B) check whether it