In front of you are 3 boxes. One box contains only apples, another box contains only oranges, and the last contains both apples and oranges. The first box has the label "apples," the second "oranges," and the third "apples and oranges." Unfortunately all of the labels are wrong. Your job is to fix the labels. You are not allowed to peek inside any of the boxes. But you can ask for a sample from any box. You point to a box, and you get a fruit from that box. What is the minimum number of samples you need to label all of the boxes correctly?
http://mkcohen.com/saturday-puzzle-9-apples-and-oranges
What if we want to find the number of squares for a chessboard of size NxN, where N is any number. Do you notice a pattern in the results in the table above? Well, if you take a look at the results that we showed above for the normal-sized 8×8 chessboard, you can see that the number of squares is equal to the sum of squares from 12 to 82, where 8 is equal to N. So, we can say in more general terms that the sum of squares for a chessboard of size NxN is equal to n^2 + (n-1)^2 + (n-2)^2 + …. (1)^2.
Formula for number of squares on NxN chessboard This is a common summation in math, and is actually equal to n(n + 1)(2n + 1)/6 – so for a chessboard of size nxn, this formula will give you the count of all of the squares on the board.
https://www.programmerinterview.com/puzzles/find-number-of-squares-chessboard/
def sum_squares_iterative(n):
res = 0
for i in range(1, n + 1):
res += i**2
return res
print(sum_squares_iterative(8))
def sum_squares_recursive(n):
return (n**2 + sum_squares_recursive(n-1)) if n >= 1 else 0
print(sum_squares_recursive(8))
def fibonacci_iterative(n):
# 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
a, b = 0, 1
for _ in range(0, n):
a, b = b, a + b
return a
def fibonacci_recursive(n):
if n > 1:
return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2)
return n
On full GC. See: https://codeahoy.com/2017/08/06/basics-of-java-garbage-collection/
Describe your current project's architecture.