Mathematics desk | ||
---|---|---|
< April 25 | << Mar | April | May >> | April 27 > |
Welcome to the Wikipedia Mathematics Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
How do I convert an ordinary computer file into a non-negative Integer number. What I'm interested in is the contents of the file. The name of the file is irrelevant and need not be saved.
For example: a file with the size of 1 byte and the value of 16 can be easily be converted to the binary number 10000 which is decimal value 16.
However, I realizes that this method does not work because what if I have
A file with size of 2 bytes and with the hexadecimal value of "00 10" would not this also convert to the decimal value 16.
Clearly I must somehow also encode the size of the files in bytes as well as the actual value of the file.
What is the best way of converting an ordinary computer file to a non-negative Integer number which uses the least amount of numerical digits? 122.107.207.98 (talk) 00:36, 26 April 2009 (UTC)
Taemyr, your method is brilliant.
eh? what kind of file has the decimal representation value of 2 . It does seems to me that the range 2-255 is not being used. And the range 512-65535 is also not being used. 122.107.207.98 (talk) 10:46, 26 April 2009 (UTC)
Integer int_of_file(FILE* f) { Integer n = 0, place = 1; int c; while ((c = getc(f)) != EOF) { n += place * (c + 1); place *= 256; } return n; }
void file_of_int(FILE* f, Integer n) { while (n) { putc((n - 1) % 256, f); n = (n - 1) / 256; } }
file_of_int
. -- BenRG (talk) 11:04, 26 April 2009 (UTC)file2num.py
#!/usr/bin/python
import sys
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: file2num.py inputfile"
sys.exit()
num=0
place=1
myfile=open(sys.argv[1])
while 1:
char=myfile.read(1)
if char:
num = num + place * (ord(char) + 1)
place = place * 256
else:
break
print num
num2file.py
#!/usr/bin/python
from __future__ import division
import sys
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: num2file.py numberfile"
sys.exit()
numfile=open(sys.argv[1])
num=int(numfile.readline())
while num:
c = (num - 1) % 256
num = (num - 1) // 256
sys.stdout.write(chr(c))
122.107.207.98 (talk) 03:14, 2 May 2009 (UTC)
If A doesn't share a birthday with B and B doesn't share a birthday with C, then there's no way A can share a birthday with C. Doesn't this ruin the calculations that "prove" the unintuitive result of the birthday paradox? Also there are circular relationships with 4 people, and 5 people, and n people.. What's the actual graph look like, or at least what's the 50/50 point? .froth. (talk) 03:26, 26 April 2009 (UTC)
Our article on the Gateaux derivative defines it this way:
My question is whether anyone can confirm that this is correct, because I thought it required that t approach 0 from above, ie. t is always positive. The reason is that the influence function is considered a special Gateaux derivative, and that definitely requires that t approach from above. Thanks in advance, It's been emotional (talk) 08:35, 26 April 2009 (UTC)
Thanks, pma that's much clearer (though I'm still trying to work out if the function you gave really is discontinuous, rather than just not Frechet differentiable). I got the stuff I cut and pasted from our article Frechet derivative, which seems completely wrong. If you can confirm that for me, I'll get to work editing it, either soon or at least I'll make a note of it for when my thesis is done (I'm under the hammer at the moment). I'll add an acknowledgement of you and the ref desk for the help too. Thanks also to 76.126, because I also had the same question. It's been emotional (talk) 08:27, 27 April 2009 (UTC)
Thx, all clear now! I think I'll at least tag that page, because it does need editing - it's inconsistent with the page on Gateaux derivatives. cheers, It's been emotional (talk) 02:35, 29 April 2009 (UTC)
I am having trouble in reconciling the Pólya enumeration theorem I am reading from my book, and what is given here on wikipedia.
My book states: Suppose S is a set of n objects and G is a subgroup of the symmetric group Sn. Let PG(X) be the cycle index of G. Then the pattern inventory for the nonequivalent colorings of S under the action of G using colors y1, y2...ym is
Here a pattern inventory of the colorings of n objects using the m colors is the generating function: . The sum here runs over all vectors of nonnegative integers satisfying ; represents the number of nonequivalent colorings of the n objects where the color occurs precisely times. For example by looking at the pattern inventory of the colorings of 4 objects (beads) by 3 colors (r,g and b) and taking G=D4, we can see that as the coefficient r2gb is 2 so there are two necklaces with 4 beads possible using these three colors. I understand this fully.
The wikipedia article however seems to take a more general approach. It starts off with two sets X and Y. I assume that X stands for the 4 beads and Y the colors {r,g,b}. The colors are then accorded some weights. Then the colorings are also assigned weights. Now it defines a generating function c(t) whose coefficients are the number of colors of a particular weight. I am having difficulty in renconciling this with what I have understood from my book. Specifically it would help if someone could clarify these things to me:
Thanks--Shahab (talk) 09:44, 26 April 2009 (UTC)
I looked at the article about Hermite interpolation [1] and I tried to reproduce the example, however I could not figure out where the 28 comes from (third row, fourth column).
It's also not clear for me what the columns (after the x and f(x) values) contain. The column which starts with -8 contains the first derivative, if the values on the left are equal to the values on the left one row above then it seems to contain the derivative, but otherwise?
It would be great if u could explain this a bit, so we could edit the example and make it easier to understand.
Thx in advance!
--F7uffyBunny (talk) 18:27, 26 April 2009 (UTC)
--- http://en.wikipedia.org/wiki/Hermite_interpolation
Figured it out and updated the article —Preceding unsigned comment added by F7uffyBunny (talk • contribs) 21:06, 26 April 2009 (UTC)
Periodically in "detective stories" you get a plot involving someone faking a set of accounts or some other list of numbers and they don't meet the normal statistical usage of digits wherein 1 is much more frequent than 9. Two parts to this: (1) does this apply for item sales records where I would expect an excess of ".99" to come up since stores love this price break. (2) If the list is the sort where that analysis applies, how should you fake it from a list of random numbers wherein each digit is equally likely - no I'm not planning anything fraudulent. -- SGBailey (talk) 22:10, 26 April 2009 (UTC)