instruction
stringlengths
34
53.1k
Information Create a diagonal line given its length (let’s call the variable, say, \$n\$ where \$n > 0\$) The diagonal line starts from the top left and goes to the bottom right. You must use the ASCII character \ for the line. The input number can be given from STDIN or if your program doesn’t support that, use a har...
Program the sequence \$R_k\$: all numbers that are sum of square roots of some(maybe one) natural numbers \$\left\{\sum_{i\in A}\sqrt i\middle|A\subset \mathbb{N}\right\}\$, in ascending order without duplication. Outputting zero is optional. You should do one of: Take an index k and output \$R_k\$, either 0 or 1 inde...
Task Given a non-negative number, check if it's odd or even. In case it's even, output that number. Otherwise, throw any exception/error that your language supports, and stop the program. Example with Python Input: 1 Output: Traceback (most recent call last): File ".code.tio", line 1, in <module> IfYouWantThenThr...
Introduction Fischer random chess, also known as Chess960 for the 960 valid starting boards, is a variant of chess where each player's pieces are randomly shuffled at the start. As a reminder, each player gets 8 pawns, two rooks, two knights, two bishops, one queen, and one king. For this challenge, you don't need to k...
The Prisoner's Dilemma, but with 3 choices, and the payoffs are random! Each round, your bot recieves a 3x3 grid and chooses a row to play. The grid might be this: 4 5 7 3 1 9 9 9 0 Each number in the grid is between 0 and 10 (inclusive). Your score for the round is grid[your_play][their_play], and your oppone...
Given a positive number \$n\$ we call another (not same as n) positive number \$m\$ good if we insert same digits in both n and m and the resulting fractional value is same. $$m/n = m_{\text{transformed}}/n_{\text{transformed}}$$ $$or$$ $$m*n_{\text{transformed}} = m_{\text{transformed}}*n$$ Clarifications: No leading...
Picolisp has a feature called "super parentheses": Brackets ('[' and ']') can be used as super parentheses. A closing bracket will match [all parentheses to and including] the innermost opening bracket, or [if there are no unmatched opening brackets] all currently open parentheses. src Taking a string containing only...
From Codidact with permission. Description APL trains are a series of functions, that get applied to an argument in this way: (f g) x = f g x here f and g are prefix functions (f g h) x = (f x) g (h x) here f and h are prefix functions, while g is an infix function (a b c d e f) x = (a (b c (d e f))) x = a (b x) c (d x...
Challenge Choose any number of languages. Call this set L. Write a program so that running it in any language in L produces an interpreter for a different language in L. Each language in L must have exactly one interpreter for it. This is to prevent, for example, Nothing or Text being part of L and all interpreters be...
Given infinite different integers, order them into a sequence \$a_1, a_2, a_3, ...\$ such that \$a_i>a_{i+1}\$ iff \$i\$ is even(or odd, as long as it's constant for all possible inputs and all \$i\$). In other word, make the sequence go alternately up and down (or down first, as long as it's constant). Examples: ℤ => ...
Background Combinatory logic is a system where a term is written using a finite set of combinators and function application between terms, and reduction rules are defined for each combinator. The well-known S and K combinators have the following reduction rules: $$ \begin{aligned} S\;x\;y\;z & \overset{S}{\implies} x\;...
This is not just another challenge asking you to color random maps... In this challenge, you are asked to write a program that is actually used in the formal proof of the Four Color Theorem. First I shall describe the challenge without any background or motivation, for the impatient. A chromogram is a list made of the ...
Challenge Make a triangle of numbers like below. How to? Let say we get a numbers in the form of ab, for example 12. We then create a triangle like below: Sorry for my bad drawing! First we have 12, and we take sum of the two numbers 1 and 2, which is 3. In case the sum of two numbers are greater than 9, we just take ...
Given an integer \$ n \$ \$ (n \ge 1) \$, return/output the total number of set bits between \$ 1 \$ and \$ n \$ inclusive. To make the problem more interesting, your solution must run with a time complexity of \$ \mathcal{O}((\log n)^k) \$ or better, for some constant \$ k \$ (AKA poly-logarithmic time complexity). Th...
Inspired by this video by Ben Eater. This challenge forms a pair with Encode USB packets. The USB 2.0 protocol uses, at a low level, a line code called non-return-to-zero encoding (specifically, a variant called NRZI), in which a stream of bits is encoded into a stream of two electrical level states J and K. Decoding w...
Lexicographic Ordering For this challenge we will be talking about the lexicographic ordering of strings. If you know how to put words in alphabetical order you already understand the basic idea of lexicographic ordering. Lexicographic ordering is a way of ordering strings of characters. When comparing two strings lex...
Take a line of input (function arguments or stdin, etc.). Remove comments in it, where a comment starts and ends with ". Do not remove comments in string literals, which start and end with '. String literals do not contain escapes, because smalltalk has nice, easily lexable syntax ;). Output this string. The number of...
Given an integer \$1 < n < 10 \$ generate a table like below. For \$n = 5\$, 1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 4 4 4 4 5 5 5 5 5 5 For \$n = 8\$, 1 2 3 4 5 6 7 8 2 2 3 4 5 6 7 8 3 3 3 4 5 6 7 8 4 4 4 4 5 6 7 8 5 5 5 5 5 6 7 8 6 6 6 6 6 6 7 8 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 Shortest code wins! Trailing whitespace allowed ...
But Is It Art? is an esolang created by ais523, where one step is break the program into orthogonally connected "tiles": A BBBB A B B AA CC A CC Each separate letter shows a different tile. Interestingly, programs in But Is It Art? only rely on the orientations of the tiles themselves, not their placement. This means...
You're a plumber working on a house, and there's some pipes that must be connected at weird angles. You have 8°, 11.25°, 22.5°, 45°, and 90° fittings at your disposal, and you want to use as few as possible to match the angle as closely as possible. Goal Match the desired angle as closely as possible, with as few fitt...
Inspired by this video by Ben Eater. This challenge forms a pair with Decode USB packets. The USB 2.0 protocol uses, at a low level, a line code called non-return-to-zero encoding (specifically, a variant called NRZI), in which a stream of bits is encoded into a stream of two electrical level states J and K. Encoding w...
The Collatz sequence Given a positive integer \$a_1\$, the Collatz sequence with starting value \$a_1\$ is defined as \begin{equation} a_{n+1} = \begin{cases} a_n/2 & \mathrm{if}\ a_n\ \mathrm{is}\ \mathrm{even} \\ 3a_n+1 & \mathrm{if}\ a_n\ \mathrm{is}\ \mathrm{odd}. \end{cases} \end{equation} It is conjectured that, ...
5 Years ago, this happened, and then it became sort of a meme. Challenge The Challenge today is, to check if a "magic square" is a valid parker square. What is a Real Magic square? All the numbers must be natural or sometimes 0 The sum of rows, columns and diagonals must be same. There must be no repeating numbers Wh...
Sandbox Given a boolean matrix representing my grass field, sheep length \$n\$ and wool thickness \$k\$, you will have to count my sheep. A sheep is a single independent unbroken line of sheep length \$n\$ and thickness \$k\$. #|##|# | # #| | #|# are all valid sheep for \$n=2,k=1.\$ ##|###|## | ## ##|###| ## | ## ...
Background The fixed-point combinator \$\textsf{fix}\$ is a higher-order function that computes the fixed point of the given function. $$\textsf{fix}\ f = f\ (\textsf{fix}\ f)$$ In terms of programming, it is used to implement recursion in lambda calculus, where the function body does not normally have access to its ow...
Risky is a new language of mine, which features an interesting form of tacit programming. In this challenge, you'll take a Risky program as input, and visualize the parsing. No knowledge of Risky is needed for this challenge, but it's a pretty interesting language so I'd recommend trying it :p. Task Risky's parsing is ...
Multi-dimensional chess is an extension of normal chess that is played on an 8x8x8x8... "board". In normal 2D chess, a knight's move is a movement by a vector of \$ \begin{bmatrix} \pm 2 \\ \pm 1 \end{bmatrix} \$ or \$ \begin{bmatrix} \pm 1 \\ \pm 2 \end{bmatrix} \$, as long as it doesn't cause the knight to go outside...
Task Given a square array of 0s and 1s, determine whether or not there exists a path of 1s connecting the leftmost and rightmost columns. A path can take steps of one unit up, down, left or right, but not diagonally. Every symbol on the path must be a 1, and it must start somewhere in the first column and end somewhe...
Intro You like cats. Naturally, you like cat’s games in tic-tac-toe. So, you’ve come up with a little party trick. You ask someone what square on the board they want you to make a move in. And you ask someone else on which turn they want you to make that move. You also let that person decide whether you play Xs or Os. ...
Mr. Binary Counterman, son of Mr. Boolean Masker & Mrs. Even Oddify, follows in his parents’ footsteps and has a peculiar way of keeping track of the digits. When given a list of booleans, he counts the 1s and 0s separately, numbering the 1s with the odds & the 0s with the evens. For example, when he looks at 1 1 0 0 1...
We'll call the consecutive distance rating of an integer sequence the sum of the distances between consecutive integers. Consider 2 9 3 6 8 1. 2 9 3 6 8 1 <----5----> <-2-> <--3--> \$2\$ and \$1\$ are consecutive integers, and their distance apart in the sequence is \$5\$. \$2\$ and \$3\$ are consecutive integers, a...
Consider a binary operator \$*\$ that operates on a set \$S\$. For simplicity's sake, we'll assume that \$*\$ is closed, meaning that its inputs and outputs are always members of \$S\$. This means that \$(*, S)\$ is a magma Let's define some basic terms describing the properties of \$*\$. We can say that \$*\$ can have...
Background Binomial transform is a transform on a finite or infinite integer sequence, which yields another integer sequence. The binomial transform of a sequence \$\{a_n\}\$ is given by $$s_n = \sum_{k=0}^{n}{(-1)^k \binom{n}{k} a_k}$$ It has an interesting property that applying the transform twice will yield the ori...
Given a list of coordinate pairs, output the Trapezoidal Riemann Sum of the values given between the first and last x-coordinates. You will be given a sorted list of coordinate pairs, like this: [ [1,2], [3,5], [5,11] ] Note that x-coordinates will always be in increasing order, ys may not. My way to do this is ...
Your challenge is to write a function/program that takes a matrix of integers m and a number n as input and: Splits m into n by n chunks Replaces each chunk with the most common value in that chunk (In case of a tie, any of the tied values is fine). Outputs the resulting matrix. Note: You can take either the size ...
Task Given a list of nodes representing a binary tree of positive integers serialized depth-first, return a list of nodes representing the same tree serialized breadth-first. To represent an absent child, you may use null, 0, 'X', Nothing, [], or any other value that is distinct from your representation of a node's val...
Inspired by the problem with the same name on Puzzling SE by our very own Dmitry Kamenetsky. You are to find the largest number that only uses every digit pair once, in a given base. For example, in ternary we have 2212011002. Challenge: Given a base from 2-10, output the largest number in that base with no repeating d...
Introduction In a standard* (e.g. not 2020) tax year, estimated payments are due quarterly according to the schedule outlined in Publication 505. Payment Period Due Date January 1 – March 31 April 15 April 1 – May 31 June 15 June 1 – August 31 September 15 September 1 – December 31 January 15 * Saturd...
Inspired by Wzl Determine if a given square binary matrix has exactly one row or column consisting of entirely 1s, and the rest of the matrix is 0s. For example, these are all true: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 ...
If you have ever looked at an objdump of a C++ program, you have likely seen something like this: _ZN3foo3bar3bazI6sampleEE3quxvi3foo This is a C++ mangled symbol, which encodes the namespaces, classes, and function/template arguments, using the Itanium ABI. Specifically, it is for the following function: void foo::ba...
Background So, nowadays the popular Prisoner's Dilemma variant is the Prisoner's Trilemma, where there are three options. I can easily see that being increased, so I figured Why settle for three options, when we can have INFINITE options? Therefore, I created the Floating Point Prisoner's ?Lemma. Equations: Each roun...
Related: Counting polystrips Background Link-a-Pix is a puzzle on a rectangular grid, where the objective is to reveal the hidden pixel art by the following rules: Connect two cells with number N with a line spanning N cells, so that the two cells are at the two ends of the line. The number 1 is considered connected t...
Print the following text and nothing else: <html> <body> <p>HTML is kinda annoying</p> </body> </html> I'm happy I'm not a web developer. The catch? Your code must fit the template: print(<?>), where ? can be any group of characters. You can paste your completed code (with the print(<>) part) into this Scast...
(Based on this closed challenge, related) Given an integer n > 1, draw a grid composed of the characters: "-" "+" and "|". However, since I want the grid to look nice, the horizontal component should be 2 wide. Trailing spaces for each line are not required. Examples: n = 2 | --+-- | n = 3 | | --+--+-- | ...
In November 2019, Alon Ran published a particularly lovely sequence in the OEIS, A329126: \$a(n)\$ is the lexicographically earliest string of digits which yields a multiple of \$n\$ when read in any numeric base. 1, 110, 101010, 111100, 100010001000100010, 1111110, 10000010000010000010000010000010000010, 11111111000,...
The Len(language,encoding) family of languages is a variety of Lenguage derivatives. To encode a program into a Len language, you replace every character with its representation in a certain encoding, then turn that into a giant integer. Your challenge is to write a function or program that encodes your language into a...
Sandbox Inspired by a Codingame challenge I tried (and failed at) about a month ago. Given a binary tree of words, say: HELLO / \ WORLD EATING / / \ ARCH IDAHO GUARD / DOOZY / ...
This is an ascii-art challenge where you will draw ascii-art showing a person "jumping" off the top of a building. The building Input given will be a group of rectangular buildings. You may assume buildings are not "stacked on top of each other", hence only one row of buildings. This is the standard format of a buildi...
Your challenge is to construct a proper quine using as few distinct characters as possible. Scoring Your score is equal to the number of distinct characters in your code, aiming to minimise this. Standard quine rules apply.
According to Wikipedia, In mathematics, a natural number \$n\$ is a Blum integer if \$n = p \times q\$ is a semiprime for which \$p\$ and \$q\$ are distinct prime numbers congruent to \$3 \bmod 4\$. That is, \$p\$ and \$q\$ must be of the form \$4t + 3\$, for some integer \$t\$. Integers of this form are referred to a...
There's only one question for machine-language golfing, and it's for the ia32 and amd64 architectures. Here's one for a predecessor of them: the Zilog Z80! The ISA is available here. As usual, if your tip is only applicable to a certain environment/calling convention, please indicate that in your answer. Only one tip ...
Given a positive integer \$n\$, output \$n\$ 2D bool images with the same width and height such that: Each image should be 4-connected, i.e. for each two pixels that are true, you can start from one and go up, down, left and right for some times to the other pixel, only passing through true pixels. Each image should h...
Say I have a pile of boxes: AAA BBB I can create it in two steps: BBB ↓ (empty) --- AAA ↓ BBB But with this: AB BA I need three steps: A ↓ (empty pile) --- BB ↓ A --- A ↓ B BA Your challenge Given a pile of boxes, output the minimum number of steps needed to create that pile. A step consists of dropping a ro...
Desmos is mainly used as an online graphing calculator, but its graphical and mathematical functionalities can also be applied in certain coding challenges. I know not that many people use Desmos on this site, but for the people that do, what are some tips for golfing in Desmos? As usual, please keep the tips somewhat ...
The task is to provide code that evaluates to 0.5 numerically, i.e. the output must be recognized by your chosen language as a numeric value (Number, float, double, etc), not as a string. The catch, the characters 0 through to 9 cannot be used. PLEASE NOTE: This IS NOT a golfing challenge, this is a popularity contest,...
Background Minkowski addition is a binary operation on two sets of points (usually geometric objects) in the Euclidean space. The Minkowski sum of two sets \$A\$ and \$B\$ is formally defined as follows: $$ A+B = \{\mathbf{a}+\mathbf{b}\,|\,\mathbf{a} \in A,\ \mathbf{b} \in B\} $$ To say in plain English, given the ori...
Think of cleave as the conceptual inverse of map. If map applies a function to each number in a list... map([1, 2, 3], x -> x * 5) -> [5, 10, 15] then cleave applies each function in a list to a number. cleave(5, [x -> x * 2, x -> x - 1, x -> x * x]) -> [10, 4, 25] More formally, given: \$n\$, an integer, and \$L\$, a...
You are given a polynomial function, in the following format: \$x = (c_0 * y^0) + (c_1 * y^1) + (c_2 * y^2) + ... + (c_n * y^n)\$ where \$c_n\$ stands for the coefficient of the \$n^{th}\$ power of \$y\$ You have to plot the equation on a \$10 * 10\$ ASCII matrix. The value must be floored to an integer before plotting...
Recursively prime-encoded integers Consider \$11681169775023850 = 2 \times 5 \times 5 \times 42239 \times 5530987843\$. This isn't a nice prime factorisation, as \$42239\$ and \$5530987843\$ make it difficult to store this factorisation in a small manner. Being primes, we can't then factorise them, but we can factorise...
Write a program which takes two arrays of positive integers as input. One of them (your choice which) will have one item missing compared to the other. Your program must figure out what is missing. Rules You can choose which array has one missing: You can take ordinary then missing or vice versa. Arrays may contain dup...
I like my job, but sometimes it can get a bit tedious and boring. As motivation, I want to know how many hours of work are left before I finally get my two days of weekend and relaxation. I work every day from Monday to Friday, totalling 38.5 hours, starting at 9am and ending at 6pm. Every day - except Friday - I get ...
Background As far as we can tell from trying everything (besides cheating with ZWSPs), you can't type `\ in Stack Exchange chat. However, you can type \` by doing `\\``. So, if you want to tell someone in chat how to type backslash-backtick, you'd need to type out `\`\\`\`` to format `\\`` into a codeblock. Challenge Y...
Background A checkered tiling of a rectangular grid is a tiling using some polyominoes, where each region can be colored either black or white so that no two polyominoes sharing an edge has the same color. In graph-theoretic terms, the chromatic number of the adjacency graph is 2. Terminology adapted from a Fillomino v...
The input for the continuous knapsack problem is as follows. For each item 1...n we are given a positive weight and profit. Overall we are also given a positive capacity which is the maximum weight we can carry. The goal is to pick items so that the profit is maximized without exceeding the capacity. This is hard if ...
Given a string which is guaranteed to be either odd, even, square, cube, prime or composite, your program or function must return an integer \$100\le N\le 999\$ which meets this description. Rules Your code must be deterministic. The choice of the integers is up to you. However, the six answers must be distinct. (For ...
The setting "Well I actually wrote the sql library they, the maintainers actually.." "Right, but do you have any experience working with django?" " ...no I don't use frameworks" After the phone interview is over, you feel like you really need a coffee. While the brew is heating, you check your messages on BusinessBook....
Input a non-empty array with \$n\$ positive integers. Test if the input array contains every integer in \$1\cdots n\$. In case you prefer 0-indexed numbers, you may choose to input an array of non-negative integers, and test if the input array contains every integer in \$0\cdots (n-1)\$ instead. All testcases and formu...
Challenge Create the image of a pride flag (rainbow flag), i.e. a six coloured striped flag (from top to bottom): red, orange, yellow, green, blue, and violet. Output Example (R) barplot(rep(1, 6), horiz = TRUE, axes = FALSE, space = 0, border = NA, col = c("darkviolet", "blue", "darkgreen", "yellow", "orange", "red")...
Your task is, to count how many pluses I have. What Pluses? The no plus: 0 Points - The naïve Plus: 1 Point + The double Plus: 2 Points + +++ + The mega double plus: 3 Points + +++ + + + + +++++++++ + + + + +++ + Pluses of higher order than 3 must be ignored. Rules Input will ...
Given an array \$A\$ of size \$n\$. You have to find the number of subsets such that their product is in the form of \$p_1 \times p_2 \times p_3 \dots\$ where \$p_1, p_2, p_3, \dots\$ are prime numbers. No prime number should appear more than once, i.e. the product is "squarefree". Example: Lets pick an array \$A\$ of ...
Consider, for a given positive integer \$k\$, the sequence \$(a, a+1, a+2, ..., a+k)\$, where \$a\$ is some positive integer. Is there ever a pair \$a, k\$ such that for each element \$a+i\$ in the sequence, either \$\gcd(a, a+i)\$ or \$\gcd(a+i, a+k)\$ are greater than 1? This was investigated by Alan R. Woods as part...
Take an array of nonnegative integers, such as [1, 0, 0, 1, 2, 4, 2, 0]. Then, draw that as a mountain where the integers represent altitude: x x x x x xx x You may use any printable non-whitespace character in place of x, and adding padding or whitespace after lines or the output is fine...
This time, you are working on a regex. Your regex is meant to approximately full-match the base-10 representations of primes \$0 \le p < 1000\$, while ignoring any non-numeric string or composite in the range. You can full-match 2, 53 or 419, but not 0, 82 or example. The approximately is important -- a minimum of 900 ...
Most Unicode characters have full names, for example ” is "RIGHT DOUBLE QUOTATION MARK". You can find a useful reference here, just type in the character you want to find the full name of and look in the DESCRIPTION column. Your challenge is to write a program or function that outputs itself as a string of these. You c...
As some of you may remember, Peter, who was a picky eater is now puzzled Peter. This time Peter got some puzzles as a present from his Aunt. He has tried a lot, but has failed to solve the puzzles. Peter needs your help to solve them. Each one of the puzzle has 2 pieces. To solve the puzzle, you must tell the number of...
Totally not inspired by Lyxal repeatedly mentioning elevators in chat :P Challenge In short: simulate some people filling up an elevator and then leaving it. The elevator is simplified as a grid, where each person can occupy one cell of the grid. The height and width of the grid is the input parameter. The width is alw...
To get this sequence I just made up, which will subsequently be referred to as TSIJMU, consider the harmonic series: \$ \frac{1}{2} + \frac{1}{3} + \frac{1}{4} ...\$ But what if you only add a term if it doesn't make the sum so far over 1, and otherwise subtract? Let's see an example here, starting at \$\frac{1}{2}\$: ...
Your task is to create either a console "app" or a function which allows the user to bet on certain numbers or retire / claim rounds. Bets Your program or function will prompt for a command after an action, and the bet is the most important, crucial to the operation of the app. A bet looks something like this: bet 5 b...
Challenge Given two positive integers \$1 \le m \le 12\$ and \$1\le d \le 31\$, representing a month and days into the month, output the amount of days that have passed since January 1st, on a non-leap year. You can assume that the number of days passed will always be constrained by the number of days in the month (so ...
Background Hamiltonian circuit problem is a decision problem which asks whether a given graph has a Hamiltonian circuit, i.e. a cycle that visits every vertex exactly once. This problem is one of the well-known NP-complete problems. It is also known that it remains so when restricted to grid graphs. Here, a grid graph ...
The name of the challenge was prompted by this GIF and the GIF also gave me the idea. Your challenge today is to take a input guaranteed to be \$2<=n<=100\$ and output a sequence of x and - characters. The output for a number N represents a sequence of operations applied to 1 where x means "multiply by 2" and - means "...
I have to fill in 2fa codes all day. They're 6-digit strings. One day I noticed that not once did any of these codes contain 6 unique digits, like 198532 There was always at least one double, like 198539 (here it's 9). For any given uniformly random string of \$N\$ digits in the set \$\{0,1,2,3,4,5,6,7,8,9\}\$, what is...
Your toy in this challenge is a special abacus of 4 rows and 8 positions per row. There's one bead on the first row, 2 beads on the 2nd row, 3 beads on the 3rd row and 4 beads on the 4th row. Beads on a same row are glued together, which means that they can only be moved as a block. Below is a valid configuration of th...
As in this question, your task – should you choose to accept it – is to calculate the date of Easter Sunday according to the Gregorian Computus (as used in the Catholic Church and most others) when provided with only a year number as input, in as few characters as possible without relying on Easter-specific date functi...
Background A Medusa have released a dangerous Hydra which is revived unless the exact number of heads it have is removed. The knights can remove a certain number of heads with each type of attack, and each attack causes a specific amount of heads to regrow. The knights have hired you to write a program or function that...
Challenge: Given an expressions made of additions and multiplications, output an expression that is a sum of products. The output must be equivalent to the input modulo the law of distribution. For example, \$1 + ((2 + 5\times 6) \times(3+4))\$ becomes \$1 + 2 \times 3 + 2 \times 4 + 5\times6\times3 + 5 \times 6 \times...
Inspired by this 3Blue1Brown video Given a square matrix \$ M \$, compute its matrix exponential \$ \exp(M) \$, which is defined, using an extension of the Maclaurin series for \$ e^x \$, as $$ \exp(M) = \sum_{r=0}^\infty \frac {M^r} {r!} = M^0 + M^1 + \frac 1 2 M^2 + \frac 1 6 M^3 + \cdots + \frac 1 {n!} M^n + \cdots ...
Giuga numbers (A007850) are composite numbers \$n\$ such that, for each prime factor \$p_i\$ of \$n\$, \$p_i \mid \left( \frac n {p_i} -1 \right)\$. That is, that for each prime factor \$p_i\$, you can divide \$n\$ by the factor, decrement it and the result is divisible by \$p_i\$ For example, \$n = 30\$ is a Giuga num...
I wrote this function in 48 bytes and I wonder, is there any way to write this code 2 characters shorter? p=lambda n,c:(n*c)[:n//2]+(n*c)[:n//2+n%2][::-1] The point of the function is to create a palindrome of length n by using all the characters from the string c. Example: n = 3, c = 'ab'. Result is 'aba'. Is there s...
Because ARM is the July 2021 LoTM, I figured I'd create the tips thread. ARM is probably the most successful architecture for the digital world. From mobile phones to supercomputers, ARM is everywhere! Consequently, let's have a thread where we can help each other shorten our ARM code. One tip per answer, and no stupid...
Everyone knows, that you can leave out the multiplication symbol (\$\times\$, or *) in a*b 23*a (2+3)*a a^(b*c) (a+b)*(c+d) but not in 2*3 => you don't want it to be 23 a*23 => most mathematicians just don't do it a^2*b => now it's (a^2)*b, if you remove the *, it's a^(2b) a/2*b => now it's (a/2)*b, if you remove th...
Create a function that accepts a list of dates (unsorted with possible duplicates) and returns the days of the week in one of the following formats: A format similar to MTWTFSS or SMTWTFS (i.e. beginning with Monday or Sunday), with non-days replaced by an underscore _, illustrated below. WEEKDAY if all the dates are ...
The Lost Numbers are 4, 8, 15, 16, 23, 42. Your goal is to create an expression to output them all. Your allowed characters are 0123456789, ^+-*/, (), % for modulo and n as the single variable allowed. Modified PEMDAS ()^*/%+- is the precedence and / is normal division (3/2 = 1.5). 0^0 = 1 although division by 0 is und...
A screen consists of some LED segments like such: The screen can be split into several(maybe one) component. Each component is a segment like above, with varying lengths. These components can be used to display any amount, including 0, of digits, as long as the component is large enough. Every digit except 1 needs two...
When you export data in JSON from Facebook, the multi-byte Unicode characters are broken. Example Unicode characters and their representation inside JSON: '\u00c2\u00b0' : '°', '\u00c3\u0081' : 'Á', '\u00c3\u00a1' : 'á', '\u00c3\u0089' : 'É', '\u00c3\u00a9' : 'é', '\u00c3\u00ad' : 'í', '\u00c3\u00ba' : 'ú', '\u00c3\u00...
Challenge Given two lists of strings where each string is of length 50 and each list is also of length 50 generate the shortest regex you can that fully matches all the strings in the first list and does not match any of the strings in the second list. Scoring Your score will be the average length of the regexes your p...
When Alice was touch typing on her QWERTY keyboard (Figure 1), she accidentally shifted both of her hands rightwards by one key, so q became w, w became e, etc. (p became [). Spaces were not affected because the space bar was quite big. Your task is to help her fix her message using the shortest number of bytes, i.e. u...
Given a boolean function with inputs, check if it's possible to only use IMPLY gate to express it. There's no extra limitation on how you use this gate, and you can use each input for any amount of times. See examples below: \$\begin{matrix} \text{Expression}&&&&&\text{Solution}&\text{Your output}\\ a&0&0&1&1&a&\text{t...
A complete Boolean function is a function such that, an amount of them can be used to express any Boolean function. For example, NAND \$\left[\begin{matrix}\text{input1}&0&0&1&1\\\text{input2}&0&1&0&1\\\text{output}&1&1&1&0\end{matrix}\right]\$ is complete. Inputs may be reused any number of times, and the functions ca...
Key links: Troll question Chat room Game Controller Interface Dwarf league table <script src="https://ajfaraday.github.io/Thud/dist/data/tables.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><table> <thead> <tr> <th>Client</th> <th>Wins</th><th>Loses</th> <th>S...