brain

tamnd's digital brain — notes, problems, research

42715 notes

Project Euler Problem 384

Define the sequence a(n) as the number of adjacent pairs of ones in the binary expansion of n (possibly overlapping).

eulermathematicscompetitive-programming
Project Euler Problem 990

Solution to Project Euler Problem 990.

eulermathematicscompetitive-programming
LeetCode 192 - Word Frequency

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.

leetcodemediumshell
Project Euler Problem 374

An integer partition of a number n is a way of writing n as a sum of positive integers.

eulermathematicscompetitive-programming
Project Euler Problem 896

A contiguous range of positive integers is called a divisible range if all the integers in the range can be arranged in

eulermathematicscompetitive-programming
LeetCode 207 - Course Schedule

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.

leetcodemediumdepth-first-searchbreadth-first-searchgraph-theorytopological-sort
Project Euler Problem 792

We define nu2(n) to be the largest integer r such that 2^r divides n.

eulermathematicscompetitive-programming
Project Euler Problem 918

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

eulermathematicscompetitive-programming
LeetCode 1 - Two Sum

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.

leetcodeeasyarrayhash-table
LeetCode 210 - Course Schedule II

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.

leetcodemediumdepth-first-searchbreadth-first-searchgraph-theorytopological-sort
Project Euler Problem 926

A round number is a number that ends with one or more zeros in a given base.

eulermathematicscompetitive-programming
Project Euler Problem 367

Bozo sort, not to be confused with the slightly less efficient bogo sort, consists out of checking if the input sequence

eulermathematicscompetitive-programming
LeetCode 164 - Maximum Gap

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.

leetcodemediumarraysortingbucket-sortradix-sort
Project Euler Problem 982

Solution to Project Euler Problem 982.

eulermathematicscompetitive-programming
Project Euler Problem 906

Three friends attempt to collectively choose one of n options, labeled 1,dots,n, based upon their individual preferences

eulermathematicscompetitive-programming
Project Euler Problem 907

An infant's toy consists of n cups, labelled C1,dots,Cn in increasing order of size.

eulermathematicscompetitive-programming
Project Euler Problem 559

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

eulermathematicscompetitive-programming
Project Euler Problem 933

Starting with one piece of integer-sized rectangle paper, two players make moves in turn.

eulermathematicscompetitive-programming
Project Euler Problem 970

nStarting at zero, a kangaroo hops along the real number line in the positive direction.

eulermathematicscompetitive-programming
Project Euler Problem 474

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.

eulermathematicscompetitive-programming
Project Euler Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.

eulermathematicscompetitive-programming
Project Euler Problem 917

The sequence sn is defined by s1 = 102022661 and sn = s{n-1}^2 bmod {998388889} for n 1.

eulermathematicscompetitive-programming
Project Euler Problem 861

A unitary divisor of a positive integer n is a divisor d of n such that gcdleft(d,frac{n}{d}right)=1.

eulermathematicscompetitive-programming
Project Euler Problem 900

Two players play a game with at least two piles of stones.

eulermathematicscompetitive-programming
Project Euler Problem 971

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

eulermathematicscompetitive-programming
Project Euler Problem 932

For the year 2025 Given positive integers a and b, the concatenation ab we call a 2025-number if ab = (a+b)^2.

eulermathematicscompetitive-programming
LeetCode 191 - Number of 1 Bits

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.

leetcodeeasydivide-and-conquerbit-manipulation
Project Euler Problem 915

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

eulermathematicscompetitive-programming
Project Euler Problem 974

Solution to Project Euler Problem 974.

eulermathematicscompetitive-programming
LeetCode 195 - Tenth Line

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.

leetcodeeasyshell
Project Euler Problem 989

Write Fn for the n-th Fibonacci number, with F1 = F2 = 1 and F{n+1} = Fn + F{n-1}.

eulermathematicscompetitive-programming
Project Euler Problem 992

Solution to Project Euler Problem 992.

eulermathematicscompetitive-programming
Project Euler Problem 306

