brain
tamnd's digital brain — notes, problems, research
42715 notes
Define the sequence a(n) as the number of adjacent pairs of ones in the binary expansion of n (possibly overlapping).
Solution to Project Euler Problem 990.
This problem asks us to write a shell script that reads a text file named words.txt and computes how many times each word appears. After counting the occurrences, the script must print every unique word together with its frequency, sorted in descending order of frequency.
An integer partition of a number n is a way of writing n as a sum of positive integers.
A contiguous range of positive integers is called a divisible range if all the integers in the range can be arranged in
This problem models course dependencies as a directed graph. Each course is represented as a node, and each prerequisite relationship is represented as a directed edge. If prerequisites[i] = [a, b], that means course b must be completed before course a.
We define nu2(n) to be the largest integer r such that 2^r divides n.
The sequence an is defined by a1=1, and then recursively for ngeq1: The first ten terms are 1, 2, -5, 4, 17, -10, -17, 8
The problem gives us an integer array called nums and another integer called target. Our task is to find two different elements in the array whose sum equals target, then return their indices.
This problem asks us to determine a valid order in which courses can be completed given prerequisite relationships between them. You are given numCourses, which represents the total number of courses labeled from 0 to numCourses - 1.
A round number is a number that ends with one or more zeros in a given base.
Bozo sort, not to be confused with the slightly less efficient bogo sort, consists out of checking if the input sequence
The problem asks us to compute the largest difference between two consecutive elements after sorting the array. At first glance, this may seem straightforward: sort the array, then scan through adjacent pairs to find the maximum difference.
Solution to Project Euler Problem 982.
Three friends attempt to collectively choose one of n options, labeled 1,dots,n, based upon their individual preferences
An infant's toy consists of n cups, labelled C1,dots,Cn in increasing order of size.
An ascent of a column j in a matrix occurs if the value of column j is smaller than the value of column j + 1 in all row
Starting with one piece of integer-sized rectangle paper, two players make moves in turn.
nStarting at zero, a kangaroo hops along the real number line in the positive direction.
For a positive integer n and digits d, we define F(n, d) as the number of the divisors of n whose last digits equal d.
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sequence sn is defined by s1 = 102022661 and sn = s{n-1}^2 bmod {998388889} for n 1.
A unitary divisor of a positive integer n is a divisor d of n such that gcdleft(d,frac{n}{d}right)=1.
Two players play a game with at least two piles of stones.
Let p be a prime of the form 5k-4 and define fp(x) = left(x^k+xright) bmod p.nnLet C(p) be the number of values 0 le x l
For the year 2025 Given positive integers a and b, the concatenation ab we call a 2025-number if ab = (a+b)^2.
The problem asks us to count how many bits are set to 1 in the binary representation of a positive integer n. A set bit is simply a bit whose value is 1. For example, the number 11 in binary is: This binary representation contains three 1 bits, so the answer is 3.
The function s(n) is defined recursively for positive integers by s(1) = 1 and s(n+1) = big(s(n) - 1big)^3 +2 for ngeq 1
Solution to Project Euler Problem 974.
This problem asks us to print exactly the 10th line from a text file named file.txt. The file contains multiple lines of plain text, and each line is separated by a newline character. The input is not provided as function arguments like many algorithm problems.
Write Fn for the n-th Fibonacci number, with F1 = F2 = 1 and F{n+1} = Fn + F{n-1}.
Solution to Project Euler Problem 992.
The following game is a classic example of Combinatorial Game Theory: Two players start with a strip of n white squares
Given any integer n gt 1 a binary factor tree T(n) is defined to be: - A tree with the single node n when n is prime.
A group of k(k-1) / 2 + 1 children play a game of k rounds.nAt the beginning, they are all seated on chairs arranged in
Let '' denote the bitwise AND operation.
A palindromic number reads the same both ways.
A driller drills for water.
Solution to Project Euler Problem 993.
Let P(n) be the number of permutations of 1,2,3,ldots,2n such that: 1.
- A Sierpiński graph of order-1 (S1) is an equilateral triangle.
Consider the following recurrence relation: Note that a0 is the golden ratio.
For a positive integer n construct a graph using all the divisors of n as the vertices.
Given a right-angled triangle with integer sides, the smaller angle formed by the two medians drawn on the the two perpe
We call a triangle fortunate if it has integral sides and at least one of its vertices has the property that the distanc
This problem asks us to transpose the contents of a text file. Transposing means converting rows into columns and columns into rows. Every word in the input file is separated by a single space, and each row contains the same number of columns. The input is a file named file.txt.
Define M(n) to be the minimum number of matchsticks needed to represent the number n.
The problem asks us to determine whether a given integer reads the same forward and backward. Such numbers are called palindromes. For example, the number 121 is a palindrome because reversing its digits still produces 121.
The problem gives us an array of positive integers called nums and a positive integer called target. We need to find the smallest possible length of a contiguous subarray whose sum is greater than or equal to target.
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
For every integer n 1, the family of functions f{n,a,b} is defined by for integers a, b, x with 0 < a < n, 0 le b < n, 0
This problem is based on (but not identical to) the scoring for the card game Cribbage.
nThe hyperbolic plane can be represented by the open unit disc, namely the set of points (x, y) in Bbb R^2 with x^2 + y^
The problem gives a Roman numeral string and asks us to convert it into its corresponding integer value. Roman numerals use seven symbols: Symbol Value --- --- I 1 V 5 X 10 L 50 C 100 D 500 M 1000 Most Roman numerals follow a simple additive rule.
Solution to Project Euler Problem 986.
Let {x} denote the fractional part of a real number x.nnDefine fN(x) to be the minimal value of {nx} for integer n satis
A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such t
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
Solution to Project Euler Problem 985.
For a given integer R consider all primitive Pythagorean triangles that can fit inside, without touching, a circle with
nA positive integer n is considered B-trivisible if the sum of all different prime factors of n which are not larger tha
This problem asks us to process a text file named file.txt and print only the phone numbers that match one of two valid formats. The valid formats are: and In both formats, every x represents a single digit from 0 to 9.
The minimum bounding square of a triangle is the smallest square that can be drawn which fully covers the triangle.
The problem asks us to transform a string into a zigzag pattern across a fixed number of rows, then read the characters row by row to produce the final result.
The problem gives two individually sorted integer arrays, nums1 and nums2, with lengths m and n. The task is to compute the median of the combined sorted sequence formed by merging both arrays. The median is the middle value of a sorted sequence.
A frog is placed on the number line.
An L-expression is defined as any one of the following: - a natural number; - the symbol A; - the symbol Z; - the symbol
The problem asks us to implement a simplified version of the C/C++ atoi function, which converts a string into a 32-bit signed integer. The conversion process is strict and follows several rules in a specific order.
Claire Voyant is a teacher playing a game with a class of students.
The problem gives us two non empty singly linked lists. Each linked list represents a non negative integer, but the digits are stored in reverse order. That means the head node contains the least significant digit.
The numbers from 1 to 12 can be arranged into a 3 times 4 matrix in either row-major or column-major order: By swapping
The problem describes a row of houses, where each house contains some amount of money. You are acting as a robber who wants to maximize the total amount stolen, but there is one important restriction, you cannot rob two adjacent houses.
Solution to Project Euler Problem 981.
Three epistemologists, known as A, B, and C, are in a room, each wearing a hat with a number on it.
There are N seats in a row.
The Fibonacci sequence (fi) is the unique sequence such that - f0=0 - f1=1 - f{i+1}=fi+f{i-1} Similarly, there is a uniq
The sum of the squares of the first ten natural numbers is, The square of the sum of the first ten natural numbers is, H
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Given nge 2 bowls arranged in a circle, mge 2 balls are distributed amongst them.
The problem gives us a database table named Weather that stores daily temperature records. Each row contains three fields: a unique id, a recordDate, and the temperature recorded on that date.
The problem asks us to reverse a singly linked list. A singly linked list is a sequence of nodes where each node stores a value and a pointer to the next node in the sequence. The input, head, represents the first node of the linked list.
A dynamical polynomial is a monicleading coefficient is 1 polynomial f(x) with integer coefficients such that f(x) divid
Consider a wire of length 1 unit between two posts.
70 coloured balls are placed in an urn, 10 for each of the seven rainbow colours.
Bob plays a single-player game of chance using two standard 6-sided dice and twelve cards numbered 1 to 12.
A positive integer, n, is a near power sum if there exists a positive integer, k, such that the sum of the kth powers of
Let dn(x) be the nth decimal digit of the fractional part of x, or 0 if the fractional part has fewer than n digits.
Let ABCD be a convex quadrilateral, with diagonals AC and BD.
A small child has a “number caterpillar” consisting of forty jigsaw pieces, each with one number on it, which, when conn
ABCD is a convex, integer sided quadrilateral with 1 le AB lt BC lt CD lt AD.
We shall call a fraction that cannot be cancelled down a resilient fraction.
The flipping game is a two player game played on an N by N square board.
The Torpids are rowing races held annually in Oxford, following some curious rules: - A division consists of n boats (ty
In the game, Monopoly, the standard board is set up in the following way: !0084monopolyboard.png A player starts on the
Consider the following configuration of 64 triangles: We wish to colour the interior of each triangle with one of three
A root or zero of a polynomial P(x) is a solution to the equation P(x) = 0.
A sequence is defined as: - gk = 1, for 0 le k le 1999 - gk = g{k-2000} + g{k - 1999}, for k ge 2000.
A triangular pyramid is constructed using spherical balls so that each ball rests on exactly three balls of the next low
Mamma Triangolo baked a triangular pizza.
For 0 le x lt 1, define di(x) to be the ith digit after the binary point of the binary representation of x.