instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
A repost of this challenge. Meta discussion. Sandbox post. Body of the question similar to the original Robber's challenge This cops and robbers is now (08/03/2018) closed to further competing cop entries, as robbers may no longer be competing to crack answers, but feel free to post new answers. The Cops challenge was...
stackexchange_codegolf
In my time on PPCG, I've noticed that quine problems and polyglot problems are quite popular. Also, meta-solutions to problems, that is, scripts which generate a program which is the solution to a problem, tend to get a lot of positive feedback from the community. Therefore, I have created this challenge, which impleme...
stackexchange_codegolf
"A picture is worth a thousand words"—so the old saying goes. The average word is about four characters long, so a picture conveys 4kB of information. But how much entropy, rather than information, can a picture convey? Your task is to generate an image, exactly 4,000 bytes in size, with the highest entropy possible. Y...
stackexchange_codegolf
Inspired by, and in memory of, our beloved genius, R.I.P. He invented and implemented dfns — his magnum opus and the subject of the challenge. For the interested: latest full dfns documentation and videos with John. Task Given an ASCII source code, answer in which of the following four categories it belongs: Dyadic d...
stackexchange_codegolf
It's likely that anyone who used Twitter a couple of months ago would know about the 'Howdy! I'm the sheriff of X" meme. Where a simple image of a sheriff is drawn with emoji, and changes to fit a theme. So I thought it was time for the Sheriff of Code Golf. Here he is: ### ##### ### ### ### # ...
stackexchange_codegolf
Background Actually (the successor to Seriously) is a stack-based imperative golfing language I created in November of 2015. Like many other golfing languages, it has one-byte commands that perform different functions based on the contents of the stack. One of its specialties is mathematics - it has a wide variety of m...
stackexchange_codegolf
What general tips do you have for golfing in sed? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to sed (e.g. "remove comments" is not an answer). Please post one tip per answer.
stackexchange_codegolf
Do you recognize the PPCG logo? it looks like this, when you do an ascii art of it. +---+ |PCG| +---+ v Now, In this Code Golf, You will make a code, that makes logos for other sites, similar to the PPCG logo. What You should do The "Shortened" string will be the string, with all upper case letters and numbers in t...
stackexchange_codegolf
RollerCoaster Tycoon 2's maze is the inspiration for this question. Credit to Marcel Vos for thoroughly breaking the classic RCT2 AI. The pathfinding AI in this question is the AI in the latest version of OpenRCT2 at the time of writing, which was updated in response to that video. Suppose a guest enters a \$w \times...
stackexchange_codegolf
This tweet lists the possible orders for Wings of a Chinese restaurant1: When ordering Pizza I usually calculate what size gives me the best Pizza-price ratio which is a simple calculation. However minimizing the price of an order at this restaurant isn't such a simple task, so I'd like to be prepared for my next orde...
stackexchange_codegolf
Background Information: What is a Fenwick Tree? With a normal array, it costs \$O(1)\$ to access and modify an element, but \$O(n)\$ to sum \$n\$ elements. Working with a prefix sum array (an array where the \$i\$th value represents the sum of the first \$i\$ values in the underlying data), access and summation are \$O...
stackexchange_codegolf
Spring has recently arrived, and it is almost the time when flowers start to sprout. So I want you to help them grow. Your task: Given two numbers, m, and n, output m flowers randomly placed on an n*n grid. A single flower looks like this: & | A flower's position is defined by where its & is. When randomly placing two...
stackexchange_codegolf
I am working on a code to print all semimagic squares [1] of a given size. I am working with the following definition: An \$n\times n\$ consists of numbers \$1,2,\cdots, n^2\$. All numbers must be distinct. Sum of each row and each column is equal. According to Ripatti A. (2018) [1]: \$n\$ number of semimagic squ...
stackexchange_codegolf
Inspired/mostly copied but I don't think it's a dupe. Also Inspired. In this challenge, you will create polyglots that include all languages from previous answers, and another language which you won't share and others must guess. The first language prints 1, the second prints 2, etcetera. For example, if the first answ...
stackexchange_codegolf
If we take a positive integer \$n\$ and write out its factors. Someone can determine \$n\$ just from this list alone. In fact it is trivial to do this since the number is its own largest factor. However if we take \$n\$ and write only the first half of its factors (factors that are smaller than or equal to \$\sqrt{n}...
stackexchange_codegolf
This question is the inverse of this one by James Williams. Rövarspråket Rövarspråket is a word game played by Swedish children, from the books about Kalle Blomkvist by Astrid Lindgren. The basic rules used during encoding are as follows (from Wikipedia): Every consonant (spelling matters, not pronunciation) was doub...
stackexchange_codegolf
Nepal’s flag (Wikipedia, Numberphile) looks very different from any other. It also has specific drawing instructions (included in the Wikipedia article). I want you guys to make a program which will draw the flag of Nepal. The user inputs the requested height of the flag (from 100 to 10000 pixels) and the program outpu...
stackexchange_codegolf
Surprisingly we haven't had a simple "find the highest digit" challenge yet, but I think that's a little too trivial. Given input of a non-negative integer, return the highest unique (ie not repeated) digit found in the integer. If there are no unique digits, your program can do anything (undefined behaviour), other th...
stackexchange_codegolf
Compare two numbers N1 = abc, N2 = def by constructing a function f(a,b,c,d,e,f) that: returns 1 if N1 > N2 returns -1 if N1 < N2 Note: You are not required to return any value for any other relation between N1 and N2. e.g. when they are equal or when their relation is undefined (complex numbers). other constrains: ...
stackexchange_codegolf
Given a string of ASCII art like such (This isn't ASCII art but it will do for the example): abc d e fgh Jumble it as if it was being displayed on a screen with one character per line, like so: a b c d e f g h Print the result, wait one second, ±0.5 seconds before clearing the terminal and the print the same thing, ...
stackexchange_codegolf
Given an \$m \times n\$ matrix of integers A, there exist a \$m \times m\$ matrix P, an \$m \times n\$ matrix D, and an \$n \times n\$ matrix Q such that: \$A = P D Q\$. P and Q are unimodular matrices (i.e. matrices which are invertible and whose inverses are also integer matrices); D is diagonal; each diagonal entry...
stackexchange_codegolf
Challenge Given a number of seconds past midnight, output the smallest angle between any two hands on a clock face, using as few bytes as possible. You may assume that the number of seconds is always less than 86400. Angles may be represented in degrees or radians. A reference solution is at: http://ideone.com/eVdgC0 T...
stackexchange_codegolf
We know that not all fractions have a terminating binary representation. However every fraction can be written as a leading portion followed by a repeating portion. For example \$1/3\$ starts with \$0.\$ and then just repeats \$01\$ endlessly. This corresponds to the bar notation taught in primary school. For examp...
stackexchange_codegolf
This challenge is a simple ASCII-art challenge inspired by the solar eclipse that happened on August 21, 2017. Given an input 0 <= n <= 4, output the corresponding stage of the eclipse described below: n=0: ***** ** ** * * * * ** ** ******* n=1: ***** ** ***** * ******* * *****...
stackexchange_codegolf
Write a program or function which takes a string of text as input and outputs the number of non-alphabetical characters in it (standard I/O rules apply). A non-alphabetical character is any character not appearing in this string: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ In terms of ASCII character codes, t...
stackexchange_codegolf
You are given an array A of length N and an array B of length N-1. You need to output array where items alternates: A[0], B[0], A[1], B[1], ..., B[N-2], A[N-1] Restrictions: N>0 Type of items is not specified, but code should work at least for unsigned integers. Sample input: A = [1,2,3,4] B = [7,8,9] Sample output:...
stackexchange_codegolf
Github You have probably played, and may even have written a program to play, a simple number guessing game. If so, this probably looks familiar: Try to guess my number (1 to 100)! Please enter a guess: 50 Too small, guess again! Please enter a guess: 75 Too big, guess again! Please enter a guess: 63 Correct! (Obvious...
stackexchange_codegolf
For the purposes of the current challenge to "outline" a word means to surround it successively with its own letters, starting with the last one, and finally to replace the original word in the center with spaces: oooooo onnnno on -> on no onnnno oooooo Task: Given a list of words, con...
stackexchange_codegolf
Write code that outputs the smallest integer \$n > 5\$ such that \$\frac{\sqrt{\log_2{n}}}{(\log_2 {\log_2 n})^2} > 1\$. Your code may have at most one digit in its source code. You can use your chosen digit more than once however. By digits we are only counting the ASCII characters between 0x30 and 0x39 (inclusive).
stackexchange_codegolf
Usually each cell in brainfuck has 256 states, which is not enough to tell whether input is EOF or a character (usually \xFF). To fix it we can add one more state to it, and EOF (256) isn't mistake from a byte. Since outputting EOF is also not defined, . on 256 works as reading, and therefore , is removed from the mod...
stackexchange_codegolf
Overview Consider the following task: Given a positive integer n > 0, output its integer square root. The integer square root of a number n is the largest value of x where x2 ≤ n, usually expressed with the formula floor(sqrt(n)). Examples: 25 -> 5, 24 -> 4, 40 -> 6, 1 -> 1. This task is easy enough on its own. Howev...
stackexchange_codegolf
You end up having a lot of very long, boring-looking conditionals in your code: if flag == 1: while have != needed: if type == 7: These can be transformed into their much more lovable <3 conditionals counterparts: if abs(flag - 1) + 2 <3: while 3 - abs(have - needed) <3: if 2 + abs(type - 7) <3: Task Your task is...
stackexchange_codegolf
The Rugby World Cup starts in a few hours! Write a program or function which, given a rugby team score as input, outputs all possible ways the score could have been attained in a Rugby game. Ways to score in Rugby Penalty kick/Drop kick: Both penalty kicks and a drop kicks are worth 3 points (We regroup them in this c...
stackexchange_codegolf
While I was writing numbers I noticed after a while that my keyboard had the Shift key pressed and blocked and all I wrote was $%&-like characters. And even worse, I had been switching between the English and Spanish keyboard layouts so I don't know which one I used for each number. Challenge Given a string containing ...
stackexchange_codegolf
Part of Advent of Code Golf 2021 event. See the linked meta post for details. The story continues from AoC2015 Day 3, Part 2. This challenge was kindly contributed by Wheat Wizard (Grain Ghost). Santa is delivering presents to an infinite two-dimensional grid of houses each 1 unit apart. The delivery begins delivering...
stackexchange_codegolf
There is a competition with \$n\$ participants in total. Alice is one of the participants. The outcome of the competition is given as a ranking per participant with a possibility of ties; e.g. there can be three participants who won 2nd place, and the next best participant gets the 5th place. More rigorously, a partici...
stackexchange_codegolf
It's holiday season. A mall is empty except of air, money, and a very clever thief that is you. The mall consists of n floors. Each floor can be represented as a rectangular 2D grid. All floors have the same 2D dimensions. You are somewhere inside the building. Your job, as a hard-working thief, is to collect c coins a...
stackexchange_codegolf
Fast and Golfiest Cops Thread Welcome to the first season of Fast and Golfiest, a cops-and-robbers challenge! I designed this challenge to encourage competitive coding for efficiency (fastest algorithm) to become more popular on the site. The rules are simple. The cops must choose a problem from LeetCode, the prestigio...
stackexchange_codegolf
Introduction Arrays are usually used with for-loops or iterators. One different task might be the use as a cheap way to rotate through a set of items, so after reaching the last index, the next item would be the first item of the array. This is useful for cases like menus and physical controls. Challenge Given the size...
stackexchange_codegolf
Task Produce this 24kB ASCII art output: ________ \ \ ________ \____ \ ...
stackexchange_codegolf
In this challenge, given a list of ghosts from Pac-Man, you must output which ghosts are missing. You must do it in as few bytes as you can Input Input will consist of a string or list, which will include a number ghosts, which could include: Blinky Inky Pinky Clyde However, input may also include Pac-Man (with that ...
stackexchange_codegolf
Your challenge is very simple: output the previous answer, in reverse. However, as with this similarly-titled question, there's a catch: in this case, you can only use characters from the answer before the last. For example: Let's say the first answer looks like this: 1 - Python print('hi!') And the second answer loo...
stackexchange_codegolf
Write a program that takes a string as input and modifies it by reversing the string in its place by mirroring the position. The first position goes to last, second to second last and so it goes on. In simple words, the string would be mirrored. "In Place" means the program should use \$O(1)\$ additional memory regardl...
stackexchange_codegolf
Given a positive integer, output a truthy/falsy value as to whether the number can eat itself. Rules Leftmost is the head, rightmost is the tail If the head is greater than or equal to the tail, the head eats the tail and the new head becomes their sum. If \$sum \ge 10 \$ then the head is replaced by \$sum \mod 10\$. \...
stackexchange_codegolf
Something I found while looking through some old files. It seemed like a neat idea for a code golf challenge. The intro One of the most popular events at the annual Cyclist's Grand Competition for Charity (CGCC) is the rocket bike parcours. The rules are simple: Inspect the parcours and place a bet on wheather is it po...
stackexchange_codegolf
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...
stackexchange_codegolf
Given a positive input \$n > 0\$, output the amout of two types based on their rarity. The two types are called \$A\$ and \$B\$, we know the followings: \$n\$ is a limited input and the maximum is \$nmax\$ At the start \$B\$ is twice as rare as \$A\$ As the presence of \$A\$ increade the rarity of \$B\$ decreases When...
stackexchange_codegolf
Normal brackets ((),[],<> and {}) are nice and unambiguous, however someone thought it would be a good idea to use non bracket characters as brackets. These characters, | and ", are ambiguous. For example does """" correspond to (()) or ()() It is impossible to tell. Things start to get interesting when you mix ty...
stackexchange_codegolf
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...
stackexchange_codegolf
You are given a \$3\times3\$ square matrix where each cell is any digit between \$0\$ and \$9\$ except \$7\$. Your task is to figure out the minimum number of digits that must be replaced with \$7\$'s so that the sums of the digits in each row and each column are the same. NB: There is no constraint whatsoever on the d...
stackexchange_codegolf
A simple contest, inspired by this stackoverflow question: You are given an image of a surface photographed by a satellite.The image is a bitmap where water is marked by '.' and land is marked by '*'. Groups of adjacent '*'s form an island. (Two '*' are adjacent if they are horizontal, vertical or diagonal neighbours)...
stackexchange_codegolf
Given three numbers m,n and p, your task is to print a list/array of length p starting with m and n and each element after p represents the difference of the 2 numbers before it, m-n (Counter-Fibonacci Sequence) For this challenge you can either use a function to return or print the result or a full program. Input Thr...
stackexchange_codegolf
Write a plain TeX program that lists the first two hundred primes (in base-10 notation). Including external files/resources is not permitted. The output may be to the terminal, the log file, or the actual dvi/pdf file, at your option, but should be easily readable to a human; in particular, there must be some delimiter...
stackexchange_codegolf
What general tips do you have for golfing in 1+? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to 1+ (e.g. "remove unnecessary whitespace" is not an answer). Please post one tip per answer.
stackexchange_codegolf
Since Euclid, we have known that there are infinitely many primes. The argument is by contradiction: If there are only finitely many, let's say \$p_1,p_2,...,p_n\$, then surely \$m:=p_1\cdot p_2\cdot...\cdot p_n+1\$ is not divisible by any of these primes, so its prime factorization must yield a new prime that was not ...
stackexchange_codegolf
QWERTY keyboard distance (QKD) is, in short, the distance between two letters/numbers/punctuation keys on a standard QWERTY keyboard (if you don't have one around, you can check this Wikipedia picture). Note that only characters without modifiers be considered for this challenge (so ; is valid, but ) is not). Some exa...
stackexchange_codegolf
The task is the following. Given an integer x (such that x modulo 100000000003 is not equal to 0) presented to your code in any way you find convenient, output another integer y < 100000000003 so that (x * y) mod 100000000003 = 1. You code must take less than 30 minutes to run on a standard desktop machine for any in...
stackexchange_codegolf
One way to represent a natural number is by multiplying exponents of prime numbers. For example, 6 can be represented by 2^1*3^1, and 50 can be represented by 2^1*5^2 (where ^ indicates exponention). The number of primes in this representation can help determine whether it is shorter to use this method of representat...
stackexchange_codegolf
Write two programs A and B. Program A (the encoder) takes 1024 pairs of integers \$(k,v)\$, where \$0≤k<2^{32}\$ and \$0≤v<1024\$, and all \$k\$ will be different. It will output a single positive integer (likely a few thousand digits long). Program B (the decoder) takes two inputs: the output-integer of program A, a...
stackexchange_codegolf
The accepted winner is isaacg, with his 7-bit ASCII answer. However, the challenge isn't over yet - this bounty is awarded to the shortest answer. If, somehow, you get all the first characters of all the other answers down into 10 bytes, you will win the bounty. This includes all the characters from Round 2's GolfScrip...
stackexchange_codegolf
At runtime, keep prompting for a line of input until the user input is not the name of an existing file or directory or other file system item, relative to the current working directory. Then return/print that last inputted filename. You may assume that all user inputs will be valid filenames. Pseudo-code 1 myform = ne...
stackexchange_codegolf
Background In typography, rivers are visual gaps in a block of text, which occur due to coincidental alignment of spaces. These are particularly annoying since your brain seems to pick them up more easily in peripheral vision, which constantly distracts your eyes. As an example, take the following block of text, lines ...
stackexchange_codegolf
(related) Your challenge is to output the highest number you can. You can output as a number or as a string. You must output something that matches the regex ^\d+$, as in only 0-9. The Twist Your source code must be: Same forwards and backwards 3 bytes long The middle byte must be different from the other two Exampl...
stackexchange_codegolf
We are used to the term "squaring" n to mean calculating n2. We are also used to the term "cubing" n to mean n3. That being said, why couldn't we also triangle a number? How to triangle a number? First off, let's pick a number, 53716. Position it in a parallelogram, whose side length equals the number of digits of the...
stackexchange_codegolf
You want to draw a regular polygon but you have limited space! In this challenge, you should draw a polygon with n sides which is as big as possible for a given square container image. I found surprisingly little information on the Internet about inscribing a polygon into a square. To save you the hassle, I verified th...
stackexchange_codegolf
Output the Nth term of the Van Eck Sequence. Van Eck Sequence is defined as: Starts with 0. If the last term is the first occurrence of that term the next term is 0. If the last term has occurred previously the next term is how many steps back was the most recent occurrence. https://oeis.org/A181391 https://www.you...
stackexchange_codegolf
Introduction This challenge was inspired by a seemingly simple task requested at work that couldn't easily be done in Microsoft Teams. At least not from what we could find! Task Your task, if you choose to accept it, is to output the last week day of any month in any year. Input You can input the desired month/year in ...
stackexchange_codegolf
Goal Given a non-negative integer, create a function that returns the starting position of number of largest consecutive 1's in that integer's binary value. When given an input 0, return 0. If the number has multiple streaks of equal length, you must return the position of the last streak. Input An integer greater than...
stackexchange_codegolf
This code-golf challenge will give you two positive integers n and k as inputs and have you count the number of rectangles with integer coordinates that can be drawn with vertices touching all four sides of the \$n \times k\$ rectangle $$ \{(x,y) : 0 \leq x \leq n, 0 \leq y \leq k\}. $$ That is, there should be: at le...
stackexchange_codegolf
Consider: c=(a,b)=>(+a||0)+(+b||0) Yes, it is not good to solve it like that. But I want to shorten it even more. If a is a string and b is a string, then return 0. If one is a number, return it (floats and intergers). And if both inputs are numbers, then return the sum (if either string can be cast to a number, treat...
stackexchange_codegolf
You may know the mathematician von Koch by his famous snowflake. However he has more interesting computer science problems up his sleeves. Indeed, let's take a look at this conjecture: Given a tree with n nodes (thus n-1 edges). Find a way to enumerate the nodes from 1 to n and, accordingly, the edges from 1 to n-1 in ...
stackexchange_codegolf
This geometric spiral looks complicated, but it's fairly simple to draw; take the following box: Draw a straight line between the corner of the box and some set distance above the next corner counter-clockwise. Continue this pattern inward, always staying that set distance away from the corner of the next line. Here...
stackexchange_codegolf
Your goal is to determine whether a given 2D point X lies within the area of the triangle with given vertices A,B,C. Write a function that takes in the coordinates of the test point X and the three triangle vertices (so that's 8 coordinates total) and returns True if the point lies inside that triangle, and False if it...
stackexchange_codegolf
Objective Requirements A main 'parent' file and a 'child' file. The parent file creates a new child file that contains code that must execute after creation. The child file that is created must delete the existing sibling file. It wants all the attention, afterall. No matter how many times the parent file is executed,...
stackexchange_codegolf
We define a tree-like list, or trist for short, as the empty list or a list containing only previously constructed trists. The natural numbers can either include 0 or not, according to your preference. The task is to create a pair of functions or complete programs f and g (they don't have to be named like this or even ...
stackexchange_codegolf
Let's define fn(k) as the sum of the first k terms of the natural numbers [1, ∞) where each number is repeated n times. k | 0 1 2 3 4 5 6 7 8 9 --------+------------------------------------------------- f_1(k) | 0 1 3 6 10 15 21 28 36 45 deltas | +1 +2 +3 ...
stackexchange_codegolf
Final results are here ! Introduction The game takes is strongly inspired by Manu's Game of Town. It takes place in a world of swords and magic. The king who ruled the whole continent just died, and the lords of the many city-states are now fighting over territory. You are one of these lords and your goal is to conquer...
stackexchange_codegolf
A Gaussian integer is a complex number whose real and imaginary parts are integers. Gaussian integers, like ordinary integers, can be represented as a product of Gaussian primes, in a unique manner. The challenge here is to calculate the prime constituents of a given Gaussian integer. Input: a Gaussian integer, which i...
stackexchange_codegolf
This is inspired by an 05AB1E answer by Magic Octupus Urn. Given two arguments, a positive integer and a string/list of characters: Translate the number to base-n, where n is the length of the string. For each character, replace every appearance of the index of that character in the base-n number with that character. ...
stackexchange_codegolf
Given two inputs -- one of them a non-empty printable ASCII string (including space, excluding newline), the other being one of two distinct, consistent values of your choice (1 / 0, l / r, left / right, etc.) -- output an ASCII art airplane banner of the string, pointing either left or right. For consistency, I'll be ...
stackexchange_codegolf
Given 4096 16-bit integers, only four of which are unique and others appeared twice (so 2050 different integers exist). Find the four uniques. To time precisely and limit RAM usage, your program will be run on a 12MHz 8051(with 128B RAM). I'll test with a random case generated by some code to test, but we aim at the wo...
stackexchange_codegolf
Add++ is the Language of the Month for January 2022, and so I'm asking for tips for golfing in it. Please stick to tips specific to Add++, and avoid general tips such as "remove whitespace" or "avoid comments". Please post separate tips as individual answers
stackexchange_codegolf
Introduction Suppose that you are handed a random permutation of n objects. The permutation is sealed in a box, so you have no idea which of the n! possible ones it is. If you managed to apply the permutation to n distinct objects, you could immediately deduce its identity. However, you are only allowed to apply the pe...
stackexchange_codegolf
Challenge Create a console program to display each byte of a file. Winning Since this is code-golf, fewest bytes wins. Rules Program must be a console application, meaning that it will be ran from some sort of command-line interpreter; Every byte must be uppercase hexadecimal, separated by a space, and it must be 2 ...
stackexchange_codegolf
Slope fields or direction fields, are a graphical representation of the solutions to a first-order differential equation of a scalar function. A slope field shows the slope of a differential equation at certain vertical and horizontal intervals on the cartesian plane, and can be used to determine the approximate tangen...
stackexchange_codegolf
Related: Hello world!!! Fibonacci distribution Create a program that returns True if a given input meets the following specifications, and False otherwise: The count of numeric characters (0-9) in the input matches a Fibonacci number. The count of non-numeric characters !(0-9) in the input matches the Fibonacci numb...
stackexchange_codegolf
Input a list of strings a and a string s for search keyword. Find out all strings in a which contains s as subsequence. And sort them in the following order: Exactly equals to s Starts with s Contains s as substring (continuous subsequence) Contains s as subsequence Detail When two strings belongs to the same sortin...
stackexchange_codegolf
write a function to tell if a number is symmetric or not. for example: input: 151 output: True input: 142 output: False and so on: 1111 True, 2390 False, 1226221 True
stackexchange_codegolf
Background Gödel numbers are a way of encoding any string with a unique positive integer, using prime factorisations: First, each symbol in the alphabet is assigned a predetermined integer code. Then, to encode a string \$ x_1 x_2 x_3 \ldots x_n \$, where each \$ x_i \$ represents an symbol's integer code, the resultan...
stackexchange_codegolf
Task: Remove all duplicates from one list of integers. A list is simply a sequence of connected values that allows the same values to be stored at different positions in this sequence. If an item was found to be the same value as another item in this list, keep the first occurence of the item and remove the second (thi...
stackexchange_codegolf
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. It's time to prepare an advent calendar, but I've only got a large sheet of rectangular paper, randomly colored red and green like this: GRRRGRRGRG GGRGGGRRGR GRRGRGRGRG GGRRGRGRGG GRGGRGRGGG RRGRGRGRRG RRRGRGRGGG RGGRGGRRRG RGGGRRRRRG...
stackexchange_codegolf
A while ago I purchased a new wallet which is able to hold 8 cards (4 on both side). However, I seem to have way more cards than that and I need to make choices on which ones I want to carry with me. Some cards I use more often than others, but the cards I prefer to carry with me are not necessarily the ones I use most...
stackexchange_codegolf
This challenge is inspired by the same task I read some time ago in CACM. There are many ways to sort stuff. Most attempt to sort in as few operations as possible (= as fast as possible). However, it is also possible to consider how few resources you might require to sort stuff, which seems more fitting for a codegolf ...
stackexchange_codegolf
The world has been invaded by aliens. They are everywhere killing people and taking over the world. You are hiding with your friend. They have one weakness - the high pitched sounds. You can't go yell at them, because you'd get caught before, so you remember the state had a conveniently made machine that emits a high p...
stackexchange_codegolf
The Rules It's time to build a typing speed test in your language of choice! 1. You provide a file with a dictionary of choice (every 'word' in it must be newline delimited). Pipe it in via stdin or provide it's name as a command line argument. a able about above absence ... 2. Pick 10 random words from the file (no ...
stackexchange_codegolf
In this challenge, you'll take an answer as input, and print the answer before it. If the answer passed as input is the first answer, print your own submission's source. You'll be passed any answer in the chain up to and including your own answer, but none after it in the chain. For example, if the first submission is ...
stackexchange_codegolf
A recent SO question asks for a convenient one-liner to generate a list of numbers and their negative counterparts in Python. Given two integers \$1≤a≤b\$, generate all the integers \$x\$ such that \$a≤|x|≤b\$. The result may be printed or returned in any order or structure, as putting the result into a list and sortin...
stackexchange_codegolf
Today's challenge is to draw a binary tree as beautiful ascii-art like this example: /\ / \ / \ / \ / \ / \ ...
stackexchange_codegolf
In the face of some regrettable rules that turned the original into a glorified sorting task, I am posting a more challenging variant. Shout out to Luis Mendo for the suggestion of how to improve the original challenge. You've inherited a server that runs several apps which all output to the same log. Your task is to ...
stackexchange_codegolf
Euler's totient function, \$\varphi(n)\$, counts the number of integers \$1 \le k \le n\$ such that \$\gcd(k, n) = 1\$. For example, \$\varphi(9) = 6\$ as \$1,2,4,5,7,8\$ are all coprime to \$9\$. However, \$\varphi(n)\$ is not injective, meaning that there are distinct integers \$m, n\$ such that \$\varphi(m) = \varph...
stackexchange_codegolf