math

Arrays vs. lists in Lisp: Why are lists so much faster in the code below?

自古美人都是妖i 提交于 2021-01-27 05:50:50
问题 I got an unexpected result while solving Problem 75 in Project Euler. My code does find the correct solution, but it behaves strangely. My solution consists of traversing a Pythagorean tree (Barning's matrices) until the perimeter limit is reached, counting the numbers of times the perimeter assumed each value, and, lastly, counting the perimeter lengths that occurred only once. My admittedly untidy but functioning code is: (defparameter *barning-matrixes* '(#(1 -2 2) #(2 -1 2) #(2 -2 3) #(1

Arrays vs. lists in Lisp: Why are lists so much faster in the code below?

强颜欢笑 提交于 2021-01-27 05:49:46
问题 I got an unexpected result while solving Problem 75 in Project Euler. My code does find the correct solution, but it behaves strangely. My solution consists of traversing a Pythagorean tree (Barning's matrices) until the perimeter limit is reached, counting the numbers of times the perimeter assumed each value, and, lastly, counting the perimeter lengths that occurred only once. My admittedly untidy but functioning code is: (defparameter *barning-matrixes* '(#(1 -2 2) #(2 -1 2) #(2 -2 3) #(1

C standard regarding pointer arithmetic outside arrays

时光毁灭记忆、已成空白 提交于 2021-01-27 04:38:52
问题 I read lot of things about pointer arithmetic and undefined behavior (link, link, link, link, link). It always ends up to the same conclusion: Pointer arithmetic is well defined only on array type and between array[0] and array[array_size+1] (one element past the end is valid with regard to the C standard). My question is: Does it means that when the compiler sees a pointer arithmetic not related to any array (undefined behavior), it could emit what it want (even nothing) ? Or is it more a

C standard regarding pointer arithmetic outside arrays

 ̄綄美尐妖づ 提交于 2021-01-27 04:38:23
问题 I read lot of things about pointer arithmetic and undefined behavior (link, link, link, link, link). It always ends up to the same conclusion: Pointer arithmetic is well defined only on array type and between array[0] and array[array_size+1] (one element past the end is valid with regard to the C standard). My question is: Does it means that when the compiler sees a pointer arithmetic not related to any array (undefined behavior), it could emit what it want (even nothing) ? Or is it more a

Algo for dividing a number into (almost) equal whole numbers

南笙酒味 提交于 2021-01-26 18:03:47
问题 I have a situation where I have invoice spreadsheets incoming with single rows that span multiple months with a quantity column containing the summation of the quantity for all months spanned. In order to run month-by-month analytics, we need to split the total quantity into equal(ish) quantities across n rows where n is the number of months spanned. These numbers can be off by one or two, but the smaller the difference between each element the better. I have a rough mockup I did in python

Algo for dividing a number into (almost) equal whole numbers

蓝咒 提交于 2021-01-26 18:01:33
问题 I have a situation where I have invoice spreadsheets incoming with single rows that span multiple months with a quantity column containing the summation of the quantity for all months spanned. In order to run month-by-month analytics, we need to split the total quantity into equal(ish) quantities across n rows where n is the number of months spanned. These numbers can be off by one or two, but the smaller the difference between each element the better. I have a rough mockup I did in python

Probability of hash collision

血红的双手。 提交于 2021-01-21 11:05:24
问题 I am looking for some precise math on the likelihood of collisions for MD5, SHA1, and SHA256 based on the birthday paradox. I am looking for something like a graph that says "If you have 10^8 keys, this is the probability. If you have 10^13 keys, this is the probability and so on" I have looked at tons of articles but I am having a tough time finding something that gives me this data. (Ideal option for me would be a formula or code that calculates this for any provided hash size) 回答1: Let's

Probability of hash collision

社会主义新天地 提交于 2021-01-21 11:05:23
问题 I am looking for some precise math on the likelihood of collisions for MD5, SHA1, and SHA256 based on the birthday paradox. I am looking for something like a graph that says "If you have 10^8 keys, this is the probability. If you have 10^13 keys, this is the probability and so on" I have looked at tons of articles but I am having a tough time finding something that gives me this data. (Ideal option for me would be a formula or code that calculates this for any provided hash size) 回答1: Let's

Normalize any value in range (-inf…+inf) to (0…1). Is it possible?

北城余情 提交于 2021-01-20 18:44:15
问题 If we have concrete range of max..min value it is quite easy to normalize it to 0..1 float values, but if we don't have concrete limits? Is it possible to build universal function to have output between 0 and 1? In my mind I think it is impossible but I am not math expert. I'm searching for implementation on JavaScript or PHP, but any code on C/C++/Python/Delphi is OK to provide examples ( if there are some ) 回答1: There are many ways to do this. I'll leave out mapping -inf and +inf , which

Normalize any value in range (-inf…+inf) to (0…1). Is it possible?

吃可爱长大的小学妹 提交于 2021-01-20 18:43:42
问题 If we have concrete range of max..min value it is quite easy to normalize it to 0..1 float values, but if we don't have concrete limits? Is it possible to build universal function to have output between 0 and 1? In my mind I think it is impossible but I am not math expert. I'm searching for implementation on JavaScript or PHP, but any code on C/C++/Python/Delphi is OK to provide examples ( if there are some ) 回答1: There are many ways to do this. I'll leave out mapping -inf and +inf , which