Are you over 18 and want to see adult content?
More Annotations
A complete backup of chickenscrawlings.tumblr.com
Are you over 18 and want to see adult content?
A complete backup of irecruitersafrica.com
Are you over 18 and want to see adult content?
A complete backup of techiesindiainc.com
Are you over 18 and want to see adult content?
A complete backup of wildeyereleasing.com
Are you over 18 and want to see adult content?
A complete backup of outofsightlitterbox.com
Are you over 18 and want to see adult content?
A complete backup of musicteachershelper.com
Are you over 18 and want to see adult content?
Favourite Annotations
Złota Proporcja, blog o podróżach i kuchniach świata - Food & travel blog zlotapropocja.pl
Are you over 18 and want to see adult content?
Abog. Luis Marcano – Abogado Penalista en Caracas, Venezuela
Are you over 18 and want to see adult content?
מלון רוטשילד - מלון בוטיק יוקרתי בלב תל אביב
Are you over 18 and want to see adult content?
Romantic library that will take your breath away - Sign up!
Are you over 18 and want to see adult content?
Serano Catering – Υπηρεσίες Catering στην Θεσσαλονίκη
Are you over 18 and want to see adult content?
Text
PROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should returnCURIOUS NUMBERS
Here’s another way of directly calculating curious numbers: k-digit A is curious if A*A = A mod 10ᵏ, ie. A*A-A = A* (A-1) = X*10ᵏ = X*5ᵏ*2ᵏ for some X. A and A-1 must be co-prime so 5ᵏ must divide one and 2ᵏ must divide the other, which means that A satisfies: A mod 5ᵏ = 0 and A mod 2ᵏ = 1. or: POTHOLES | PROGRAMMING PRAXIS Potholes are marked with an “X” in the road, and also count as 1 unit of length. The task is to take a road of length N and fix all potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Your task is to write a program that takes a string representing a road and returnsthe
BABY STEPS, GIANT STEPS In a previous exercise we discussed the discrete logarithm problem, which is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; the modulus m is usually taken as prime. Today we look at an algorithm, known as baby steps, giant steps, that was developed by Daniel Shanks in 1971: 1. Compute limits: b = ⌈ √m ⌉. h = (x −1) b. 2. Construct liHOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
POLLARD’S RHO ALGORITHM FOR DISCRETE LOGARITHMS l. =. l. 0 + m ( p − 1) / d for some m = 0, 1, , d − 1, which must all be checked until the discrete logarithm is found. Thus, Pollard’s rho algorithm consists of iterating the sequences until a match is found, for which we use Floyd’s cycle-finding algorithm, just as in Pollard’s rho algorithm for factoring integers. INSERT INTO A CYCLIC SORTED LIST Today's task comes to us from i has 1337 code: Given a cyclic list with elements in sorted order, write a function to insert a new element into the cyclic list that maintains the sorted order of the cyclic list. Do not assume that the cyclic list is referenced by its minimal element. Your task PRIORITY QUEUES WITH DISTINCT ELEMENTS August 14, 2016 at 3:30 AM. Here is a Haskell version that uses the “priority search queue” provided by the psqueues package.-- There is an existing data structure called the "priority search queue" that -- allows us to easily implement this. LEFTPAD | PROGRAMMING PRAXIS March 25, 2016. Large portions of the internet failed a few days ago when a program called leftpad, which pads a string to a given length by adding spaces or other characters at the left of the string, was suddenly removed from its repository. The whole episode is sad, and brings nothing but shame on everyone involved (though everyoneinvolved
PROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should returnCURIOUS NUMBERS
Here’s another way of directly calculating curious numbers: k-digit A is curious if A*A = A mod 10ᵏ, ie. A*A-A = A* (A-1) = X*10ᵏ = X*5ᵏ*2ᵏ for some X. A and A-1 must be co-prime so 5ᵏ must divide one and 2ᵏ must divide the other, which means that A satisfies: A mod 5ᵏ = 0 and A mod 2ᵏ = 1. or: POTHOLES | PROGRAMMING PRAXIS Potholes are marked with an “X” in the road, and also count as 1 unit of length. The task is to take a road of length N and fix all potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Your task is to write a program that takes a string representing a road and returnsthe
BABY STEPS, GIANT STEPS In a previous exercise we discussed the discrete logarithm problem, which is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; the modulus m is usually taken as prime. Today we look at an algorithm, known as baby steps, giant steps, that was developed by Daniel Shanks in 1971: 1. Compute limits: b = ⌈ √m ⌉. h = (x −1) b. 2. Construct liHOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
POLLARD’S RHO ALGORITHM FOR DISCRETE LOGARITHMS l. =. l. 0 + m ( p − 1) / d for some m = 0, 1, , d − 1, which must all be checked until the discrete logarithm is found. Thus, Pollard’s rho algorithm consists of iterating the sequences until a match is found, for which we use Floyd’s cycle-finding algorithm, just as in Pollard’s rho algorithm for factoring integers. INSERT INTO A CYCLIC SORTED LIST Today's task comes to us from i has 1337 code: Given a cyclic list with elements in sorted order, write a function to insert a new element into the cyclic list that maintains the sorted order of the cyclic list. Do not assume that the cyclic list is referenced by its minimal element. Your task PRIORITY QUEUES WITH DISTINCT ELEMENTS August 14, 2016 at 3:30 AM. Here is a Haskell version that uses the “priority search queue” provided by the psqueues package.-- There is an existing data structure called the "priority search queue" that -- allows us to easily implement this. LEFTPAD | PROGRAMMING PRAXIS March 25, 2016. Large portions of the internet failed a few days ago when a program called leftpad, which pads a string to a given length by adding spaces or other characters at the left of the string, was suddenly removed from its repository. The whole episode is sad, and brings nothing but shame on everyone involved (though everyoneinvolved
APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
KAPREKAR NUMBERS
Wolfram’s MathWorld describes Kaprekar numbers like this:. Consider an n-digit number k.Square it and add the right n digits to the left n or n-1 digits.If the resultant sum is k, then k is called a Kaprekar number. For example, 9 is a Kaprekar number since 9 2 = 81 and 8 + 1 = 9 and 297 is a Kaprekar number since 297 2 = 88209 and 88 + 209 = 297.. Your task is to write a function thatNON-ABUNDANT SUMS
It's been a long time since we did an exercise from Project Euler; here is number 23: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 +STALIN SORT
Stalin Sort is a single-pass sort that operates in O(1) space and O(n) time. Iterate down the list of elements checking if they are in order. Any element which is out of order is sent to the gulag (eliminated from the list). At the end you have a sorted list, though it may notbe
HOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
DISCRETE LOGARITHMS
The discrete logarithm problem is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; x and m must be relatively prime, which is usually enforced by taking the modulus m as prime. For instance, in the expression 3 y ≡ 13 (mod 17), the discrete logarithm y = 4, since 3 4 ≡ 13 (mod 17). The discrete logarithm problem is of fundamental importance in some branchesSQUARE DIGIT CHAINS
Here is the Project Euler version of the problem: A number chain is created by continuously added the square of the digits of a number to form a new number until it has been seen before. For example: 44 → 32 → 13 → 10 → 1 → 1. 85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89. Therefore any chain that arrives at 1 or SEND + MORE = MONEY, PART 1 A classic puzzle of recreational mathematics is the cryptarithm, where the solver is given a math problem in words and must systematically substitute digits for the letters of the puzzle to form a valid calculation. For instance, the famous cryptarithm SEND + MORE = MONEY is solved as M=1, Y=2, E=5, N=6, D=7, R=8, S=9 MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random numberPROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should returnGEOTHMETIC MEANDIAN
In the world of Randall Munroe, the geothmetic meandian of any set of positive numbers is computed by iterating three sequences — the arithmetic mean, the geometric mean, and the median — until they converge. For instance, the geothmetic meandian of the set (1,1,2,3,5) is 2.089, computed as follows: 1 2.4 1.9743504858348200 2 2 2CURIOUS NUMBERS
Here’s another way of directly calculating curious numbers: k-digit A is curious if A*A = A mod 10ᵏ, ie. A*A-A = A* (A-1) = X*10ᵏ = X*5ᵏ*2ᵏ for some X. A and A-1 must be co-prime so 5ᵏ must divide one and 2ᵏ must divide the other, which means that A satisfies: A mod 5ᵏ = 0 and A mod 2ᵏ = 1. or: POTHOLES | PROGRAMMING PRAXIS Potholes are marked with an “X” in the road, and also count as 1 unit of length. The task is to take a road of length N and fix all potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Your task is to write a program that takes a string representing a road and returnsthe
BABY STEPS, GIANT STEPS In a previous exercise we discussed the discrete logarithm problem, which is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; the modulus m is usually taken as prime. Today we look at an algorithm, known as baby steps, giant steps, that was developed by Daniel Shanks in 1971: 1. Compute limits: b = ⌈ √m ⌉. h = (x −1) b. 2. Construct liHOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
PRIORITY QUEUES WITH DISTINCT ELEMENTS August 14, 2016 at 3:30 AM. Here is a Haskell version that uses the “priority search queue” provided by the psqueues package.-- There is an existing data structure called the "priority search queue" that -- allows us to easily implement this. LEFTPAD | PROGRAMMING PRAXIS March 25, 2016. Large portions of the internet failed a few days ago when a program called leftpad, which pads a string to a given length by adding spaces or other characters at the left of the string, was suddenly removed from its repository. The whole episode is sad, and brings nothing but shame on everyone involved (though everyoneinvolved
MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random numberPROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should returnGEOTHMETIC MEANDIAN
In the world of Randall Munroe, the geothmetic meandian of any set of positive numbers is computed by iterating three sequences — the arithmetic mean, the geometric mean, and the median — until they converge. For instance, the geothmetic meandian of the set (1,1,2,3,5) is 2.089, computed as follows: 1 2.4 1.9743504858348200 2 2 2CURIOUS NUMBERS
Here’s another way of directly calculating curious numbers: k-digit A is curious if A*A = A mod 10ᵏ, ie. A*A-A = A* (A-1) = X*10ᵏ = X*5ᵏ*2ᵏ for some X. A and A-1 must be co-prime so 5ᵏ must divide one and 2ᵏ must divide the other, which means that A satisfies: A mod 5ᵏ = 0 and A mod 2ᵏ = 1. or: POTHOLES | PROGRAMMING PRAXIS Potholes are marked with an “X” in the road, and also count as 1 unit of length. The task is to take a road of length N and fix all potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Your task is to write a program that takes a string representing a road and returnsthe
BABY STEPS, GIANT STEPS In a previous exercise we discussed the discrete logarithm problem, which is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; the modulus m is usually taken as prime. Today we look at an algorithm, known as baby steps, giant steps, that was developed by Daniel Shanks in 1971: 1. Compute limits: b = ⌈ √m ⌉. h = (x −1) b. 2. Construct liHOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
PRIORITY QUEUES WITH DISTINCT ELEMENTS August 14, 2016 at 3:30 AM. Here is a Haskell version that uses the “priority search queue” provided by the psqueues package.-- There is an existing data structure called the "priority search queue" that -- allows us to easily implement this. LEFTPAD | PROGRAMMING PRAXIS March 25, 2016. Large portions of the internet failed a few days ago when a program called leftpad, which pads a string to a given length by adding spaces or other characters at the left of the string, was suddenly removed from its repository. The whole episode is sad, and brings nothing but shame on everyone involved (though everyoneinvolved
MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random number APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
HOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
KAPREKAR NUMBERS
Wolfram’s MathWorld describes Kaprekar numbers like this:. Consider an n-digit number k.Square it and add the right n digits to the left n or n-1 digits.If the resultant sum is k, then k is called a Kaprekar number. For example, 9 is a Kaprekar number since 9 2 = 81 and 8 + 1 = 9 and 297 is a Kaprekar number since 297 2 = 88209 and 88 + 209 = 297.. Your task is to write a function thatSTALIN SORT
Stalin Sort is a single-pass sort that operates in O(1) space and O(n) time. Iterate down the list of elements checking if they are in order. Any element which is out of order is sent to the gulag (eliminated from the list). At the end you have a sorted list, though it may notbe
SEND + MORE = MONEY, PART 1 A classic puzzle of recreational mathematics is the cryptarithm, where the solver is given a math problem in words and must systematically substitute digits for the letters of the puzzle to form a valid calculation. For instance, the famous cryptarithm SEND + MORE = MONEY is solved as M=1, Y=2, E=5, N=6, D=7, R=8, S=9DISCRETE LOGARITHMS
The discrete logarithm problem is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; x and m must be relatively prime, which is usually enforced by taking the modulus m as prime. For instance, in the expression 3 y ≡ 13 (mod 17), the discrete logarithm y = 4, since 3 4 ≡ 13 (mod 17). The discrete logarithm problem is of fundamental importance in some branchesSQUARE DIGIT CHAINS
Here is the Project Euler version of the problem: A number chain is created by continuously added the square of the digits of a number to form a new number until it has been seen before. For example: 44 → 32 → 13 → 10 → 1 → 1. 85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89. Therefore any chain that arrives at 1 or MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random number DOUBLE TRANSPOSITION CIPHER May 29, 2009. Transposition ciphers work by rearranging the letters of a plaintext to form a ciphertext; both the length of the text and the frequency distribution of the letters are identical between plaintext and ciphertext. The rail-fence cipher is a well-known transposition cipher; another is the columnar transposition that is the subjectPROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should returnGEOTHMETIC MEANDIAN
In the world of Randall Munroe, the geothmetic meandian of any set of positive numbers is computed by iterating three sequences — the arithmetic mean, the geometric mean, and the median — until they converge. For instance, the geothmetic meandian of the set (1,1,2,3,5) is 2.089, computed as follows: 1 2.4 1.9743504858348200 2 2 2CURIOUS NUMBERS
Here’s another way of directly calculating curious numbers: k-digit A is curious if A*A = A mod 10ᵏ, ie. A*A-A = A* (A-1) = X*10ᵏ = X*5ᵏ*2ᵏ for some X. A and A-1 must be co-prime so 5ᵏ must divide one and 2ᵏ must divide the other, which means that A satisfies: A mod 5ᵏ = 0 and A mod 2ᵏ = 1. or: POTHOLES | PROGRAMMING PRAXIS Potholes are marked with an “X” in the road, and also count as 1 unit of length. The task is to take a road of length N and fix all potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Your task is to write a program that takes a string representing a road and returnsthe
BABY STEPS, GIANT STEPS In a previous exercise we discussed the discrete logarithm problem, which is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; the modulus m is usually taken as prime. Today we look at an algorithm, known as baby steps, giant steps, that was developed by Daniel Shanks in 1971: 1. Compute limits: b = ⌈ √m ⌉. h = (x −1) b. 2. Construct liHOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
PRIORITY QUEUES WITH DISTINCT ELEMENTS August 14, 2016 at 3:30 AM. Here is a Haskell version that uses the “priority search queue” provided by the psqueues package.-- There is an existing data structure called the "priority search queue" that -- allows us to easily implement this. LEFTPAD | PROGRAMMING PRAXIS March 25, 2016. Large portions of the internet failed a few days ago when a program called leftpad, which pads a string to a given length by adding spaces or other characters at the left of the string, was suddenly removed from its repository. The whole episode is sad, and brings nothing but shame on everyone involved (though everyoneinvolved
MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random numberPROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should returnGEOTHMETIC MEANDIAN
In the world of Randall Munroe, the geothmetic meandian of any set of positive numbers is computed by iterating three sequences — the arithmetic mean, the geometric mean, and the median — until they converge. For instance, the geothmetic meandian of the set (1,1,2,3,5) is 2.089, computed as follows: 1 2.4 1.9743504858348200 2 2 2CURIOUS NUMBERS
Here’s another way of directly calculating curious numbers: k-digit A is curious if A*A = A mod 10ᵏ, ie. A*A-A = A* (A-1) = X*10ᵏ = X*5ᵏ*2ᵏ for some X. A and A-1 must be co-prime so 5ᵏ must divide one and 2ᵏ must divide the other, which means that A satisfies: A mod 5ᵏ = 0 and A mod 2ᵏ = 1. or: POTHOLES | PROGRAMMING PRAXIS Potholes are marked with an “X” in the road, and also count as 1 unit of length. The task is to take a road of length N and fix all potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Your task is to write a program that takes a string representing a road and returnsthe
BABY STEPS, GIANT STEPS In a previous exercise we discussed the discrete logarithm problem, which is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; the modulus m is usually taken as prime. Today we look at an algorithm, known as baby steps, giant steps, that was developed by Daniel Shanks in 1971: 1. Compute limits: b = ⌈ √m ⌉. h = (x −1) b. 2. Construct liHOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
PRIORITY QUEUES WITH DISTINCT ELEMENTS August 14, 2016 at 3:30 AM. Here is a Haskell version that uses the “priority search queue” provided by the psqueues package.-- There is an existing data structure called the "priority search queue" that -- allows us to easily implement this. LEFTPAD | PROGRAMMING PRAXIS March 25, 2016. Large portions of the internet failed a few days ago when a program called leftpad, which pads a string to a given length by adding spaces or other characters at the left of the string, was suddenly removed from its repository. The whole episode is sad, and brings nothing but shame on everyone involved (though everyoneinvolved
MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random number APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
HOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
KAPREKAR NUMBERS
Wolfram’s MathWorld describes Kaprekar numbers like this:. Consider an n-digit number k.Square it and add the right n digits to the left n or n-1 digits.If the resultant sum is k, then k is called a Kaprekar number. For example, 9 is a Kaprekar number since 9 2 = 81 and 8 + 1 = 9 and 297 is a Kaprekar number since 297 2 = 88209 and 88 + 209 = 297.. Your task is to write a function thatSTALIN SORT
Stalin Sort is a single-pass sort that operates in O(1) space and O(n) time. Iterate down the list of elements checking if they are in order. Any element which is out of order is sent to the gulag (eliminated from the list). At the end you have a sorted list, though it may notbe
SEND + MORE = MONEY, PART 1 A classic puzzle of recreational mathematics is the cryptarithm, where the solver is given a math problem in words and must systematically substitute digits for the letters of the puzzle to form a valid calculation. For instance, the famous cryptarithm SEND + MORE = MONEY is solved as M=1, Y=2, E=5, N=6, D=7, R=8, S=9DISCRETE LOGARITHMS
The discrete logarithm problem is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; x and m must be relatively prime, which is usually enforced by taking the modulus m as prime. For instance, in the expression 3 y ≡ 13 (mod 17), the discrete logarithm y = 4, since 3 4 ≡ 13 (mod 17). The discrete logarithm problem is of fundamental importance in some branchesSQUARE DIGIT CHAINS
Here is the Project Euler version of the problem: A number chain is created by continuously added the square of the digits of a number to form a new number until it has been seen before. For example: 44 → 32 → 13 → 10 → 1 → 1. 85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89. Therefore any chain that arrives at 1 or MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random number DOUBLE TRANSPOSITION CIPHER May 29, 2009. Transposition ciphers work by rearranging the letters of a plaintext to form a ciphertext; both the length of the text and the frequency distribution of the letters are identical between plaintext and ciphertext. The rail-fence cipher is a well-known transposition cipher; another is the columnar transposition that is the subjectPROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should return POTHOLES | PROGRAMMING PRAXIS Today's exercise comes from one of those online code exercises, via Stack Overflow: There is a machine that can fix all potholes along a road 3 units in length. A unit of road will be represented by a period in a string. For example, "" is one section of road 3 units in length.Potholes
GEOTHMETIC MEANDIAN
In mathematics, the arithmetic geometric mean of two positive real numbers is computed by repeatedly taking half their sum and the square root of their product until the two numbers converge. For instance, the arithmetic geometric mean of 24 and 6 is 13.456171, with the iterative steps computed as follows: 0 24 6 1 15DOUBLE DABBLE
Over at ComputerPhile, Professor Brailsford gives a beautiful explanation of the double-dabble algorithm for converting a number from binary to binary-coded decimal. If you don’t want to watch the video — you should — there is also an explanation at Wikipedia, or you can read the original description by C. B. Falconer.. Your task is to implement the double-dabble algorithm as shown byHOARE’S PARTITION
I've recently rekindled my interest in sorting algorithms (it's a fascination that never really goes away), and I've been looking at quick sort. The most common academic version of quick sort uses a partition due to Nick Lomuto, which takes a single pointer that scans through the arry, concludes with the partitioning element in the POLLARD’S RHO ALGORITHM FOR DISCRETE LOGARITHMS We studied discrete logarithms in two previous exercises. Today we look at a third algorithm for computing discrete algorithms, invented by John Pollard in the mid 1970s. Our presentation follows that in the book Prime Numbers: A Computational Perspective by Richard Crandall and Carl Pomerance, which differs somewhat from other sources. Ourgoal is to
SQUARE DIGIT CHAINS
Today’s task appears on Project Euler, Rosetta Code, and Sloane’s, so it is well worth a look; we even did a version of this task in a previous exercise.Here is the Project Euler version of the problem: A number chain is created by continuously added the square of the digits of a number to form a new number until it has been seen before.PEARSON HASHING
Cryptographic hashes, also called message digests, are ubiquitous in modern cryptography — Brce Schneier calls them "the workhorses of modern cryptography" — used among other things in digital signatures, message authentication codes, as fingerprints to detect duplicate data, and as checksums to detect data corruption. Today we look at a simple example of a hash MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random numberPROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should return POTHOLES | PROGRAMMING PRAXIS Today's exercise comes from one of those online code exercises, via Stack Overflow: There is a machine that can fix all potholes along a road 3 units in length. A unit of road will be represented by a period in a string. For example, "" is one section of road 3 units in length.Potholes
GEOTHMETIC MEANDIAN
In mathematics, the arithmetic geometric mean of two positive real numbers is computed by repeatedly taking half their sum and the square root of their product until the two numbers converge. For instance, the arithmetic geometric mean of 24 and 6 is 13.456171, with the iterative steps computed as follows: 0 24 6 1 15DOUBLE DABBLE
Over at ComputerPhile, Professor Brailsford gives a beautiful explanation of the double-dabble algorithm for converting a number from binary to binary-coded decimal. If you don’t want to watch the video — you should — there is also an explanation at Wikipedia, or you can read the original description by C. B. Falconer.. Your task is to implement the double-dabble algorithm as shown byHOARE’S PARTITION
I've recently rekindled my interest in sorting algorithms (it's a fascination that never really goes away), and I've been looking at quick sort. The most common academic version of quick sort uses a partition due to Nick Lomuto, which takes a single pointer that scans through the arry, concludes with the partitioning element in the POLLARD’S RHO ALGORITHM FOR DISCRETE LOGARITHMS We studied discrete logarithms in two previous exercises. Today we look at a third algorithm for computing discrete algorithms, invented by John Pollard in the mid 1970s. Our presentation follows that in the book Prime Numbers: A Computational Perspective by Richard Crandall and Carl Pomerance, which differs somewhat from other sources. Ourgoal is to
SQUARE DIGIT CHAINS
Today’s task appears on Project Euler, Rosetta Code, and Sloane’s, so it is well worth a look; we even did a version of this task in a previous exercise.Here is the Project Euler version of the problem: A number chain is created by continuously added the square of the digits of a number to form a new number until it has been seen before.PEARSON HASHING
Cryptographic hashes, also called message digests, are ubiquitous in modern cryptography — Brce Schneier calls them "the workhorses of modern cryptography" — used among other things in digital signatures, message authentication codes, as fingerprints to detect duplicate data, and as checksums to detect data corruption. Today we look at a simple example of a hash MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random number JUNE | 2021 | PROGRAMMING PRAXIS Lagarias and Sloane study the “approximate squaring” map f(x) = x⌈x⌉ and its behavior when iterated in this paper.. Consider the fraction x = n / d when n > d > 1; let’s take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the “ceiling”) is 2, and 8/7 × 2 = 16/7. APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
CURIOUS NUMBERS
Today’s exercise is in the style of Project Euler, so the rules are that your solution must not use more than a minute of computer time and that you can’t peek at the solution until you have the answer yourself.. Some numbers have the curious property that when they are squared, the number appears in the least-significant digits of theproduct.
DOUBLE DABBLE
Over at ComputerPhile, Professor Brailsford gives a beautiful explanation of the double-dabble algorithm for converting a number from binary to binary-coded decimal. If you don’t want to watch the video — you should — there is also an explanation at Wikipedia, or you can read the original description by C. B. Falconer.. Your task is to implement the double-dabble algorithm as shown byKAPREKAR NUMBERS
Wolfram’s MathWorld describes Kaprekar numbers like this:. Consider an n-digit number k.Square it and add the right n digits to the left n or n-1 digits.If the resultant sum is k, then k is called a Kaprekar number. For example, 9 is a Kaprekar number since 9 2 = 81 and 8 + 1 = 9 and 297 is a Kaprekar number since 297 2 = 88209 and 88 + 209 = 297.. Your task is to write a function thatSTALIN SORT
Stalin Sort is a single-pass sort that operates in O(1) space and O(n) time. Iterate down the list of elements checking if they are in order. Any element which is out of order is sent to the gulag (eliminated from the list). At the end you have a sorted list, though it may notbe
NON-ABUNDANT SUMS
It's been a long time since we did an exercise from Project Euler; here is number 23: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 +DISCRETE LOGARITHMS
The discrete logarithm problem is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; x and m must be relatively prime, which is usually enforced by taking the modulus m as prime. For instance, in the expression 3 y ≡ 13 (mod 17), the discrete logarithm y = 4, since 3 4 ≡ 13 (mod 17). The discrete logarithm problem is of fundamental importance in some branches TWO QUEUES MAKE A STACK In the previous exercise we implemented queues. Today's exercise will use those queues to solve exercise 10.1-7 from CLRS: Show how to implement a stack using two queues. Analyze the running time of the stack operations. You may assume that the queue operations enqueue, dequeue, and isEmpty are provided. You should provide the stackoperations
LAST NON-ZERO DIGIT OF A FACTORIAL Today’s exercise appears from time to time on beginning-programmer message boards: Write a program that, given n, returns the last non-zero digit of n! (factorial). For instance, 7! = 1 * 2 *PROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should returnGEOTHMETIC MEANDIAN
In the world of Randall Munroe, the geothmetic meandian of any set of positive numbers is computed by iterating three sequences — the arithmetic mean, the geometric mean, and the median — until they converge. For instance, the geothmetic meandian of the set (1,1,2,3,5) is 2.089, computed as follows: 1 2.4 1.9743504858348200 2 2 2 POTHOLES | PROGRAMMING PRAXIS Potholes are marked with an “X” in the road, and also count as 1 unit of length. The task is to take a road of length N and fix all potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Your task is to write a program that takes a string representing a road and returnsthe
CURIOUS NUMBERS
Here’s another way of directly calculating curious numbers: k-digit A is curious if A*A = A mod 10ᵏ, ie. A*A-A = A* (A-1) = X*10ᵏ = X*5ᵏ*2ᵏ for some X. A and A-1 must be co-prime so 5ᵏ must divide one and 2ᵏ must divide the other, which means that A satisfies: A mod 5ᵏ = 0 and A mod 2ᵏ = 1. or:DOUBLE DABBLE
Processing the BCD digits (check if >4 and add 3) n times will be a big waste of time, compared to only (ceilling n 3) divisions by ten! On my system double-dabble takes more than double the time of bcd, for 4-digits, 16-bit BCDs. A good friend died a few years ago. He was very interested in programming microprocessors. MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random numberPEARSON HASHING
Cryptographic hashes, also called message digests, are ubiquitous in modern cryptography — Brce Schneier calls them "the workhorses of modern cryptography" — used among other things in digital signatures, message authentication codes, as fingerprints to detect duplicate data, and as checksums to detect data corruption. Today we look at a simple example of a hashSQUARE DIGIT CHAINS
Here is the Project Euler version of the problem: A number chain is created by continuously added the square of the digits of a number to form a new number until it has been seen before. For example: 44 → 32 → 13 → 10 → 1 → 1. 85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89. Therefore any chain that arrives at 1 or PRIORITY QUEUES WITH DISTINCT ELEMENTS August 14, 2016 at 3:30 AM. Here is a Haskell version that uses the “priority search queue” provided by the psqueues package.-- There is an existing data structure called the "priority search queue" that -- allows us to easily implement this.PROGRAMMING PRAXIS
Today’s exercise comes from Stack Overflow:. Given a number N and a set of numbers s = {s1, s2, , sn} where s1 < s2 < < sn < N, remove all multiples of {s1, s2, , sn} from the range 1..N.. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and 2MAX | PROGRAMMING PRAXIS Today's exercise comes from Stack Overflow: Given an array A consisting of N integers, return the maximum sum of two numbers whose digits add up to an equal sum. If there are not two numbers whose digits have an equal sum, the function should returnGEOTHMETIC MEANDIAN
In the world of Randall Munroe, the geothmetic meandian of any set of positive numbers is computed by iterating three sequences — the arithmetic mean, the geometric mean, and the median — until they converge. For instance, the geothmetic meandian of the set (1,1,2,3,5) is 2.089, computed as follows: 1 2.4 1.9743504858348200 2 2 2 POTHOLES | PROGRAMMING PRAXIS Potholes are marked with an “X” in the road, and also count as 1 unit of length. The task is to take a road of length N and fix all potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Your task is to write a program that takes a string representing a road and returnsthe
CURIOUS NUMBERS
Here’s another way of directly calculating curious numbers: k-digit A is curious if A*A = A mod 10ᵏ, ie. A*A-A = A* (A-1) = X*10ᵏ = X*5ᵏ*2ᵏ for some X. A and A-1 must be co-prime so 5ᵏ must divide one and 2ᵏ must divide the other, which means that A satisfies: A mod 5ᵏ = 0 and A mod 2ᵏ = 1. or:DOUBLE DABBLE
Processing the BCD digits (check if >4 and add 3) n times will be a big waste of time, compared to only (ceilling n 3) divisions by ten! On my system double-dabble takes more than double the time of bcd, for 4-digits, 16-bit BCDs. A good friend died a few years ago. He was very interested in programming microprocessors. MINIMUM STANDARD RANDOM NUMBER GENERATOR In 1988, Stephen K. Park and Keith W. Miller, reacting to the plethora of unsatisfactory random number generators then available, published a linear congruential random number generator that they claimed should be the "minimum standard" for an acceptable random number generator. Twenty-five years later, the situation is only somewhat better, and embarrassingly bad random numberPEARSON HASHING
Cryptographic hashes, also called message digests, are ubiquitous in modern cryptography — Brce Schneier calls them "the workhorses of modern cryptography" — used among other things in digital signatures, message authentication codes, as fingerprints to detect duplicate data, and as checksums to detect data corruption. Today we look at a simple example of a hashSQUARE DIGIT CHAINS
Here is the Project Euler version of the problem: A number chain is created by continuously added the square of the digits of a number to form a new number until it has been seen before. For example: 44 → 32 → 13 → 10 → 1 → 1. 85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89. Therefore any chain that arrives at 1 or PRIORITY QUEUES WITH DISTINCT ELEMENTS August 14, 2016 at 3:30 AM. Here is a Haskell version that uses the “priority search queue” provided by the psqueues package.-- There is an existing data structure called the "priority search queue" that -- allows us to easily implement this. ESSAYS | PROGRAMMING PRAXIS Essays are not exercises, they don’t present a task to challenge you, but instead provide extended discussion and complete source code. Though essays are often based on exercises, they are larger, providing more space to delve more deeply into the topic at hand. New essays are added from time to time, so be sure to check back often. APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
APPROXIMATE SQUARING Lagarias and Sloane study the "approximate squaring" map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let's take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the "ceiling")is 2, and 8/7
IBAN | PROGRAMMING PRAXIS The International Bank Account Number (IBAN) is an internationally agreed standard of identifying bank accounts with a hash number to reduce errors. The first two characters of an IBAN are the two-letter country code, the next two characters are a two-digit hash, and the remaining characters identify the bank routing number and depositoraccount number.
NON-ABUNDANT SUMS
It's been a long time since we did an exercise from Project Euler; here is number 23: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 +HOARE’S PARTITION
Hoare’s partition concludes by returning the right-side pointer; all items to the left of the pointer, plus the item at the pointer itself, are smaller than all items to the right of the pointer. The partitioning element is somewhere in the left-hand partition, but not necessarily at its end, which requires a change to the recursive callin
BABY STEPS, GIANT STEPS In a previous exercise we discussed the discrete logarithm problem, which is to compute the exponent y in the expression x y ≡ n (mod m), given x, n, and m; the modulus m is usually taken as prime. Today we look at an algorithm, known as baby steps, giant steps, that was developed by Daniel Shanks in 1971: 1. Compute limits: b = ⌈ √m ⌉. h = (x −1) b. 2. Construct liCOLLINEARITY
A complex solution, pun intended, to within an epsilon: representing points as rectangular numbers in the obvious way, then computing the cosine of the angle between two vectors. (Or if at least one of the two vectors is null, the three points are at most two, and POLLARD’S RHO ALGORITHM FOR DISCRETE LOGARITHMS l. =. l. 0 + m ( p − 1) / d for some m = 0, 1, , d − 1, which must all be checked until the discrete logarithm is found. Thus, Pollard’s rho algorithm consists of iterating the sequences until a match is found, for which we use Floyd’s cycle-finding algorithm, just as in Pollard’s rho algorithm for factoring integers. TRANSLATE CSV TO HTML January 15, 2013. A common format for data storage is the CSV format for comma-separated values. A common format for data presentation is HTML for browsers using tables. Your task is to write a function that reads a file in CSV format and translates it to a table in HTML format. When you are finished, you are welcome to read or run asuggested
PROGRAMMING PRAXIS
A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer* Home
* About
* HOWTO: Posting Source Code* Standard Prelude
* List Utilities
* List Comprehensions* Pattern Matching
* Structures
* Matrices
* Hash Tables
* Dictionaries
* Input/Output
* Strings
* Sorting
* Higher-Order Funcs* Math Functions
* Bits
* Random Numbers
* Control Flow
* Date Arithmetic
* Unit Testing
* Miscellaneous
* Exercises
* Chronological
* Reverse
* Permuted
* Themes
* Search
* Essays
* Contact
100011322432435545
MAY 18, 2021
I had an email from a reader who found my factoring program on StackOverflow :
Python 2.7.13 (default, Mar 13 2017, 20:56:15)on cygwin
Type "help", "copyright", "credits" or "license" for more information. >>> def isPrime(n, k=5): # miller-rabin ... from random import randint ... if n < 2: return False ... for p in : ... if n % p == 0: return n == p ... s, d = 0, n-1 ... while d % 2 == 0: ... s, d = s+1, d/2 ... for i in range(k): ... x = pow(randint(2, n-1), d, n) ... if x == 1 or x == n-1: continue ... for r in range(1, s): ... x = (x * x) % n ... if x == 1: return False ... if x == n-1: break ... else: return False ... return True...
>>> def factors(n, b2=-1, b1=10000): # 2,3,5-wheel, then rho ... def gcd(a,b): # euclid's algorithm ... if b == 0: return a ... return gcd(b, a%b) ... def insertSorted(x, xs): # linear search ... i, ln = 0, len(xs) ... while i < ln and xs < x: i += 1 ... xs.insert(i,x) ... return xs ... if -1 <= n <= 1: return ... if n < -1: return + factors(-n) ... wheel = ... w, f, fs = 0, 2, ... while f*f <= n and f < b1: ... while n % f == 0: ... fs.append(f) ... n /= f ... f, w = f + wheel, w+1 ... if w == 11: w = 3 ... if n == 1: return fs ... h, t, g, c = 1, 1, 1, 1 ... while not isPrime(n): ... while b2 <> 0 and g == 1: ... h = (h*h+c)%n # the hare runs ... h = (h*h+c)%n # twice as fast ... t = (t*t+c)%n # as the tortoise ... g = gcd(t-h, n); b2 -= 1 ... if b2 == 0: return fs ... if isPrime(g): ... while n % g == 0: ... fs = insertSorted(g, fs) ... n /= g ... h, t, g, c = 1, 1, 1, c+1 ... return insertSorted(n, fs) He complained that the program failed to factor the number 100011322432435545, entering an infinite loop instead of returning alist of factors.
Your task is to figure out what is wrong, and fix it. When you are finished, you are welcome to reador run
a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1
2
Posted by programmingpraxisFiled in Exercises
Leave a Comment »
POTHOLES
MAY 11, 2021
Today’s exercise comes from one of those online code exercises, viaStack Overflow :
> There is a machine that can fix all potholes along a road 3 units in > length. A unit of road will be represented by a period in a string. > For example, “…” is one section of road 3 units in length. > Potholes are marked with an “X” in the road, and also count as 1 > unit of length. The task is to take a road of length N and fix all > potholes with the fewest possible sections repaired by the machine. The city where I live needs one of those machines. Here are some examples: .X. 1 .X...X 2XXX.XXXX 3
.X.XX.XX.X 3
Your task is to write a program that takes a string representing a road and returns the smallest number of fixes that will remove all the potholes. When you are finished, you are welcome to reador run
a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1 2
Posted by programmingpraxisFiled in Exercises
3 Comments »
REMOVE MULTIPLES
APRIL 27, 2021
Today’s exercise comes from Stack Overflow:
> Given a number _N_ and a set of numbers s = {s1, s2, …, sn} where > s1 < s2 < … < sn < _N_, remove all multiples of {s1, s2, …, sn} > from the range 1.._N_. You should look at the original post on Stack Overflow. The poster gets the answer wrong (he excludes 3), he get the explanation of his wrong answer wrong (he excludes 10 as a multiple of 2), and his algorithm is odd, to say the least. I’m not making fun of him, but I see this kind of imprecision of thought all the time on the beginner-programmer discussion boards, and I can only think that he will struggle to have a successful programming career. Your task is to write a program that removes multiples from a range, as described above. When you are finished, you are welcome to reador run
a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1
2
Posted by programmingpraxisFiled in Exercises
9 Comments »
GEOTHMETIC MEANDIAN
APRIL 13, 2021
In mathematics, the arithmetic geometric mean of two positive real numbers is computed by repeatedly taking half their sum and the square root of their product until the two numbers converge. For instance, the arithmetic geometric mean of 24 and 6 is 13.456171…, with the iterative steps computed as follows: 0 24 6 1 15 12 2 13.5 13.416407864998738175455042 3 13.458203932499369089227521 13.458139030990984877207090 4 13.458171481745176983217305 13.458171481706053858316334 5 13.458171481725615420766820 13.458171481725615420766806 The arithmetic geometric mean was invented by Lagrange and studied by Gauss, and is used today to compute various transcendental functions because it converges so quickly. In the world of Randall Munroe, the geothmetic meandian of any set of positive numbers is computed by iterating three sequences — the arithmetic mean, the geometric mean, and the median — until they converge. For instance, the geothmetic meandian of the set (1,1,2,3,5) is 2.089, computed as follows: 1 2.4 1.9743504858348200 2 2 2.1247834952782734 2.1161924605448084 2 3 2.0803253186076938 2.0795368194795802 2.1161924605448084 4 2.0920181995440275 2.0919486049152223 2.0803253186076938 5 2.0880973743556477 2.0880901331209600 2.0919486049152223 6 2.0893787041306098 2.0893779142184865 2.0880973743556477 7 2.0889513309015815 2.0889512436159920 2.0893779142184865 8 2.0890934962453533 2.0890934865653277 2.0889513309015815 9 2.0890461045707540 2.0890461034958396 2.0890934865653277 Your task is to write programs that compute the arithmetic geometric mean and geothmetic meandian. When you are finished, you are welcometo read
or
run a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1
2
Posted by programmingpraxisFiled in Exercises
7 Comments »
GREEDY TEXT JUSTIFICATIONMARCH 30, 2021
Today’s exercise would make a good interview question, though I don’t know of anyone doing that; you should answer as if you are standing at a whiteboard explaining your code as you go: > Given a string and a line width, split the string into words (a > maximal run of characters excluding spaces) and write the words onto > successive lines with spaces added between the words so that each > line is the requested width. Words should be added to lines greedily > (as many words as will fit) and extra spaces should be assigned to > the left of the output string. The last line should not have spaces > added, so it may be shorter than the other lines. For example, the string “This is an example of text justification” is written with a line width of 16 like this:----+----+----+-
This is anexample of text
justification.
----+----+----+-
Your task is to write a program that greedily justifies text. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1
2
Posted by programmingpraxisFiled in Exercises
7 Comments »
FIZZBUZZ
MARCH 23, 2021
I’ve seen several recent posts on the beginning-programmer forums about how to solve the fizzbuzz problem, so let’s talk about thattoday:
Enumerate the numbers from 1 to N by writing “Fizz” if the number is divisible by 3, “Buzz” if the number is divisible by 5, “FizzBuzz” if the number is divisible by both, and the number itself if the number is divisible by neither. For instance, counting from 1 to 25 works like this: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11. Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22,23, Fizz, Buzz.
> FizzBuzz also appears as the first problem in Project Euler, where > they characterize the problem like this: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. Your task is to solve the two versions of the FizzBuzz problem, for all numbers up to _N_; you can use a simple method, but it is more fun to be a little bit clever. When you are finished, you are welcome toread or run
a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1 2
Posted by programmingpraxisFiled in Exercises
8 Comments »
BIGGER TO THE RIGHTMARCH 9, 2021
Given a list of integers, calculate a list of integers that contains, at each item of the list, the count of integers in the original list that are greater than the item at the current position of the original list. For example, given the input list (10 12 8 17 3 24 19), the desired output is (4 3 3 2 2 0 0), because at the first item in list, 10, there are four items (12 17 24 19) greater than 10, at the second item in the list, 12, there are three items (17 24 19) greater than 12, at the third item in the list, 8, there are three items (17 24 19) greater than 8, at the fourth item in the list, 17, there are two items (24 19) greater than 17, at the fifth item in the list, 3, there are two items (24 19) greater than 3, at the sixth item in the list, 24, there are 0 items () greater than 24, and at the seventh item in the list, 19, there are 0 items greater than 19. Your task is to write a program to calculate the list of counts of greater than the current item; is there an O(_n_) solution? When you are finished, you are welcome to read a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1
2
Posted by programmingpraxisFiled in Exercises
6 Comments »
TRAILING COMMENTS
FEBRUARY 23, 2021
Today’s exercise is based on a blog entry that Reddit pointed me to. Sean is trying to write a program that finds lines of code in his Python programs that have trailing comments at the ends of lines, which he considers bad style. His naive program improperly flagged a line as containing a trailing comment when the comment marker is embedded in a quoted string: x = "# This is fine" "This \# is fine too" x = "" # This is not Sean gets a little bit sidetracked in his blog entry, and never quite solves the problem; I’m not convinced the code he writes is correct (though he seems to think it is), and I’m also not convinced that trailing comments are a bad thing. Nevertheless, the task makes an interesting exercise, especially when we also handle quoted escapesequences.
Your task is to write a program that identifies lines of code with trailing comments. When you are finished, you are welcome to reador run
a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1
2
Posted by programmingpraxisFiled in Exercises
6 Comments »
LOCAL MAXIMA
FEBRUARY 16, 2021
A local maximum of a list of integers is an element of the list at which the adjacent list elements are either less than or equal to the current element; for instance, in the input list (1 2 1 2 3 4 3 2 3 2 1) there are three local maxima, one at the first 2, one at the 4, and one and the last 3. The elements at either end of a list should be considered as greater than the boundary. Only one maximum should be reported for a plateau (consecutive equal maxima). Your task is to write a program that finds the local maxima of a list of integers. When you are finished, you are welcome to reador run
a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1 2
Posted by programmingpraxisFiled in Exercises
13 Comments »
RUN LENGTH ENCODING
FEBRUARY 9, 2021
Alexey Grigorev says:
> Most candidates cannot solve this interview problem:>
> Input: “aaaabbbcca”>
> Output:
>
> Write a function that converts the input to the output. I ask it in > the screening inverview and give it 25 minutes. How would you solve> it?
Your task is to write the requested function. When you are finished, you are welcome to reador
run a suggested solution, or to post your own solution or discuss the exercise in the comments below.Pages: 1
2
Posted by programmingpraxisFiled in Exercises
9 Comments »
Previous Entries
Older posts
CATEGORIES
* Administrivia
* Exercises
ARCHIVES
* May 2021
* April 2021
* March 2021
* February 2021
* January 2021
* December 2020
* November 2020
* October 2020
* September 2020
* August 2020
* July 2020
* June 2020
* May 2020
* April 2020
* March 2020
* February 2020
* January 2020
* December 2019
* November 2019
* October 2019
* September 2019
* August 2019
* July 2019
* June 2019
* May 2019
* April 2019
* March 2019
* February 2019
* January 2019
* November 2018
* October 2018
* September 2018
* August 2018
* July 2018
* June 2018
* May 2018
* April 2018
* March 2018
* February 2018
* January 2018
* December 2017
* November 2017
* October 2017
* September 2017
* August 2017
* July 2017
* June 2017
* May 2017
* April 2017
* March 2017
* February 2017
* January 2017
* December 2016
* November 2016
* October 2016
* September 2016
* August 2016
* July 2016
* June 2016
* May 2016
* April 2016
* March 2016
* February 2016
* January 2016
* December 2015
* November 2015
* October 2015
* September 2015
* August 2015
* July 2015
* June 2015
* May 2015
* April 2015
* March 2015
* February 2015
* January 2015
* December 2014
* November 2014
* October 2014
* September 2014
* August 2014
* July 2014
* June 2014
* May 2014
* April 2014
* March 2014
* February 2014
* January 2014
* December 2013
* November 2013
* October 2013
* September 2013
* August 2013
* July 2013
* June 2013
* May 2013
* April 2013
* March 2013
* February 2013
* January 2013
* December 2012
* November 2012
* October 2012
* September 2012
* August 2012
* July 2012
* June 2012
* May 2012
* April 2012
* March 2012
* February 2012
* January 2012
* December 2011
* November 2011
* October 2011
* September 2011
* August 2011
* July 2011
* June 2011
* May 2011
* April 2011
* March 2011
* February 2011
* January 2011
* December 2010
* November 2010
* October 2010
* September 2010
* August 2010
* July 2010
* June 2010
* May 2010
* April 2010
* March 2010
* February 2010
* January 2010
* December 2009
* November 2009
* October 2009
* September 2009
* August 2009
* July 2009
* June 2009
* May 2009
* April 2009
* March 2009
* February 2009
June 2021
S
M
T
W
T
F
S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
May
ARCHIVES
* May 2021
* April 2021
* March 2021
* February 2021
* January 2021
* December 2020
* November 2020
* October 2020
* September 2020
* August 2020
* July 2020
* June 2020
* May 2020
* April 2020
* March 2020
* February 2020
* January 2020
* December 2019
* November 2019
* October 2019
* September 2019
* August 2019
* July 2019
* June 2019
* May 2019
* April 2019
* March 2019
* February 2019
* January 2019
* November 2018
* October 2018
* September 2018
* August 2018
* July 2018
* June 2018
* May 2018
* April 2018
* March 2018
* February 2018
* January 2018
* December 2017
* November 2017
* October 2017
* September 2017
* August 2017
* July 2017
* June 2017
* May 2017
* April 2017
* March 2017
* February 2017
* January 2017
* December 2016
* November 2016
* October 2016
* September 2016
* August 2016
* July 2016
* June 2016
* May 2016
* April 2016
* March 2016
* February 2016
* January 2016
* December 2015
* November 2015
* October 2015
* September 2015
* August 2015
* July 2015
* June 2015
* May 2015
* April 2015
* March 2015
* February 2015
* January 2015
* December 2014
* November 2014
* October 2014
* September 2014
* August 2014
* July 2014
* June 2014
* May 2014
* April 2014
* March 2014
* February 2014
* January 2014
* December 2013
* November 2013
* October 2013
* September 2013
* August 2013
* July 2013
* June 2013
* May 2013
* April 2013
* March 2013
* February 2013
* January 2013
* December 2012
* November 2012
* October 2012
* September 2012
* August 2012
* July 2012
* June 2012
* May 2012
* April 2012
* March 2012
* February 2012
* January 2012
* December 2011
* November 2011
* October 2011
* September 2011
* August 2011
* July 2011
* June 2011
* May 2011
* April 2011
* March 2011
* February 2011
* January 2011
* December 2010
* November 2010
* October 2010
* September 2010
* August 2010
* July 2010
* June 2010
* May 2010
* April 2010
* March 2010
* February 2010
* January 2010
* December 2009
* November 2009
* October 2009
* September 2009
* August 2009
* July 2009
* June 2009
* May 2009
* April 2009
* March 2009
* February 2009
BLOGROLL
* WordPress.com
* WordPress.org
Create a free website or blog at WordPress.com.Write a Comment...
Email (Required) Name (Required) WebsiteLoading Comments...
Comment
×
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. To find out more, including how to control cookies, see here: CookiePolicy
* FollowFollowing
* Programming Praxis*
Already have a WordPress.com account? Log in now.*
* Programming Praxis* Customize
* FollowFollowing
* Sign up
* Log in
* Report this content * Manage subscriptions* Collapse this bar
Details
Copyright © 2024 ArchiveBay.com. All rights reserved. Terms of Use | Privacy Policy | DMCA | 2021 | Feedback | Advertising | RSS 2.0