instruction
stringlengths
34
53.1k
Background Page 219 of A New Kind of Science (a book by Stephen Wolfram, the creator of Mathematica) shows an interesting 2D pattern generated by constraints. The relevant section in the book starts at page 210; you can browse other pages for more context. In short, the large binary image is the result generated by 12...
Since jq is the Language Of The Month for September 2021, what general tips do you have for golfing in jq? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to jq (e.g. "remove comments" is not an answer). Please post one tip per answer.
Task: Input will consist of some text, with nested [] separating some of it into nested groups: abc[d[fgijk]nopq]rst[u[v[[w]]]xy[[[z]]]] Your task is to remove all brackets, and everything wrapped in an odd number of brackets. For example, a[b]c would remove the [], and the b inside of it. a[[b]]c, however, would only...
The string abaaba Is a palindrome, meaning it doesn't change when it's reversed. However we can split it in half to make two palindromes aba aba We could also split it up this way: a baab a And all three of those are palindromes. In fact there are only two ways to split the string into smaller strings such that non...
Content You count numbers every day (I think), and most of you know how to count properly, the one next to 1 is 2, and the next is 3, so go on, no matter what number you receive, you can easily know what next number is. Anyway, the program doesn't know, they are incredibly stupid, if I make a program shaped like 1, it ...
Though challenges involving magic squares abound on this site, none I can find so far ask the golfer to print / output all normal magic squares of a certain size. To be clear, a normal magic square of order \$n\$ is: An \$n\times n\$ array of numbers. Each positive integer up to and including \$n^2\$ appears in exactl...
Euler's numerus idoneus, or idoneal numbers, are a finite set of numbers whose exact number is unknown, as it depends on whether or not the Generalized Riemann hypothesis holds or not. If it does, there are exactly 65 idoneal numbers. If not, there are either 66 or 67. For the purposes of this challenge, we'll revoluti...
Toki Pona is a constructed language with 137ish words, designed to constrain the speaker to expressing ideas in a simple and straightforward manner, reducing ideas to more essential forms. Often, people attempt to avoid directly expressing numeric quantities in Toki Pona, opting to express them in more practical terms....
When I was a child I used to play a variation of Snap to stake soccer trading cards. "Game" is an overstatement because the only role of the players is to secretly prepare their starting piles. As the game starts there are no choices other than just perform the game algorithm. Rules There is no maximum number of player...
There are 31 positive integers that cannot be expressed as the sum of 1 or more distinct positive squares: 2, 3, 6, 7, 8, 11, 12, 15, 18, 19, 22, 23, 24, 27, 28, 31, 32, 33, 43, 44, 47, 48, 60, 67, 72, 76, 92, 96, 108, 112, 128 There are 2788 positive integers that cannot be expressed as the sum of 1 or more distinct ...
A listening party is an event where a bunch of people get together to listen to some music (like a viewing party, but for music). In the age of the internet you can do Listening Parties online with friends, where you just all hit play together. The problem is on the internet everyone is in different time-zones so you ...
The fill bucket is a tool available in many drawing tools which replaces a contiguous chunk of one color with a another color. We are going to define a fill bucket which operates on lists of non-negative integers. When used this replaces a contiguous sub-list of one integer with another selected integer. For example [...
Challenge Implement the "greedy queens" sequence (OEIS: A065188). Details Taken from the OEIS page. This permutation [of natural numbers] is produced by a simple greedy algorithm: starting from the top left corner, walk along each successive antidiagonal of an infinite chessboard and place a queen in the first availabl...
Background A Young diagram is a diagram that represents a nonincreasing sequence of positive integers using left-justified rows of squares. As an example, 5, 4, 1 is drawn as OOOOO OOOO O A Young diagram is said to be symmetric if it is identical to its transpose (reflection along the NW-SE diagonal). The above diagra...
Unlolify a lolified message! I had to ask a coworker if they wanted to have lunch with me, but we're both hackers so it could not be in a lame way. The message asking that was roughly this: please respond with 011110010110010101110011 if you'd like to join lunch today The colleague being a hacker, just responded with...
I was wondering if there is any way to assign 2 values (G and H) to say a list of ["egg", "chicken"] in Pyth. In python it would be something along the lines of G, H = ["egg", "chicken"] At the moment the shortest way I can think of would be something like =N["egg""chicken")=G@N0=H@N1 which uses the lookup function t...
Platforms are stretches of - characters separated by one or more characters. For example: ------ -- ------ - The above has 4 platforms sizes 6, 2, 6 and 1. Platforms that are not supported will fall. To be supported platforms need Jimmies. Jimmies look like this: \o/ They are three units wide. Don't ask me what ...
Problem Starting with a set of 10 coins at the start where all coins are tails up, and given n number of integers \$x_1, x_2, x_3... x_n\$ representing n rounds of coin flipping. At each round, we randomly flip \$x_i\$ number of coins at random. i.e Coins that were heads become tails, and vice versa. Within each round,...
The golfing language Jelly has a very complex and clever string compression system which I'm not going to go into depth about here. You can find a very good explanation here. Basically, Jelly's string literals are represented as “...», where ... is a string of characters from Jelly's codepage that is decoded into a bas...
To quote http://brainfuck.org/utm.b: A tag-system transforms strings over an alphabet A = {a[1], a[2], ... a[n], a[n+1]} as follows: a positive integer m is chosen, and so is a function P that maps each a[i] for 1<=i<=n to a string P(a[i]) over the alphabet A. Now: if the string being transformed has fewer than m ele...
Background K functions have a feature called projection, which is essentially partial application of values to a function. The syntax for projections is a natural extension of the regular function call syntax: f[1;2;3] / call a ternary function f with three arguments 1, 2, 3 f[1;2;] / the third argument is missi...
Consider a form of binary where digits can be any of \$1\$, \$0\$ and \$-1\$. We'll still call this "binary" because we convert the digits from base two. For example, $$\begin{align} [1, 0, -1, 1]_2 & = 1 \times 2^3 + 0 \times 2^2 + -1 \times 2^1 + 1 \times 2^0 \\ & = 8 - 2 + 1 \\ & = 7 \end{align}$$ We'll call a repre...
Given a map from arrays of integers of same size to single integers, determine if there is a set of indices such that the output is equal to the maximum of the elements at those indices for every corresponding pair. You can take the input as a map if your language support, arrays of pairs, separated 2D array of input a...
Given a string consisting of only upper and lower case letters, output an if it begins with a vowel, and a if not. For the purposes of this challenge, we'll ignore normal grammar rules, and use a very basic rule instead: if the input begins with a vowel (any of AEIOUaeiou), then output an. Otherwise, output a. Your pro...
Word equations, but not as you know it! Given a sentence which will include two numbers, numerically, and a spelt operator, in the order seen in the examples, your goal is to give the numerical answer The operators will be spelt as: "add", "minus", "times" and "divide" Any real number integer may be used, as suggested ...
Pascal's triangle is a triangular diagram where the values of two numbers added together produce the one below them. This is the start of it: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 You can see that the outside is all 1s, and each number is the sum of the two above it. This continues forever. Your challenge is to chec...
Background The 4-8-8 tiling looks like this: For the purpose of this challenge, we take the orientation of the tiling as exactly shown above. In plain English words, we take the tiling so that it can be seen as a rectangular grid of alternating octagons and squares, the upper left corner being an octagon. In order to ...
Inspired by a tweet by Nathan W. Pyle There is, now, a standard method of converting your boring, normal human name into a mysterious, ethereal Ghost Name™️. Ably described by Mr Pyle... Use your first name: a - add “t” after it e - add “boo” after it h - becomes “s” n - add “oo” after it r - add “eee” after it...
Consider the following 9 "row patterns", using 0s to represent empty cells and 1s to represent a full cell. Each pattern is associated with an integer \$n\$, such that \$0 \le n \le 8\$ (multiple [1,1,1,1,1,1]s exist as there's some difference that we don't care about): \$n\$ Pattern 0 [0,0,0,0,0,0] 1 [1,1,1,...
Al wanted to use my computer to do some simple calculations, so I lent him the use of my R terminal for a bit. He complained though, saying it wasn't set up how he liked it. I said "No problem Al, set it up how you like and I'll just revert it later." This suited Al, and I left him to it. Al isn't a big fan of online R...
This was inspired by this question. Given an \$m\times n\$ matrix of \$0\$'s and \$1\$'s, apply "gravity" to it. This means to drop down all the \$1\$'s as if they were affected by gravity. For example [[1,0,1,1,0,1,0] [0,0,0,1,0,0,0] [1,0,1,1,1,1,1] [0,1,1,0,1,1,0] [1,1,0,1,0,0,1]] Should result in [[0,0,0,0,0,0,...
Basically the tron light-cycle game as a king of the hill competition! Leaderboard Updated as of 2022-04-05 #1) Player Avoid by Agent Biscutt #2) Dodge West by Imanton1 #3) Space Finder by Spitemaster #4) Blind Bot by TheSilican Judge/Leaderboard Website The Game Players will write bots that compete in a light-cyc...
Context : Suppose you have a sheet of paper measuring 8 x 10. You want to cut it exactly in half while maintaining its rectangular shape. You can do this in two ways. You can cut it in half preserving its long dimension of 10 (for our purpose we will refer to this as long cut from now on). Example : $$ [8, 10] \right...
Let's start with the natural numbers [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,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,...
Backstory I was fiddling around with the Evolution of Trust and thought of this.Warning: I recommend you go check it out first before attempting this challenge. Summary for people who haven’t played A quick summary of what it says on the site: there is a machine. If you put in one coin, your opponent gets three coins (...
Recently, I created a binary word search that got me working with grids. It was fun, so I wanted to create some more similar content. Meet Pythagoras' Golfing grid: Each of d, e, f, g, h, i, j, k and T represent a numeric value. Now consider an orthogonal triangle along the lower diagonal of this grid (so the vertical...
Let's go for a rollercodester ride The objective of this challenge is to create a program that is run recursively through several languages of your choice. The output of the first iteration becomes the code for the second iteration, et. cetera. You choose the language sequence, but each unique language may be used onl...
Write a program that groups a string into parentheses cluster. Each cluster should be balanced. Examples : split("((())d)") ➞ ["((()))"] split("(h(e(l)l)o)(w(o)r)l(d)(w)h(a(t)(s)u)p") ➞ ["((()))", "(())", "()", "()", "(()())"] split("((())())(()(()()))") ➞ ["((())())", "(()(()()))"] Input may contain letters other t...
The basis vectors for geometric algebra are $$(e_0=1), e_1, e_2,\dots,e_n$$ They all square to 1 (we do not consider vectors which square to -1 or zero) $$e_i \cdot e_i = 1$$ They are associative and anticommutative (except \$e_0=1\$ which is associative and commutative) $$e_i \cdot e_j =-e_j \cdot e_i \: \; (i\neq j);...
For the purposes of this challenge a substring \$B\$ of some string \$A\$ is string such that it can be obtained by removing some number of characters (possibly zero) from the front and back of \$A\$. For example \$face\$ is a substring of \$defaced\$ \$ de\color{red}{face}d \$ This is also called a contiguous substri...
Pascal's triangle is a triangular diagram where the values of two numbers added together produce the one below them. This is the start of it: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 You can see that the outside is all 1s, and each number is the sum of the two above it. This continues forever. Your challenge is to coun...
Given a permutation of the alphabet and an input string, encrypt the input string by replacing all characters with the one's you've been given. The capitalization should be kept the same and non-letters are not to be changed. [hnvwyajzpuetroifqkxmblgcsd], "Hello, World!" -> "Zytti, Giktw!" As [abcdefghijklmnopqrstuvwx...
This was inspired by Apply gravity to this matrix Your challenge is to input a matrix with non-negative one-digit integers and drop down the 1's down 1 column, the 2's down 2 columns, the 3's down 3 columns, and so on. Once a number has been moved down and there is no number to take its original place, replace that slo...
Given \$n, m\ge 1\$. There are \$n\$ balls. Do \$m\$ moves, each choose a ball (maybe also the first one), and exchange with the one currently on the first place. At the end, the order of balls should be the same as the initial state. You can either output all possibilities, or a random one provided all possibilities h...
I have a small pill box of \$n\$ slots. (Think of it as a linear one like the image below, but not necessarily having 7 slots.) Each slot has at most one pill. Every day, I take one of two actions: take one pill from the pill box, or refill the pill box. The order of taking a pill alternates between left-to-right and ...
@BeastlyGerbil presents, the world's very first MOBIUS SUDOKU: Google Sheets version (The left most square backs onto the right most square, and the middle squares back onto each other. The ends are then attached as indicated.) RULES: Normal sudoku rules apply for rows and boxes - boxes are split into groups of 3...
Given a string containing only the characters -, |, + and newline determine the longest straight line contained in it. A straight line is either an uninterupted run of -s and +s in a single row or an uninterupted run of |s and +s in a single column. So for example: | | ---- | --+-- ...
Challenge Given input as a list/array of natural numbers that each represent the floor of a class a student has to go to, sort the numbers in a way such that the MAD (mean average deviation) number of flights between classes is minimized, thus saving energy and preventing the chance of being late to a class. When sorte...
An example will easily explain this to you. Suppose an array [1,2,3,4,5] Step 1 1 2 3 4 5 ----+---- Step 2 5/ 4/ 1 2 3 / ----+/ Step 3 5| 4| 1 2 3| ----+| Step 4 5\ 4\ 1 2 3\ ----+-\ Step 5 Take the sum of face-to-face elements 6 6 3 You just successfully folded an array 1 time. 2 times f...
Inspired by How to write down numbers having an infinity of decimals? Link Background From Wikipedia: for almost all real numbers \$x\$, coefficients \$a_i\$ of the continued fraction expansion of \$x\$ have a finite geometric mean that is independent of the value of \$x\$ and is known as Khinchin's Constant. Khinchin...
Background Flow Free is a series of puzzle games whose objective is to connect all the same-colored pairs of dots on the grid. In this challenge, we consider the original game on a rectangular grid (no variations like bridges, warps, or hexagonal grids). A puzzle in Flow Free might look like this: Puzzle Solution ......
Your task is to create a good multiplication table for others to use. Given an integer \$n\$, generate a multiplication table that displays products up to \$n×n\$. You should start with \$2×2\$ as 1 times any number is itself and that is reflected in the row/column indices. Scientific notation and floating-points are N...
The objective Given the non-negative integer \$n\$, output the value of the hyperfactorial \$H(n)\$. You don't have to worry about outputs exceeding your language's integer limit. Background The hyperfactorial is a variant of the factorial function. is defined as $$ H(n) = 1^{1} \cdot 2^{2} \cdot 3^{3} \cdot \: \cdots ...
Getting the area covered by a rectangle is really easy; just multiply its height by its width. However in this challenge we will be getting the area covered by multiple rectangles. This is equally easy ... so long as the rectangles don't overlap. If the rectangles don't overlap the total area covered is the sum of th...
Every digital clock contains a small creature that has to advance the time every minute [citation needed]. Due to the popularty of digital clocks and the popularity of catching them in the wild, they are nearly extinct in nature which is why in this challenge we try to automate this task: Given your string of a given t...
This question is a part of the lean LotM. A ring is a type of structure that takes the rules of addition and multiplication we are familiar with and abstracts them, so we can reason about them. To do this we state a number of expected properties as axioms and see what we can say about systems that follow these axioms....
There is a "sorting" algorithm often called Stalin Sort, where instead of sorting an array, you just remove any items that are out of order. In this challenge, you'll implement part of a sorting algorithm which recursively sorts the removed items, then merges the arrays to form one (properly sorted) array. Algorithm Ta...
The Pascal's triangle and the Fibonacci sequence have an interesting connection: Source: Math is Fun - Pascal's triangle Your job is to prove this property in Lean theorem prover (Lean 3 + mathlib). Shortest code in bytes wins. import data.nat.choose.basic import data.nat.fib import data.list.defs import data.list.nat...
Ungolfed, ugly, horrible proof to help you make progress on this challenge: https://gist.github.com/huynhtrankhanh/dff7036a45073735305caedc891dedf2 A bracket sequence is a string that consists of the characters ( and ). There are two definitions of a balanced bracket sequence. Definition 1 The empty string is balanc...
Inspired by Is this Flow Free puzzle trivial? by @Bubbler. Lengthy chunks of this challenge are borrowed from there. This may be one step of a solution for the linked challenge, depending on chosen strategy. Background Flow Free is a series of puzzle games whose objective is to connect all the same-colored pairs of dot...
Lean is a theorem prover and programming language. It's also as of writing the Language of the Month! What tips do people have for golfing in Lean? As always, tips should be specific to to Lean (e.g. "Remove comments" is not an answer), and stick to a single tip per answer.
The title is an homage of the Natural Number Game, which is a nice interactive tutorial into proving certain properties of natural numbers in Lean. Given that the previous two were slightly too involved (either mathematically or technically) for newcomers to Lean (i.e. the vast majority of CGCC community), I decided to...
Inspired by Is this Flow Free puzzle trivial? by @Bubbler. Lengthy chunks of this challenge are borrowed from there. This may be one step of a solution for the linked challenge, depending on chosen strategy. Challenge Given an array of digits 1-9 and a padding character of your choice, output the border of the shape ma...
The title is an homage of the Natural Number Game, which is a nice interactive tutorial into proving certain properties of natural numbers in Lean. The definitions used in Lv1 will be reused here. I've done some improvements: Now it starts with import tactic, which means you can freely use powerful mathlib tactics. I...
Background The number of values for a given type is called the cardinality of that type, and that of type T is written as |T|. Haskell and a few other languages have a certain set of enum types, each of which has a small finite number of values (the exact names vary, so this challenge uses some arbitrarily chosen names...
Create a program which prints itself, followed by an additional program. This additional program should print the first program, itself, and then a third program. This continues until the nth program, which prints every program in order up to itself, but fails to print a successor. All programs output by your code shou...
Sometimes authors will write (s)he as a stand in for she or he and for some reason they don't want to use singular they. This is ok for the nominative but doesn't work so well when you want to write "her or him". You can write h(er)(im) which covers both cases but gives two extra "pronouns" h her him herim In formal...
Background A fractal sequence (Wikipedia; MathWorld) is an infinite sequence of positive integers meeting the following conditions: Each positive integer appears infinitely many times in the sequence. Before the first occurrence of a number \$i > 1\$, every number smaller than \$i\$ appears at least once. Between co...
Part of the lean Language of the Month A pong* is a set \$P\$ with an operation \$+\$, that satisfies the following properties: \$ \forall a, b \in P : (b + b) + a = a\\ \forall a, b \in P : a + (b + b) = a\\ \forall a, b, c \in P: a + (b + c) = (a + b) + c \\ \$ This makes a pong*, just a group where every element is ...
Introduction: Although we have a lot of challenges where swapping two items in a list is a subtask, like Single swaps of an array; Swap to Sort an Array; \$n\$ swaps into a nop; etc., we don't have the simple challenge of just swapping two items given a list and two indices. Input: A list with some positive integers \$...
Prefix normal words arise in the context of binary jumbled pattern matching. A binary word \$w\$ consisting of \$0\$s and \$1\$s is said to be prefix normal * if, among all of its substrings, none contains more \$1\$s than the prefix of \$w\$ of the same length does. In other words, if \$w\$ contains \$n\$ \$1\$s then ...
Definition (from Wikipedia) A Pythagorean triple consists of three positive integers a, b, and c, such that a² + b² = c². The typical example of a Pythagorean triple is (3,4,5): 3² + 4² = 9 + 16 = 25 which is 5² Task: Given an integer number c, write a program or function that returns the list of pythagorean triples wh...
Background Scrabble is a word game in which players collaboratively build a board consisting of letter tiles that spell words. Each word must be connected to another word, and players gain points based on the letters they use and where they are placed. Words can be spelled either from left-to-right or top-to-bottom, an...
Background One kind of river-crossing problems involves two kinds of animals. One such problem reads like this: (all wordings, including animal species, are arbitrary) A farmer has to cross a river with three chickens and three dogs. There's a boat which can only fit the farmer and at most two animals. On either side ...
You are a historian studying a long forgotten language. You have just discovered a clay tablet which seems to list all known words in the language, in alphabetical order. Your task is to find this alphabet's order, if it exists. The Task Given an ordered list of words, try to output an ordered list of characters such t...
Let \$S \subset \mathbb N_{\geq0}\$ be a subset of the nonnegative integers, and let $$ S^{(k)} = \underbrace{S + S + \dots + S}_{k\ \textrm{times}} = \{ a_1 + a_2 + \dots + a_k : a_i \in S\}. $$ For example, $$\begin{align} \{1,2,3\}^{(2)} &= \{1+1, 1+2, 1+3, 2+1, 2+2, 2+3, 3+1, 3+2, 3+3\}\\ &=\{2,3,4,5,6\} \end{align...
Information Given a non-negative odd integer (let's call it \$n\$), find the number of all possible paths which covers all squares and get from the start to end on a grid. The grid is of size \$n\$×\$n\$. The start of the path is the top left corner and the end is the bottom right corner. You have to count the number ...
Output the flattened version of the sequence A297359, which starts like the following: 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 2, 4, 6, 4, 2, 1, 6, 10, 10, 6, 1, 1, 7, 16, 20, 16, 7, 1, 3, 8, 23, 36, 36, 23, 8, 3, 3, 11, 31, 59, 72, 59, 31, 11, 3, 1, 14, 42, 90, 131, 131, 90, 42, 14, 1,... ---------------- 1, ...
Gobar primes (A347476) are numbers which give a prime number when 0's and 1's are interchanged in their binary representation. For example, \$10 = 1010_2\$, and if we flip the bits, we get \$0101_2 = 5\$ which is prime. Therefore, 10 is a Gobar prime As simple as that: print the series with any delimiter. Shortest code...
Input 4 integers w, x, y, z from the range -999 to 999 inclusive where none of the values is 0. Output 4 integers a, b, c, d so that aw + bx + cy + dz == 0 where none of the values is 0. Restrictions Your output should be the solution with the smallest sum of absolute values possible. That is the smallest value of \$|...
Inspired by a question (now closed) at Stack Overflow. Given a square matrix, let its double trace be defined as the sum of the entries from its main diagonal and its anti-diagonal. These are marked with X in the following examples: X · · X · X X · · X X · X · · X X · · · X · X · X · · · X · · · X · X · X · · · X No...
Introduction This challenge is about producing a code to count the frequency of bigrams in a text. A bigram is two consecutive letters in a text. For instance 'aabbcd' contains the bigrams aa, ab, bb, bc, cd once each. Counting bigram frequencies is super useful in cryptography. In a brute force algorithm, this code ma...
Challenge Build the Wheat Wizard's stove using 2-input NAND gates. The solution with the fewest NAND gates wins. Externally, it works in the following way: (the first line is added from the original spec for physical output) It has 10 levels, from 0 to 9. The display has 9 lights, and if the current level is L, exactl...
In this challenge, you'll create some programs which behave similarly to genes. When you run one, it will return one of its two "alleles" (a half of its source code), and concatenating any two alleles from your programs will result in a new, functioning program (which returns its own alleles). As an example, say you wr...
We all know about the Fibonacci sequence. We start with two 1s and keep getting the next element with the sum of previous two elements. n-bonacci sequence can be defined in similar way, we start with n 1s and take the sum of previous n elements to get the next element. Challenge Given a positive integer m > 1, output t...
Background Zeckendorf representation is a numeral system where each digit has the value of Fibonacci numbers (1, 2, 3, 5, 8, 13, ...) and no two consecutive digits can be 1. Nega-Zeckendorf representation is an extension to this system that allows encoding of all integers, not just positive ones. Its base values are ne...
Background The recurrence of the Fibonacci sequence is defined as $$ f(n+2) = f(n+1) + f(n) $$ From this recurrence alone, the following gap formulae (recurrences relating three terms with certain amount of gaps) can be derived: $$ f(n+4) = 3f(n+2) - f(n) \\ f(n+6) = 4f(n+3) + f(n) \\ f(n+8) = 7f(n+4) - f(n) $$ You mig...
Challenge Given two integer values \$a \ge 2\$ and \$0 \le b < a\$, generate a \$(2a-1) \times (2a-1)\$ matrix consisting of the integers 0, 1, and 2 as follows: Create a checkerboard of 0s and 1s of the given size, corners being 0. If \$b > 0\$, overwrite the checkerboard with 2s in the X shape at the center, each le...
All variables in this question are integer valued. Input 4 integers w, x, y, z. They can be positive or negative and will be less than 1048576 in absolute value. Output The general solution to the equation. \$ aw+bx+cy+dz = 0 \$. The variables \$a, b, c, d\$ must all be integer values. Output format Your output should ...
Write a function that accepts a rectangular grid of ids in any reasonable format, for example a multi-line string: IIILOO ILLLOO and a string or list of box drawing charcters such as: ' ═║╔╗╚╝╠╣╦╩╬' or [0x20, 0x2550, 0x2551, 0x2554, 0x2557, 0x255a, 0x255d, 0x2560, 0x2563, 0x2566, 0x2569, 0x256c'] (see below for more...
The goal is to create a generator generator [...] generator generator comprehension. The generator must be created via generator comprehension. The following expression must be valid for any number of nestings: next(next(next(next(next(generator))))). The winner is whoever achieves this with the fewest number of byte...
Based on this game. Description : Based on Wikipedia's description. The 24 Game is an arithmetical card game in which the objective is to find a way to manipulate four integers so that the end result is 24. For example, for the card with the numbers 4, 7, 8, 8, a possible solution is : \begin{equation} ( 7 − ( 8 ÷ 8 ) ...
Challenge Generate the 2D sequence of bits of A141727. (Allowed I/O methods explained at the bottom.) 1 1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 1 0 1 0 1 0 0 0 1 1 0 0 1 1 1 ...
Given an integer \$n \geq 2\$, print a triangle of height \$n\$ of (triangles of height \$n\$ of asterisks), as in this SO question. For \$n=2\$, print: * *** * * * ********* For \$n=3\$, print: * *** ***** * * * *** *** *** *************** * * ...
I was trying to write a short MIPS32 code for computing the median of three registers. The rules: Assume that some values are pre-loaded into $t0, $t1, $t2. The median of the three values should be placed in $t0. No branches are allowed, but otherwise any instruction is okay. You may arbitrarily modify the values of a...
There is a division-free algorithm for computing determinants published by R.S.Bird in 2011 that uses only matrix multiplications. Given a \$n×n\$ matrix \$X\$, the matrix \$Y=μ(X)\$ is another \$n×n\$ matrix which entries are given by $$Y_{i,j} = \begin{cases} 0 & \text{ if } j < i \\ X_{i,j} & \text{ if } j > i \\ -(...
A triplet of real tensors \$(A,B,C)\$ of size \$\gamma \times \gamma \times \sigma\$ represents a matrix multiplication algorithm with \$\sigma\$ elementary multiplications iff the following function evaluates to zero: $$ \text{error}(A,B,C) \equiv \sum_{i,j,k,l,m,n=1}^\gamma\left(\sum_{r=1}^{\sigma}{A_{ij}^r B_{kl}^r ...
Given a positive integer \$n\$ and another positive integer \$b\$ (\$1 < b < 36\$), return the number of digits/length of \$n\$ in base \$b\$ 1597 16 -> 3 1709 9 -> 4 190 29 -> 2 873 24 -> 3 1061 27 -> 3 289 26 -> 2 1575 34 -> 3 1135 15 -> 3 1161 22 -> 3 585 23 -> 3 1412 23 -> 3 1268 14 -> 3 714 12 -> 3 700 29 -> 2 100...
Given two integer matrices a and b, your challenge is to replace any occurences of b in a with a matrix of the same size filled with 0s. For example: Given: a: [ [1, 2, 3], [4, 3, 2], [3, 5, 4] ] b: [ [3], [2] ] b occurs once in a: [ [1, 2, 3], [4, 3, 2], [3, 5, 4] ] Fill that area with zeroes: [ [1,...
Similar to this. Input a list and rotate N numbers in it given their indices. The following example uses 1-indexing, but feel free to use either. In other words, take a list of indices and a list of numbers: [1,2,3,4,5,6,7] [1,3,6] Separate out the elements at those indices: [ 2 4 5 7] 1 3 6 Rotate those...