The following game is a classic example of Combinatorial Game Theory: Two players start with a strip of n white squares

eulermathematicscompetitive-programming
Project Euler Problem 829

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.

eulermathematicscompetitive-programming
Project Euler Problem 964

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

eulermathematicscompetitive-programming
Project Euler Problem 774

Let '' denote the bitwise AND operation.

eulermathematicscompetitive-programming
Project Euler Problem 4

A palindromic number reads the same both ways.

eulermathematicscompetitive-programming
Project Euler Problem 901

A driller drills for water.

eulermathematicscompetitive-programming
Project Euler Problem 993

Solution to Project Euler Problem 993.

eulermathematicscompetitive-programming
Project Euler Problem 916

Let P(n) be the number of permutations of 1,2,3,ldots,2n such that: 1.

eulermathematicscompetitive-programming
Project Euler Problem 312

- A Sierpiński graph of order-1 (S1) is an equilateral triangle.

eulermathematicscompetitive-programming
Project Euler Problem 921

Consider the following recurrence relation: Note that a0 is the golden ratio.

eulermathematicscompetitive-programming
Project Euler Problem 931

For a positive integer n construct a graph using all the divisors of n as the vertices.

eulermathematicscompetitive-programming
Project Euler Problem 904

Given a right-angled triangle with integer sides, the smaller angle formed by the two medians drawn on the the two perpe

eulermathematicscompetitive-programming
Project Euler Problem 919

We call a triangle fortunate if it has integral sides and at least one of its vertices has the property that the distanc

eulermathematicscompetitive-programming
LeetCode 194 - Transpose File

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.

leetcodemediumshell
Project Euler Problem 893

Define M(n) to be the minimum number of matchsticks needed to represent the number n.

eulermathematicscompetitive-programming
LeetCode 9 - Palindrome Number

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.

leetcodeeasymath
LeetCode 209 - Minimum Size Subarray Sum

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.

leetcodemediumarraybinary-searchsliding-windowprefix-sum
Project Euler Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

eulermathematicscompetitive-programming
Project Euler Problem 447

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

eulermathematicscompetitive-programming
Project Euler Problem 928

This problem is based on (but not identical to) the scoring for the card game Cribbage.

eulermathematicscompetitive-programming
Project Euler Problem 972

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^

eulermathematicscompetitive-programming
LeetCode 13 - Roman to Integer

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.

leetcodeeasyhash-tablemathstring
Project Euler Problem 986

Solution to Project Euler Problem 986.

eulermathematicscompetitive-programming
Project Euler Problem 965

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

eulermathematicscompetitive-programming
Project Euler Problem 922

A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such t

eulermathematicscompetitive-programming
Project Euler Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms.

eulermathematicscompetitive-programming
Project Euler Problem 985

Solution to Project Euler Problem 985.

eulermathematicscompetitive-programming
Project Euler Problem 914

For a given integer R consider all primitive Pythagorean triangles that can fit inside, without touching, a circle with

eulermathematicscompetitive-programming
Project Euler Problem 967

nA positive integer n is considered B-trivisible if the sum of all different prime factors of n which are not larger tha

eulermathematicscompetitive-programming
LeetCode 193 - Valid Phone Numbers

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.

leetcodeeasyshell
Project Euler Problem 998

The minimum bounding square of a triangle is the smallest square that can be drawn which fully covers the triangle.

eulermathematicscompetitive-programming
LeetCode 6 - Zigzag Conversion

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.

leetcodemediumstring
LeetCode 4 - Median of Two Sorted Arrays

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.

leetcodehardarraybinary-searchdivide-and-conquer
Project Euler Problem 959

A frog is placed on the number line.

eulermathematicscompetitive-programming
Project Euler Problem 909

An L-expression is defined as any one of the following: - a natural number; - the symbol A; - the symbol Z; - the symbol

eulermathematicscompetitive-programming
LeetCode 8 - String to Integer (atoi)

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.

leetcodemediumstring
Project Euler Problem 898

