instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
The Collatz Sequence (also called the 3x + 1 problem) is where you start with any positive integer, for this example we will use 10, and apply this set of steps to it: if n is even: Divide it by 2 if n is odd: Multiply it by 3 and add 1 repeat until n = 1 10 is even, so we divide by 2 to get 5. 5 is odd, so we...
stackexchange_codegolf
Your task: given a nonzero positive number i, calculate pi using the Nilakantha series unto i terms. The Nilakantha series is as follows: $$\text 3 + \frac{4}{2 \times 3 \times 4} - \frac{4}{4 \times 5\times 6}+\frac{4}{6 \times 7 \times 8} - ...$$ 3 is the first term, 4/2*3*4 is the second, -4/4*5*6 is the third, and...
stackexchange_codegolf
This page is not for Visual Basic Tips Visual Basic .NET (VB.NET) is an multi-paradigm dialect of basic that was developed and released by Microsoft in 2002 as a replacement for Visual Basic. The current version of VB.Net as of Feb 2018 is Visual Basic .NET 15.0. Unlike Visual Basic (VB), Visual Basic .NET (VB.NET) is ...
stackexchange_codegolf
Given an ASCII art hexagon as input, output one whose sides are all one unit longer. _____ ____ / \ / \ / \ / \ / \ \ \ => \ \ \ / \ / \____/ \ / \_____/ ...
stackexchange_codegolf
Heading into the final day of regular season games for the 2023 NBA season, the fifth to ninth seeds in the Western Conference were still very undecided. Four games would determine the seeding: New Orleans (N) at Minnesota (M) Utah at LA Lakers (L) Golden State (G) at Portland LA Clippers (C) at Phoenix Let the Boole...
stackexchange_codegolf
You work for a social media platform, and are told to create a program in a language of your choice that will automatically flag certain post titles as "spam". Your program must take the title as a string as input and output a truthy value if the title is spam, and a falsey value if not. To qualify as non-spam, a title...
stackexchange_codegolf
Given a string, reverse it interleavingly. Here's how to do it for abcdefghi and abcdefghij, 0-indexed: Separate the chars at even indices from the chars at odd indices:a c e g i b d f h a c e g i b d f h j Reverse the chars at odd indices:a c e g i h f d b a c e g i j h f d b Interleave into one string again:ahcf...
stackexchange_codegolf
Your task: Print or return a conversion table with every byte from 00 to ff's value as an unsigned integer, to its value as a signed one (using two's complement). For example: 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 1...
stackexchange_codegolf
Your friend Jack is a picky eater. He only likes certain foods, and he only likes to eat a certain amount of them each day. Despite this, Jack has very strict calorie and macronutrient goals that he strives to meet with his diet. To complicate things further, Jack's cravings change day by day, and he will only eat the ...
stackexchange_codegolf
Many old Game Boy games often required string input from the user. However, there was no keyboard. This was handled by presenting the user with a "keyboard screen" like so: The 'character pointer' would begin on letter A. The user would navigate to each desired character with the D-Pad's four buttons (UP, DOWN, LEFT a...
stackexchange_codegolf
Your task Given a string of lowercase letters, output the "alphabet checksum" of that string, as a letter. Example Let's say we have the string "helloworld". With a = 0, b = 1, c = 2 ... z = 25, we can replace all of the letters with numbers: h e l l o w o r l d 7 4 11 11 14 22 14 17 11 3 Now, we can sum th...
stackexchange_codegolf
Cops' Challenge Robbers' challenge here. It has now been four days since the challenge was posted so all new answers should be marked as non-competing in the title. These answers can still be cracked by robbers but will not go towards their total, and cannot win this challenge. In this cops-and-robbers challenge, you...
stackexchange_codegolf
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 ...
stackexchange_codegolf
Several years back, Hot Wheels made a simple flash game called "Formula Fuelers Racers"*. To play the game, you select three ingredients from a fridge to put into your car, which is then raced against the computer's randomly-generated car. It turns out the mechanics of this game are pretty simple. First off, the act...
stackexchange_codegolf
COBOL is a very old language, at the time of writing it is 58 years old. It is so old, in fact, that it has a very interesting quirk: the first six characters of each line are comments. Why is this, you ask? Well, those 6 characters were intended to be used as line numbers, back in the day where programs weren't comple...
stackexchange_codegolf
In this optimization challenge you will write a program that sorts a single array by only comparing elements through asking the user on stdout to input comparison results on stdin. The below protocol is line-based, so everytime you print to stdout or read from stdin it is assumed a newline follows. Throughout the quest...
stackexchange_codegolf
Given an input integer n > 1, output an ASCII-art octagon with side lengths composed of n characters. See examples below: n=2 ## # # # # ## n=3 ### # # # # # # # # # # ### n=4 #### # # # # # # # # # # # # # # # # #### n=5 ##### ...
stackexchange_codegolf
Given a positive square number as input. Output the number of values between the input and next highest square. Example Input: 1 Output: 2 Reason: The numbers 2 and 3 are between 1 and 4, the next highest square Input: 4 Output: 4 Reason: The numbers 5, 6, 7, 8 are between 4 and 9
stackexchange_codegolf
Introduction Humans are a remarkable species, but we can be very awkward to understand sometimes—especially for computers. In particular, we seem to like writing polynomials in a very convoluted fashion with seemingly arbitrary rules. What is the shortest program you can write to format a polynomial correctly using t...
stackexchange_codegolf
A few days ago, I came up with a fun card game to play with my friends. We were having fun playing it, when I thought, "Why not make this a KoTH?" So, here it is! Overview In this game, the objective is to get the most points. Your bot starts with 0 points and 20 energy. Every turn (500 in a game), both bots play one c...
stackexchange_codegolf
Background There is an interesting question on MathSE about some conjectures that are disproven by extremely large counter-examples. This delightful answer tells the story of a sequence of numbers called Gijswijt's sequence, which is now registered as A090822. The sequence is defined as follows Let \$a_1 = 1\$ and for...
stackexchange_codegolf
This is a bit similar to this dust covered entry but I'm hoping my spin on it makes it unique enough. Not been able to find anything dissuading me from posting this but there is quite the sea out there. Anyway! The challenge: Your code receives a string of characters; It converts this into an ASCII-art style version of...
stackexchange_codegolf
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...
stackexchange_codegolf
My colleague recently sent me the following piece of JavaScript as a joke: let butScript = (nrOfButs) => { for(var i = 0; i < nrOfButs; i++){ if(i % 3 == 0){ console.log("Yeah") } if(i % 2 == 0){ console.log("But") } if(i % 3 == 1){ console...
stackexchange_codegolf
inspired by this chat conversation A satisfying number is a number whose decimal representation is of the form abx, with the following properties: x is the longest trailing repeating suffix, or the last digit if there is no repetition at the end (123333 -> 3333, 545656 -> 5656, 123 -> 3) b is the single digit prior to...
stackexchange_codegolf
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...
stackexchange_codegolf
Let us consider the following representation of the periodic table. __________________________________________________________________________ | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |--------------------------------------------------------------------------| |1| 1...
stackexchange_codegolf
In some nations there are recommendations or laws on how to form emergency corridors on streets that have multiple lanes per direction. (In the following we only consider the lanes going in the direction we are travelling.) These are the rules that hold in Germany: If there is only one lane, everyone should drive to t...
stackexchange_codegolf
This is the cop's thread. The robber's thread is here. Write a code that takes an input n and creates a n-by-n "snake matrix". A snake matrix is a matrix that follows this pattern: 3-by-3: 1 2 3 6 5 4 7 8 9 and 4-by-4: 1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13 The exact output format is optiona...
stackexchange_codegolf
Challenge: Your task is to use any language to output that language's name times the number of character's in its name. Use the common name or acronym of the language. If there are multiple versions of a language, you need not include the version number. The capitalization matters. Examples: PHP -> PHPPHPPHP Java -> ...
stackexchange_codegolf
This is a program I wrote in JavaScript to validate some inputted credentials, with an intentional vulnerability. The credentials_validator function takes an object as input, with usernames and passwords. It returns a function, which takes a username and password and returns true if the credentials are valid. Your chal...
stackexchange_codegolf
In this challenge, your task is to take an simple recording in mp3 format and find the time offsets of the beats in the file. Two example recordings are here: https://dl.dropboxusercontent.com/u/24197429/beats.mp3 https://dl.dropboxusercontent.com/u/24197429/beats2.mp3 Here is the third recording with much more noise t...
stackexchange_codegolf
Task: Your task is, when given three inputs: a numerator n a denominator d another integer, x Create a program/function that finds the xth digit of the number after the decimal place. Specs: The range of n and d is between 1 and 2^31 - 1, inclusive. The range of x is between 1 and 10,000,000, inclusive. You may ch...
stackexchange_codegolf
A hill number is a number that has the same digit in the first & the last, but that's not all. In a hill number the first digits are strictly increasing until the largest digit, and after the largest digit, the last digits are strictly decreasing. The largest digit can be repeated but consecutively only, meaning no gap...
stackexchange_codegolf
It seems that many people would like to have this, so it's now a sequel to this challenge! Definition: a prime power is a natural number that can be expressed in the form pn where p is a prime and n is a natural number. Task: Given a prime power pn > 1, return the power n. Testcases: input output 9 2 16 4 343 ...
stackexchange_codegolf
Inspired by this SciFi.SE question. Background (with minor spoiler): In the movie The Martian, protagonist Mark Watney uses an ASCII table to look up hexadecimal values of ASCII characters so he can attempt to communicate back to Earth.* Challenge With no input, output the following ASCII table exactly like this: D...
stackexchange_codegolf
Bowling Bowling is a game where, essentially, each player gets 10 turns to: Take 2 attempts at knocking down 10 pins arranged in a triangle. between turns the pins are reset from the 1st to the 2nd attempt the pins are left as-is The arrangement of the pins resembles the following scheme, with the pins numbered 0-9: ...
stackexchange_codegolf
The challenge: output this exact ASCII art of a spiderweb in a window: _______________________________ |\_____________________________/| || \ | / || || \ /|\ / || || /\'.__.' : '.__.'/\ || || __.' \ | / '.__ || ||'. /\'---':'---'/\ .'|| ||\ '. /' \...
stackexchange_codegolf
Objective Given a 2D array of any size, write a program or function to shift alternatively the columns and rows Example a b c d e f g h i j k l m n o All elements in the first column shift down one row, the second column shift up one row, the third shift down one row and so on, wrapping when they reach the edge. k g m...
stackexchange_codegolf
Objective Given a permutation of 4 distinct items, classify the permutation by the normal subgroup(s) it belongs. Input/Output Format You gotta choose the followings as the hyperparameters for your submission: The 4 distinct items. The permutation serving as the identity permutation. The input format is to accept a...
stackexchange_codegolf
I've been really interested with sequences that follow the property \$a(n+1) = a(n - a(n))\$ recently, so here's another question about these sequences. In particular we are concerned with sequences from the integers to the natural numbers. A periodic sequence with the above property is an n-Juggler if and only if it...
stackexchange_codegolf
Let's say you are given an integer array. Create a function to determine the largest sum of any array's adjacent subarrays. For instance, the contiguous subarray with the largest sum is [4, -1, 2, 1] in the array [-2, 1, -3, 4, -1, 2, 1, -5, 4]. You can employ a variant of Kadane's algorithm to resolve this issue. The ...
stackexchange_codegolf
A few hours earlier, I got this puzzle: Suppose, you toss a coin n times, then what is the probability of getting m number of heads? ( where m belongs to the set of all prime numbers) For instance, take n = 2, then SS = { HH, HT, TH, TT } So, output is 1/4 (for HH case) Then, for n = 3, SS = { HHH, HHT, HTH, THH, HTT...
stackexchange_codegolf
Inspired by the fact that a few related challenges to this could be answered by Vyxal in 0 Bytes using a special flag combination. Given only one input integer \$n\$, calculate \$f(n,n)\$ where $$ f(x,y)= \begin{cases} x & \text{if } y=0 \\ f(\left(\sum_{k=1}^xk\right),\text{ }y-1) & \text{otherwise} \end{cases} $$ If ...
stackexchange_codegolf
Task: convert a HTML page into a mountain! When HTML pages are indented, they can look like: <div> <div> <div> </div> <div> <div> </div> </div> </div> </div> But to be honest, a mountain is more representative of this structure. So we can rewrite it as: ...
stackexchange_codegolf
Introduction Forte is a very peculiar esoteric language based on the concept of modifying the values of numbers. In Forte numbers are not constants but variables, you can use the LET instruction to assign new values to them. For example, after executing LET 2=4-1 from now on 2 assumes the value of 3, which means that w...
stackexchange_codegolf
Let n be a positive integer then n = a + b + c for some a, b, and c that are palindrome integers. What is the largest possible integer a for k = 1 to 1_000_000? Golf this or have the fastest running time. NOTE: it's NOT the same as this question as I am asking for the largest palindrome component. The question just ask...
stackexchange_codegolf
Sandbox Background (not necessary for the challenge) A standard number theory result using the pigeonhole principle is the fact that given any natural number k, there is a Fibonacci number that is a multiple of k. We can see this by considering modular pairs (F(n-1) % k, F(n) % k), and noting that there are only a fini...
stackexchange_codegolf
A very common need in algorithms classes and computer science in general is to iterate 4-directionally over a grid or matrix (such as in BFS or DFS). This seems to often result in a lot of clunky and verbose code with a lot of arithmetic and comparisons within loops. I've seen many different approaches to this, but I c...
stackexchange_codegolf
Background Incident is a fairly unusual programming language, in that its list of tokens is not predetermined, but rather inferred from the input. As such, tokenising an Incident program can be fairly difficult, especially if you want to do so efficiently. This task is about doing that yourself. The task Your program w...
stackexchange_codegolf
Automatic house building nanobots have been fabricated, and it's your job to code them. Here is the house created by input 7 4 2 /-----/| / / | |-----| | | | | | | / |_____|/ The input is a string containing the house's dimensions. 7 is the width. |_____| ---7--- 4 is the height. | | | | 2 is the d...
stackexchange_codegolf
Introduction (may be ignored) Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. This is the second challenge in this series. The first challenge can be found here. In this challenge,...
stackexchange_codegolf
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...
stackexchange_codegolf
Challenge Write a program or a function that returns or prints a square-random-symmetrical matrix. Input N: The size of the matrix i.e 6 x 6 Output The matrix. You can either print it, return it as string (with the newlines) or as a list/array of lists/arrays. Rules You need to use at least N different characters, ...
stackexchange_codegolf
A very common need in algorithms classes and computer science in general is to iterate 4-directionally over a grid or matrix (such as in BFS or DFS). This seems to often result in a lot of clunky and verbose code with a lot of arithmetic and comparisons within loops. I've seen many different approaches to this, but I c...
stackexchange_codegolf
Three positive integers A, B, C are ABC-triple if they are coprime, with A < B and satisfying the relation : A + B = C Examples : 1, 8, 9 is an ABC-triple since they are coprime, 1 < 8 and 1 + 8 = 9 6, 8, 14 is not because they are not coprime 7, 5, 12 is not because 7 > 5 You can see this Frits Beukers 2005 presenta...
stackexchange_codegolf
User inputs an integer. Print out proper fractions using all positive integers up to the user's input, in ascending order. Rule 1: Eliminate equal fractions. Rule 2: Fractions should be in their simplest form. Rule 3: Use "/" as a fraction symbol and next line (\n or \r as convenient) as a separator between fractions. ...
stackexchange_codegolf
Given an input string of length 2 or longer consisting solely of alphabetical characters [A-Z] or [a-z] (your choice if they're all uppercase or all lowercase), output a continuous string of characters forming a double diamond pattern. The input string starts on the center line and extends down-and-right at a diagonal ...
stackexchange_codegolf
Objective Your goal is to make a program that converts an input to its acronym. Your input is guaranteed to have only letters and spaces. The input will have exactly one space between words. You must output the acronym of the input. Rules Your code cannot be case-sensitive(e.g. foo and Foo are the same) Your code must...
stackexchange_codegolf
The purpose of this challenge is to graphically depict a walk on the plane, where the direction of each step \$k\$ is determined by the primality of \$k\$ and the parity of its binary expansion. Specifically, Initial direction is fixed, say North. All steps have the same length. The direction of step \$k\$ can be Nort...
stackexchange_codegolf
Introduction Rules of the puzzle: The puzzle Binary (also known as Takuzu or Subiku) is very simple to understand, and has only a few rules: Since the name of the game is binary it's pretty obvious, but you can only fill in zeros and ones. No more than two of the same digit can be vertically or horizontally adjacent t...
stackexchange_codegolf
preface In a very heated situation you have to go even further with golfing. (e.g. in a challenge where your answer is 100 characters long and it is just embarrassing that you couldn't make it 99) In that case, from now on you use the winner's algorithm of this challenge :) goal You have to write a program that takes ...
stackexchange_codegolf
Introduction A popular word puzzle is to convert one word into another via a series of steps which replace only one letter and which always result in a valid word. For example, BAG can be converted to DOG via a path of five steps: BAG -> BAT -> CAT -> COT -> COG -> DOG Shorter paths also exist in this case; for example...
stackexchange_codegolf
The magic music box (MMB) This explains the motivation for the challenge, feel free to ignore. The magic music box is a word game played by a group of people, where one is the owner of the magic music box and the other people are trying to put words inside the magic music box. Rules for the game with humans: the game g...
stackexchange_codegolf
The problem over here introduces an new type of strings: if you split the string into equal halfs and swap the pairs, it produces the same output as sorting the string. We call that a half-sort. Given a purely ASCII string, check if the string is in a half-sort. An example of a half-sort string The string node is a hal...
stackexchange_codegolf
Find what is the distance for a given string to its closest palindrome of the same length. For this task I decided to give the characters further away from the string's center more weight (think of it as contributing more torque), proportional to their distance to the center. Let's define the palindrome distance for a ...
stackexchange_codegolf
Task Take the (integer) number of human years that the dog has lived, \$n\$, as input and return its age in dog years, \$d\$, to two decimal places. The number of human years, \$n\$, will be between \$1\$ and \$122\$ inclusive: \$n \in [1,122], n \in \Bbb{N}\$. According to BBC's Science Focus Magazine, the correct fun...
stackexchange_codegolf
Do randomly generated drum loops sound good? A drum loop is a \$5\times 32\$ matrix \$A\$ of \$1\$s and \$0\$s such that \$A_{1,1}=A_{1,17}=A_{2,9}=A_{2,25}=1\$, for each \$i\$, the \$i\$th row has exactly \$f(i)\$ different \$1\$s, where \$ f(1)=3, f(2)=2, f(3)=6, f(4)=8, f(5)=5\$, for each \$j\equiv 1\bmod 4\$, the ...
stackexchange_codegolf
Given positive integer n < 10, create a 2 dimensional matrix where each location is filled with its x and y index (starting from the top left). For example: Input: 2 00 10 10 11 Input: 3 00 10 20 01 11 21 02 12 22 Once the grid is created, randomly fill each index. This can be with an 'x' or any other way to denote a...
stackexchange_codegolf
NOTE: The winner of this competition is Jack!!!. No more submissions will be accepted. Here is the chat room for this king-of-the-hill challenge. This is my first one so I'm open to suggestions! Reaper is a game concept developed by the Art of Problem Solving which involves patience and greed. After modifying the game ...
stackexchange_codegolf
For this challenge a "binary tree" is a rooted tree where each node has 0 children (leaf) or 2. The children of a node are unordered, meaning that while you might draw the tree with left and right children there isn't a distinction between them and mirroring the tree or a sub-tree does not produce a new tree. In this...
stackexchange_codegolf
A primitive element of a finite field is a generator of the multiplicative group of the field. In other words, alpha in F(q) is called a primitive element if it is a primitive q−1th root of unity in F(q). This means that all the non-zero elements of F(q) can be written as alpha^i for some (positive) integer i. All ele...
stackexchange_codegolf
Output the infinite list of pairs of integers (a, b), where both \$ a > 1 \$ and \$ b > 1 \$, ordered by the value of \$ a^b \$. When there are multiple pairs where \$ a^b \$ is equal, they should be ordered lexicographically. For example, \$ 2^4 = 4^2 = 16 \$, but (2, 4) should come before (4, 2), because it is lexico...
stackexchange_codegolf
You are given the functions: h1(f,*args) and h2(f,*args) Both are methods which are already defined for you (here the asterisk indicates a variable number of arguments) f is a function, *args is a list of parameters to be passed to that function h1 returns a boolean value: True if the function f ever halts when called ...
stackexchange_codegolf
I thought of a new way to generate my passwords, and even though it's probably not very clever in the long run, it could still make for a fun code-golf. Taking a string of words, the password is generated thus: Pick the nth character in the nth word If n is larger than the word, continue counting backwards Example: T...
stackexchange_codegolf
Black Box is a board game, Your task is to reveal all clues. What is black box Black box is a board game with hidden atoms, Your task is given input, All atoms, reveal all clues. I/O Input The atoms can be any 1-char that is not newline (Used for separator) Like this. O.... ...O. ..O.. ..... ....O Output When the code...
stackexchange_codegolf
According to Wikipedia, a strongly Darboux function is one for which the image of every (non-empty) open interval is the whole real line In other words, a function \$f\$ is strongly Darboux if given 3 arbitrary real numbers \$a\$, \$b\$, and \$y\$, it is always possible to find an \$x\$ between (distinct) \$a\$ and \...
stackexchange_codegolf
Everyone is likely familiar with the following song, which is a musical round: Background Fewer people might recall trying to sing the 4-person version of this with a few friends and failing. Offsetting the lyrics of a song with different harmonious pitches is known as singing a "round" and that's what we're here to s...
stackexchange_codegolf
Objective Write a program or function (or equivalent) that sorts out and returns the odd letter in the matrix of random size. Details You will be passed a matrix (as a string) as input of random dimensions such as this. bbbbbbbbbb bbbbbdbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb Your job is to find the letter that doesn't...
stackexchange_codegolf
This task is to output the shortest path to a file, after glob expansion. What is shell globbing? In most shells, you can use the * character in a path to represent any characters at the position. For example, If directory foo contains files bar baz and asdf, then foo/b* will expand to foo/bar foo/baz. Now, lets say t...
stackexchange_codegolf
GPA Calculator (GPA = Grade Point Average) You are a stressed out college student during finals week. Instead of studying for your exams coming up, you decide it is best to determine what GPA you will have at the end of the semester. This way you have data to back up your decision of staying up all night to get that A ...
stackexchange_codegolf
This is a simple one: Take a matrix of integers as input, and output the index of the row with the most non-zero elements. You may assume that there will only be one row with the most non-zero elements. Test cases: These are 1-indexed, you may choose if you want 0 or 1-indexed. 1 0 row = 1 --- 0 -1 0 0 row = 1 --- 1...
stackexchange_codegolf
Imagine you have a positive integer number \$n\$. Let \$m\$ be the number obtained by reversing \$n\$'s digits. If \$m\$ is a whole multiple of \$n\$, then \$n\$ is said to be a reverse divisible number. If neither are a palindrome, \$m\$ is called a palintiple. For example, \$1089 \cdot 9 = 9801\$, so \$9801\$ is a pa...
stackexchange_codegolf
What general tips do you have for golfing in Nim? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Nim (e.g. "remove comments" is not an answer). Please post one tip per answer.
stackexchange_codegolf
Given an input of any valid Glypho program, output its "human-readable" counterpart. Glypho is an interesting esolang idea: The instruction reference is given here. For each instruction, the characters abcd represent the symbols composing each instruction. a refers to the first unique symbol, b refers to the secon...
stackexchange_codegolf
Your Challenge You must write a program/function etc. that takes a domain name of a StackExchange site and outputs the domain for the meta version of the site passed to it. Examples: stackoverflow.com => meta.stackoverflow.com codegolf.stackexchange.com => codegolf.meta.stackexchange.com mathoverflow.net => meta.mathov...
stackexchange_codegolf
This challenge is related Challenge Your task is to write as many programs/snippets as you can, where each one outputs/prints/ returns an alphabet. The first program must output the letter A or a, the second one B or b and so on. You can not reuse any characters between the programs (Except Whitespace, it can be reused...
stackexchange_codegolf
Introduction The game Minecraft has a 1 in 10000 chance of showing "Minceraft" instead of "Minecraft" on the title screen. Your challenge Your challenge is to code a function or program that takes no input, and on average 1 of 10000 times, returns "Minceraft" and the rest of the time returns "Minecraft". Scoring This i...
stackexchange_codegolf
Given \$a\$ and \$b\$, both odd \$n+1\$-bit integers, compute \$a/b\$ to a precision of \$n+1\$ bits in the 2-adic integers. That is, compute \$c\$ such that \$a = bc\, (\mathop{\rm mod} 2^{n+1})\$. \$n\$ should be your language's native integer size, or if native integers are bigints, take it as a parameter. If your l...
stackexchange_codegolf
Take an arbitrarily sized string as input. This string represents a baseball plate appearance, in which each character represents a pitch as follows: Strike: S Ball: B Foul ball: F Hit by pitch: H Ball in play: X (For those wondering, this is a very very simplified version of Retrosheet's notation) Your program must...
stackexchange_codegolf
Write an infinite list of triangle codes, defined as code where the i-th line has i bytes for all lines, such that the i-th code generates (i-1)th code and has 1 more line than the (i-1)th code. The score is the number of lines in the initial code. Lowest score wins. For example, if . .. ... .... is outputted by . .. ...
stackexchange_codegolf
Given a number x, find the sum of all primes up to that number. The input will always be a positive number, bigger than 2. An upper limit isn't defined, so data types can be ignored. Use whichever you want. This is a code-golf, so the shortest code in bytes wins. Example for 5: 2 + 3 + 5 = 10 Test cases: Input Ou...
stackexchange_codegolf
Your input is an array of integers in the range [-1,4]. An array element of -1 means that there might be a bomb in that position. A non-negative element means that there is not a bomb in that position and also the numeric value tells how many bombs there are within distance 2. For example, if we have the following arra...
stackexchange_codegolf
This is the Robbers' thread. Cops' thread is here. Background Boggle is a board game where the players have to find English words on a 4-by-4 board of random alphabets. Words can be constructed by selecting sequentially adjacent cells on the board. ("adjacent" means horizontally, vertically or diagonally adjacent.) A...
stackexchange_codegolf
Introduction The perimeter density matrix is an infinite binary matrix M defined as follows. Consider a (1-based) index (x, y), and denote by M[x, y] the rectangular sub-matrix spanned by the corner (1, 1) and (x, y). Suppose that all values of M[x, y] except Mx, y, the value at index (x, y), have already been determin...
stackexchange_codegolf
Some of you may be familiar with the way that a motorcycle shifts. But for those who don't, It looks like this 6 5 4 3 2 N 1 Now I want to know what gear I am in after performing a few up and down shifts. The program should work from neutral. Sample input: V^^ Sample output: 2 As you can see I downshifted once from ...
stackexchange_codegolf
Now that we're graduating, it's time to tally up the number of times someone suggested that PPCG was graduating, even before the annoucement! (see here) Your program will receive a list of chat messages. Each message has three pieces of data: the user (e.g. Geobits), the timestamp (e.g. Aug 19 '15 2:41 PM), and the mes...
stackexchange_codegolf
This is the Cops' thread. Robbers' thread is here. Background Boggle is a board game where the players have to find English words on a 4-by-4 board of random alphabets. Words can be constructed by selecting sequentially adjacent cells on the board. ("adjacent" means horizontally, vertically or diagonally adjacent.) A...
stackexchange_codegolf
When coding in Python, sometimes you want a multiline string within a function, e.g. def f(): s = """\ Line 1 Line 2 Line 3""" (The backslash is to remove a leading newline) If you try to actually print out s, however, you'll get Line 1 Line 2 Line 3 That's not what we want at all! There's...
stackexchange_codegolf
Given an integer n output the nth iteration of the Hilbert Curve in ASCII using the characters _ and |. Here are the first 4 iterations: n=1 _ | | n=2 _ _ | |_| | |_ _| _| |_ n=3 _ _ _ _ | |_| | | |_| | |_ _| |_ _| _| |_____| |_ | ___ ___ | |_| _| |_ |_| _ |_ _| _ | |___| |___| | n...
stackexchange_codegolf