## Posts

Showing posts from April, 2019

### ACC's Math Conjecture II Another one for posterity: If N= 31622777 , then  N^3 = 31622777 796632428411433, and that's the largest N that has such a property. I have tested this conjecture up to N's 100-digits long, and it holds true. Used the code below. If you can find a larger N, let me know. Thanks, ACC. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace SquareStart { class Program { static void Main(string[] args) { int power = Int32.Parse(args); BigInteger factor = 1; BigInteger MAX = 1000000; BigInteger count = 0; for (BigInteger n = 1; ; n++, count++) { if (n % 10 != 0 && (BigInteger.Pow(n, power)).ToString().StartsWith(n.ToString())) { Console.WriteLine("{0} => {1}", n, BigInteger.Pow(n, power)); BigInteger temp = n; n = 10 * n - factor; if (n <= temp) { n = temp; } else {

### Number of Enclaves Here is the problem (medium):  https://leetcode.com/problems/number-of-enclaves/ Given a 2D array  A , each cell is 0 (representing sea) or 1 (representing land) A move consists of walking from one land square 4-directionally to another land square, or off the boundary of the grid. Return the number of land squares in the grid for which we  cannot  walk off the boundary of the grid in any number of moves. Example 1: Input: [[0,0,0,0],[1,0,1,0],[0,1,1,0],[0,0,0,0]] Output: 3 Explanation: There are three 1s that are enclosed by 0s, and one 1 that isn't enclosed because its on the boundary. Example 2: Input: [[0,1,1,0],[0,0,1,0],[0,0,1,0],[0,0,0,0]] Output: 0 Explanation: All 1s are either on the boundary or can reach the boundary. Note: 1 <= A.length <= 500 1 <= A[i].length <= 500 0 <= A[i][j] <= 1 All rows have the same size. Here is one way to solve it: a) We'll do a Breadth-First-Search (BFS) using a Queue b) Have a helper m

### Friend Circles Here is a medium Leetcode problem:  https://leetcode.com/problems/friend-circles/ There are  N  students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a  direct  friend of B, and B is a  direct  friend of C, then A is an  indirect  friend of C. And we defined a friend circle is a group of students who are direct or indirect friends. Given a  N*N  matrix  M  representing the friend relationship between students in the class. If M[i][j] = 1, then the i th  and j th students are  direct  friends with each other, otherwise not. And you have to output the total number of friend circles among all the students. Example 1: Input: [[1,1,0], [1,1,0], [0,0,1]] Output: 2 Explanation: The 0 th and 1 st students are direct friends, so they are in a friend circle. The 2 nd student himself is in a friend circle. So return 2. Example 2: Input: [[1,1,0], [1,1,1], [0,1,1]] Output: 1 Explanation: The 0 th

### ACC's Math Conjecture Assume P, N and X are positive integers greater than 1. The only possible value for X in the below expression is 2 . I can't prove the conjecture but I can write some code that validates it for large P's and N's, and no matter how far it goes, the only possible integer value for X is 2. Take a look at some of the results (P;N;X). Code is down below, cheers, ACC. 2;2;2 4;4;2 16;8;2 32;10;2 256;16;2 1024;20;2 2048;22;2 8192;26;2 32768;30;2 65536;32;2 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SQRootPower { class Program { static void Main(string[] args) { int MAXN = 2000000; int MAXP = 1000; for (int n = 2; n <= MAXN; n++) { for (int p = 2; p <= MAXP; p++) { double result = _SQRootPower(n, p); if (Math.Abs((int)result - result) <= 0.00000001) { Console.WriteLine("{0};{1};{2}", n, p, result); } } } }

### IBM Ponder This, April 2019 IBM Ponder This is awesome. For 20 years they have been posting a math/coding/esoteric challenge once a month, and when you nail the answer, you get your name posted on a web site. Wow, name posted on a web site!!! 😊 IBM Ponder This this month ( April 2019 ) is the following: “ Find nine different prime numbers that can be placed in a 3x3 square in such a way that the average of every row, column, and diagonal is also a prime number. ” Here are the steps that I took to solving this problem, and I’ll explain each one of them: Sieve Cache Backtrack Prune Trial-N-Error Sieve : first apply the  sieve of Eratosthenes  to produce as many primes as you want, in N^2 time and N space Cache : cache the primes, you don't want to be performing the same test over and over again Backtrack : backtracking  is a technique commonly used in Algorithms to perform a depth-first-search in order to find a solution Prune : you need to prune the backtracking by cutting shor

### On the approximation of Riemann's Zeta Function for S=3 (Apéry's constant) Recently I've been obsessed with the Riemann's Hypothesis (RH). RH states that the zeroes for a particular type of equation called the "Zeta Function" lies on a particular line. The main corollary of proving such conjecture is that due to Euler, it will be possible to come up with a precise formula for the distribution of primes. It will be an interesting phenomenal when RH is proved: not only we'll know that the primes are distributed randomly, but they will also behave according to some predictable formula. Meaning that primes will be, at the same time, random but predictable , something that humans can't really grasp yet. The Zeta Function has well-known values, especially for positive even numbers. Zeta(2) and Zeta(4) were discovered by Euler, and both follow the pattern (k * PI^n)/m. Question is, can we write some code to approximate Zeta(3) using the same structure? Yes, we can. First have a code which implements Zeta (straightforward). The main lo