Claire Voyant is a teacher playing a game with a class of students.

eulermathematicscompetitive-programming
LeetCode 2 - Add Two Numbers

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.

leetcodemediumlinked-listmathrecursion
Project Euler Problem 913

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

eulermathematicscompetitive-programming
LeetCode 198 - House Robber

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.

leetcodemediumarraydynamic-programming
Project Euler Problem 981

Solution to Project Euler Problem 981.

eulermathematicscompetitive-programming
Project Euler Problem 905

Three epistemologists, known as A, B, and C, are in a room, each wearing a hat with a number on it.

eulermathematicscompetitive-programming
Project Euler Problem 364

There are N seats in a row.

eulermathematicscompetitive-programming
Project Euler Problem 940

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

eulermathematicscompetitive-programming
Project Euler Problem 6

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

eulermathematicscompetitive-programming
Project Euler Problem 10

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

eulermathematicscompetitive-programming
Project Euler Problem 930

Given nge 2 bowls arranged in a circle, mge 2 balls are distributed amongst them.

eulermathematicscompetitive-programming
LeetCode 197 - Rising Temperature

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.

leetcodeeasydatabase
LeetCode 206 - Reverse Linked List

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.

leetcodeeasylinked-listrecursion
Project Euler Problem 812

A dynamical polynomial is a monicleading coefficient is 1 polynomial f(x) with integer coefficients such that f(x) divid

eulermathematicscompetitive-programming
Project Euler Problem 826

Consider a wire of length 1 unit between two posts.

eulermathematicscompetitive-programming
Project Euler Problem 493

70 coloured balls are placed in an urn, 10 for each of the seven rainbow colours.

eulermathematicscompetitive-programming
Project Euler Problem 640

Bob plays a single-player game of chance using two standard 6-sided dice and twelve cards numbered 1 to 12.

eulermathematicscompetitive-programming
Project Euler Problem 749

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

eulermathematicscompetitive-programming
Project Euler Problem 820

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.

eulermathematicscompetitive-programming
Project Euler Problem 177

Let ABCD be a convex quadrilateral, with diagonals AC and BD.

eulermathematicscompetitive-programming
Project Euler Problem 253

A small child has a “number caterpillar” consisting of forty jigsaw pieces, each with one number on it, which, when conn

eulermathematicscompetitive-programming
Project Euler Problem 311

ABCD is a convex, integer sided quadrilateral with 1 le AB lt BC lt CD lt AD.

eulermathematicscompetitive-programming
Project Euler Problem 245

We shall call a fraction that cannot be cancelled down a resilient fraction.

eulermathematicscompetitive-programming
Project Euler Problem 459

The flipping game is a two player game played on an N by N square board.

eulermathematicscompetitive-programming
Project Euler Problem 597

The Torpids are rowing races held annually in Oxford, following some curious rules: - A division consists of n boats (ty

eulermathematicscompetitive-programming
Project Euler Problem 84

In the game, Monopoly, the standard board is set up in the following way: !0084monopolyboard.png A player starts on the

eulermathematicscompetitive-programming
Project Euler Problem 189

Consider the following configuration of 64 triangles: We wish to colour the interior of each triangle with one of three

eulermathematicscompetitive-programming
Project Euler Problem 269

A root or zero of a polynomial P(x) is a solution to the equation P(x) = 0.

eulermathematicscompetitive-programming
Project Euler Problem 258

A sequence is defined as: - gk = 1, for 0 le k le 1999 - gk = g{k-2000} + g{k - 1999}, for k ge 2000.

eulermathematicscompetitive-programming
Project Euler Problem 154

A triangular pyramid is constructed using spherical balls so that each ball rests on exactly three balls of the next low

eulermathematicscompetitive-programming
Project Euler Problem 747

Mamma Triangolo baked a triangular pizza.

eulermathematicscompetitive-programming
Project Euler Problem 689

For 0 le x lt 1, define di(x) to be the ith digit after the binary point of the binary representation of x.

eulermathematicscompetitive-programming