instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
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
Newton's theory of gravitation says that the gravitational force between two point masses is F=(Gm1m2)/ r2 Where G is the gravitational constant: 6.674×10−11 N · (m/kg)2 m1 is the mass of the first object m2 is the mass of the second object r is the distance between their centers of mass Challenge You need to simul...
stackexchange_codegolf
\$P_k(n)\$ means the number of partitions of \$n\$ into exactly \$k\$ positive parts. Given \$n\$ and \$k\$, calculate \$P_k(n)\$. Tip: \$P_k(n) = P_k(n−k) + P_{k−1}(n−1)\$, with initial values \$P_0(0) = 1\$ and \$P_k(n) = 0\$ if \$n \leq 0\$ or \$k \leq 0\$. [Wiki] Examples n k Ans 1 1 1 2 2 1 4 ...
stackexchange_codegolf
Goal You will be given a positive integer number less than 10^20. You must convert it to Korean. For example, if the input is 12345, the output should be 일만이천삼백사십오. Technical details (Small) Let's starts with simple numbers. // 1 - 9 1 -> 일 2 -> 이 3 -> 삼 4 -> 사 5 -> 오 6 -> 육 7 -> 칠 8 -> 팔 9 -> 구 // 10, 100, 1000 10 ->...
stackexchange_codegolf
Main task Your task is to print out integers in descending order, starting from 1, and increasing as you keep hitting 1 again, up until the given input is reached, then, print out the rest until you hit 1 again. Example with input 6: 1 21 321 4321 54321 654321 Without newlines (valid output): 121321432154321654321 Sid...
stackexchange_codegolf
Task Given a number between 0 and 1 and another integer, print the approximated value of the first number rounded off to the specified number of digits given by the second integer. For example, if the input is 0.3212312312 , 2 then the output is: 0.32 Rules The number of digits after the dot should always equal the s...
stackexchange_codegolf
Part of the lean Language of the Month A pong* is a set \$P\$ with an operation \$+\$, that satisfies the following properties: \$ \forall a, b \in P : (b + b) + a = a\\ \forall a, b \in P : a + (b + b) = a\\ \forall a, b, c \in P: a + (b + c) = (a + b) + c \\ \$ This makes a pong*, just a group where every element is ...
stackexchange_codegolf
I find it deeply weird that this is possible in Ruby (I won't immediately say how): obj = #code redacted print obj.state # Some value. LValue = obj print obj.state # Different value! Your challenge is to create code roughly of this form. Create an object and assign it to a variable. It should have some defined attr...
stackexchange_codegolf
The Rundown Given any input x and y, perform a complex operation, and print a corresponding result. How your program should work Given an input x and y in the form z = x+yi, find zi-z If the absolute real value of zi-z is larger than the absolute imaginary part, print the real part; vice versa for the other way around...
stackexchange_codegolf
Modern regular expressions (regexes) have many features (\d, {n,m}, \1, etc.), but to define a regular language (modern regexes can define broader classes of languages, in their defense), all you need are three operators: concatenation (+), union (|), and the Kleene star (*). Here are some examples: a - Matches the str...
stackexchange_codegolf
Introduction It's 2600 BC and people are building pyramids now. They already made the basis of the pyramid but don't know how to continue. So, they called you for help. The rules of making a pyramid is quite simple. For the layer above the previous layer, all you need to do is follow this step-by-step hand guide: Cut ...
stackexchange_codegolf
Related: Interquine Program A outputs program B's code when run, and B outputs C's source, and C outputs A's source. This time you can't exchange two characters and exchange again :) Requirements: Only one language across all programs Standard loopholes restrictions apply All programs are different. One program th...
stackexchange_codegolf
Apparently, we really like printing the alphabet in different languages. How about the Russian Cyrillic alphabet? Print/output/return this exact text (trailing whitespace is permitted) АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя This is the Russian Cyrillic alphabet with upper and lower case int...
stackexchange_codegolf
Introduction Of course, we've got a lot of sequence challenges, so here is another one. The Kimberling sequence (A007063) goes as following: 1, 3, 5, 4, 10, 7, 15, 8, 20, 9, 18, 24, 31, 14, 28, 22, ... This is produced by shuffling the normal iteration: [1] 2 3 4 5 6 7 8 The first term of the sequence is 1. Aft...
stackexchange_codegolf
Given a letter of the English alphabet, your task is to build a semi-diagonal alphabet to the input. How to build a Semi-Diagonal alphabet? Brief Description: First, you take the position of the letter in the alphabet, P (P is 1-indexed here). Then, you print each letter until the input (inclusive) on a line, precede...
stackexchange_codegolf
Introduction Kerning means adjusting the spacing between the letters of a text. As an example, consider the word Top written with the following three glyphs: ##### ..... ..... ..#.. ..... ..... ..#.. ..##. .###. ..#.. .#..# .#..# ..#.. .#..# .#..# ..#.. ..##. .###. ..... ..... .#... ..... ..... .#... We could just fil...
stackexchange_codegolf
It is well known that a person on a grid under the influence of alcohol has an equal chance of going in any available directions. However, this common-sense statement does not hold in the realm of very small drunkards, whose behavior is very much as if they take every available path at once, and the possible paths they...
stackexchange_codegolf
Challenge : Given a string representing a mathematical expression return the result Input : A string representing a mathematical expression : '1 + 2 - 3 * (2/3 * 1)'. Output : The result after performing all operations. Operators : Possible operators + ---> plus - ---> minus * ---> multiplication / -...
stackexchange_codegolf
This challenge is related to Flipping Pancakes. You may have heard of pancake sorting, where a stack of pancakes is sorted by size by inserting spatula into the stack and flipping all of the pancakes above the spatula, until the pancakes are sorted smallest to largest on the plate. The burnt pancake problem is slightly...
stackexchange_codegolf
A comment I made in chat and the ensuing conversation inspired me to make this challenge. Am I the only one referred to by initials around here? We are all about golfing things down. We can have MB and D-nob and ... O. If I'm known as "CH" then I think everyone else ought to have an initial-based nickname as well. He...
stackexchange_codegolf
Short version RC4, designed in 1987, is one of the most famous stream ciphers. This question asks you to practically demonstrate its 2nd byte bias (for a theoretical proof, see section 3.2 of this paper). Long version OK, here I try to elaborate it for non-cryptographers. As you have noted, RC4 is a very popular cipher...
stackexchange_codegolf
Given an integer k and a list of integers A of size n, find the product of all subsets in A of size k and sum them together. For example, k = 2 n = 4 A = 1 2 3 4 The subsets of size 2 and their products are 1 2 = 2 1 3 = 3 1 4 = 4 2 3 = 6 2 4 = 8 3 4 = 12 which sum together to 35. Some test cases: Input A = 73 36 86 ...
stackexchange_codegolf
The game shapez.io has a lot of shapes. In my previous challenge, the object was to generate a random code for a shape. Now, your challenge is to render a shape. Specs Shapes Each shape has a unique shortcode, for example: is CrWgRuSp - clockwise from top right, red circle, green wedge, uncolored rectangle, purple sta...
stackexchange_codegolf
Emmet is a text-editor and IDE plugin for writing HTML code using much fewer keypresses. You might think of it like a code-golfing HTML preprocessor. Its syntax is based on CSS selectors. Your challenge is to code-golf an implementation of Emmet. Given some Emmet code, output the resulting HTML. Note that for the purpo...
stackexchange_codegolf
Background As you maybe know Ramanujan made this magic square by \$4x4\$ Matrix: This works like all magic squares. But the special thing in this square is that his birthdate is hidden in the first row, the 22\$^{nd}\$ Dec 1887. Challenge Can you make one for your birthdate? Input The User will give Input in this form...
stackexchange_codegolf
Disclaimer: ModTen is a fictional card game which was created for the sole purpose of this challenge. The rules of ModTen ModTen is played with a standard 52-card deck. Because the full rules are yet to be invented, we're going to focus on the hand ranking exclusively. A winning hand in ModTen. Graphics from Wikipedia...
stackexchange_codegolf
All the quine challenges on this site are focused on byte count, or the characters themselves. This one is different. Your challenge is to write a program that produces output which has a code point sum identical to the source's code point sum. To produce a code point sum: Find the values of the characters in the prog...
stackexchange_codegolf
Challenge This coding challenge is to figure out how many rounds the cat can live. In a \$4\times4\$ matrix, there are a number of mice and exactly 1 cat. Example: $$ \begin{array} {|r|r|}\hline & & & ⬜ \\ \hline ⬜ & & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & \\ \hline & & & \\ \hline \end{array} $$ But in each square of t...
stackexchange_codegolf
Let's play code golf... by playing golf. Input Your input will be a string consisting of #'s, an o, an @, and .'s. For example: ......@.. .....##.. ......... ......o.. . - playable golf course (all shots must end on one of these) # - a barrier (shots cannot go through this) o - the starting position of your golf ball ...
stackexchange_codegolf
Sequence Definition Construct a sequence of positive integers a(n) as follows: a(0) = 4 Each term a(n), other than the first, is the smallest number that satisfies the following: a) a(n) is a composite number, b) a(n) > a(n-1), and c) a(n) + a(k) + 1 is a composite number for each 0 <= k < n. So we start with a(0) =...
stackexchange_codegolf
Background When you run tail -f file in bash, the file is outputted and then any subsequent appends. However, when you remove something that has already been displayed, tail outputs: tail: nameoffile: file truncated Your Challenge When given an input f, append tail: [value of f]: file truncated (with trailing & leadin...
stackexchange_codegolf
Draw the parabolic trajectory of a thrown ball. The input is the ball's initial upward velocity, a positive integer v. Every second, the ball moves 1 space right and v spaces vertically, and then v decreases by 1 to due to gravity. So, the upward velocity eventually steps down from v to 0 and down to -v, finally falli...
stackexchange_codegolf
Given a string as an input (which can be any acceptable/convenient format in your language), implement pendulum encoding. The test cases are split into individual items (which aren't quoted) for a visually appealing explanation. How do I do that? The current iteration index starts at 0. If the iteration index is even,...
stackexchange_codegolf
What are some tips on how to shorten this code even further? The code is meant to compute the parallel resistance of an electric circuit. Using scanf float r;main(){float a;scanf("%f",&a);r+=1/a;printf("%f",1/r);main();} Using command-line arguments #include<stdlib.h> float r;main(c,v)char**v;{for(int i=1;i<c;)r+=1/at...
stackexchange_codegolf
Minecraft inventory management is hard. You have 17 diamonds, but you need 7 to craft an enchantment table, a pickaxe, and a sword. Do you pick them up and right click 7 times? Or do you right click once and right click twice and take the 7 left? It's so confusing! for those of you who are now confused, don't worry, I'...
stackexchange_codegolf
Write the shortest possible program or function that will join a list of columnar strings. For this challenge, columnar strings are defined as one-character-wide strings spanning across multiple lines. Each character, except for the last one, is separated by a newline character. Some examples, separated by ---: a b c d...
stackexchange_codegolf
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...
stackexchange_codegolf
Wise is a simple bitwise language I designed a while back. It is based around Python's bitwise operations. It has several operations most of these are the same or very similar to the equivalent symbol in Python. : Duplicate the top of the stack ? Rotate the top of the stack to the bottom ! Rotate the bottom of the s...
stackexchange_codegolf
Blackjack, also known as twenty-one, is a comparing card game between yourself and a dealer, where each player in turn competes against the dealer, but players do not play against each other. Play goes as follows, the dealer deals you a card. The dealer then deals them-self a card, face down. The dealer then deals yo...
stackexchange_codegolf
Your task In your language of choice: create a program that outputs 1 This 1 may either be a string or value equivalent to the number one. The shifting catch If you take the unicode codepoint (or whatever codepoint encoding your languages uses if not UTF) for each character in your program, and shift each of those valu...
stackexchange_codegolf
A Latin Square is a square of size n × n containing numbers 1 to n inclusive. Each number occurs once in each row and column. An example of a 3 × 3 Latin Square is: [[1, 2, 3], [3, 1, 2], [2, 3, 1]] Another is: [[3, 1, 2], [2, 3, 1], [1, 2, 3]] Given an integer input n where n > 0, determine how many Latin Square...
stackexchange_codegolf
Based on a chat message The Challenge Given an input number \$n > 9\$, construct its reverse, ignoring leading zeros. Then, construct a list of all prime factors that the number and its reverse don't have in common. Multiply those factors together to create the Uncommon Factor Number of the input. Or, to put it another...
stackexchange_codegolf
Let \$A\$ be a square matrix that is at least \$2 \times 2\$ where each element is an integer. \$A^2 = A \times A\$ will then have the same dimensions as \$A\$, and will have integer elements. For example, let $$A = \left[ \begin{matrix} -3 & 2 \\ 0 & -1 \end{matrix} \right]$$ Therefore, $$\begin{align} A^2 & = \left...
stackexchange_codegolf
The Task The task is easy: given an Alpha-2 country code, output the Alpha-3 equivalent. The input may be in any case you choose, and the output in any consistent case of your choosing. Here are the codes: [["AF", "AFG"], ["AX", "ALA"], ["AL", "ALB"], ["DZ", "DZA"], ["AS", "ASM"], ["AD", "AND"], ["AO", "AGO"], ["AI", "...
stackexchange_codegolf
Given an inconsistently indented piece of html code your task is to return the same text but correctly indented Indent space = 4 Assume input will be non-empty. Input can be taken as string or array/list of lines Opening and closing tags must be on the same line as long as there is not any other tag inside. <td></td>...
stackexchange_codegolf
Given an input of a 2 dimensional array of integers, rotate the array 90 degrees clockwise. It should work for rectangular arrays of all sizes and proportions. The rotated array should be printed at the end of the program. Example: Input: [[0,1,2,3,4,5], [6,7,8,9,0,1], [2,3,4,5,6,7], [8,9,0,1,2,3]] Output: [[8,2...
stackexchange_codegolf
This is a code-shuffleboard answer-chaining challenge, where the answers will aim to, together, output the lyrics to this beloved 80s song. This is the full lyrics of the song, line by line. The first answer will contain a program that will output the first line of the song (We're no strangers to love). The second wil...
stackexchange_codegolf
This is my first question in Code golf I found it in stack-overflow (originally in JavaScript however all languages are acceptable): Render on screen NxN (where N in range 1-16) grid where each cell have black boundary and red number inside - cells are numerated in hex starting from left-upper corner to bottom-right. E...
stackexchange_codegolf
Stack Cats is a reversible, stack-based language. Its reversible nature makes for somewhat weird loops. This challenge is about the conditional loop (...). When these loops are nested in certain ways, it's possible to transform the code to reduce the nesting depth. Here are the rules (where A and B stand for an arbitra...
stackexchange_codegolf
Introduction cowsay is a Unix command made by Tony Monroe, written in Perl. It outputs a picture of a cow saying given text. For example: ________________________ < Typical cowsay output! > ------------------------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | ...
stackexchange_codegolf
Time for a new typography challenge! It’s a common problem when copy-pasting between various document formats: hyphenation. While it reduces the raggedness of a left-aligned layout or evens spacing in a justified layout, it’s a complete pain when your PDF is not properly constructed and retains the hyphens in the layou...
stackexchange_codegolf
Related Goats are great. Everybody loves goats. And they also, for some reason, are an excellent complex ascii art for many languages to have built-ins for. Because of this, I personally feel a catalogue to document just how easily a language can print goats is greatly needed. The Challenge Given an integer input via a...
stackexchange_codegolf
This is the cops' challenge. To post a robber, go here. In this challenge, cops will invent a (likely simple) programming language, and write an interpreter, transpiler, or compiler that allows you to run it. Robbers will write a program in this language that manages to inject arbitrary code into the interpreter, trans...
stackexchange_codegolf
Not a new one: Input N, being n, 0 ≤ n ≤ 5. Output N times "Hello World." Example: Input 3 Output Hello World. Hello World. Hello World. These 2 are my best solutions: First public class Out { public static void main(String[] a) throws Exception { java.io.OutputStream o = System.out; ...
stackexchange_codegolf
Background You are planning your trip away from the Diamond City, and must travel through Diamond Road. However, Diamond Road branches away from Diamond City to different locations. Out of curiosity, you'd like to measure the total distance of unique roads used for all paths. We define a path as a string that only cont...
stackexchange_codegolf
Note: This is the radiation-hardening version of my previous challenge Pristine Bit Checking. This should be much more difficult than that one. Write a program/function that takes two integers in the range \$0\$ to \$255\$ inclusive, and returns whether the binary forms of the numbers are exactly one bit different. Fo...
stackexchange_codegolf
This challenge is to write fast code that can perform a computationally difficult infinite sum. Input An n by n matrix P with integer entries that are smaller than 100 in absolute value. When testing I am happy to provide input to your code in any sensible format your code wants. The default will be one line per row of...
stackexchange_codegolf
Setup Take the following 4x4x4 cube along with a 2D view of 3 of its faces, with a common 1x1x1 cube highlighted: The arrows represent the points of view that generated the V1, V2 and V3 faces drawn underneath the big cube. Given an arrangement of some 1x1x1 cubes inside the main cube we can try and identify it with o...
stackexchange_codegolf
You are on a plane filled with boxes, and you get a sequence of movements, say "up right right down left": You move up, pushing all boxes in front of you away: You move right, right and down, getting and finally left. This time you only push one box rather than infinite boxes: At the end, there are 4 spaces. Given ...
stackexchange_codegolf
Let \$n=42\$ (Input) Then divisors are : 1, 2, 3, 6, 7, 14, 21, 42 Squaring each divisor : 1, 4, 9, 36, 49, 196, 441, 1764 Taking sum (adding) : 2500 Since \$50\times 50=2500\$ therefore we return a truthy value. If it is not a perfect square, return a falsy value. Examples : 42 ---> true 1 ---> true 246 ---> true 1...
stackexchange_codegolf
The Typical Way to Make an Acronym Out of a Phrase Is to Take the First Letter of Each Word: TTWMAOPITFLEW. howeveR, sometimEs, you can make an acronym of random leTters In a seNtence such As like this: RETINA. The only condition is that the letters have to be in the correct order. For instance: LORD can be acronymise...
stackexchange_codegolf
Introduction In Android Studio and other IDEs there are code completions to assist efficient code insertion (especially when the names of the classes or methods are so verbose), like the one in the image below. There are slightly different logics used between IDEs to determine what classes, methods and variables to su...
stackexchange_codegolf
Given a string that represents a bunch of tables stacked on top of each other and/or arranged side-by-side, disassemble all the tables. Tables A table looks like this: ------- | | | | More formally, a table has a tabletop, composed of n dashes, and two visible legs. (Obviously, there are two hidden behind, but...
stackexchange_codegolf
Given a string of text, output it as a 'tower'. Each slice of the string (of the form 0:n) is repeated 5*n times, so the first character is repeated 5 times, then the first and the second 10 times, etc. Examples: 'hello' -> ['h'] ['h'] ['h'] ['h'] ['h'] ['h', 'e'] ['h', 'e'] ['h', 'e'] ['h', 'e'] ['...
stackexchange_codegolf
A palindrome is a string which is the same when read forwards and backwards. For example "racecar" is a palindrome, but "Racecar" is not. A substring is a contiguous set of characters in a larger string. Your task is to write a program or method which takes a string or character array as input and outputs the length of...
stackexchange_codegolf
Code Python 3, 245 bytes E=print def F(): B,C,A=1,1,1;yield 0 while True:yield B;B,C,A=B+C+A+1,C+A+1,A+1 C=int(input()) D=0 for A in range(C): E(end='*'*(C-(C-A)+1));B=A while 0<B:E(end=' '+chr(42+B)*B);B-=1 E();D+=1 for A in F(): if D==0:E(end=str(A));break D-=1 Try it online! What it does? Takes a number from...
stackexchange_codegolf
Input: An integer n Output: A string A * B Example 12 Possible 2 divisible numbers: 12 * 1, 6 * 2, 4 * 3 12-1 = 11 6-2 = 4 4-3 = 1 4 and 3 has the minimal absolute difference of 1 Therefore, Output: 4 * 3 Order of the numbers does not matter This challenge idea was taken from a puzzle in Clash of Code in https://www...
stackexchange_codegolf
Given string S representing a dollar amount, make change for that amount of money use the least number of coins to make the change and record the amount of each coin in a list. Here are the coins available to use and their value. Coin : Value Dollar Coins : $1.00 Quarters: $0.25 Dimes: $0.10 Nickels: $0.05 Pennies: $0....
stackexchange_codegolf
We're going rootin' tootin' cow-poke shootin! This is a simple contest, first program to draw their pistol wins. How it works: I require 2 things from you, an executable, and a command to be run from a bash terminal. The executable needs to do one thing: wait until it receives 'draw!' from STDIN, and then print 'bang!...
stackexchange_codegolf
Thanksgiving in the United States is coming up on November 24th. Many people will have a large dinner with their families, traditionally including turkey and many side dishes. This typically means the family members must coordinate who's going to bring each of the various dishes. In this challenge, the goal is to write...
stackexchange_codegolf
Inspired by A014486. Challenge Given an integer input in base 10, construct a representation for the binary forest corresponding to the input. Representations include, but are not limited to, nested arrays and strings. How? Convert the input to binary. 1s represent branches, and 0s represent leaves. To make this easier...
stackexchange_codegolf
The periodic table gets its shape from the arrangement of elements into blocks: An element is assigned its block based on what type of orbital holds its valence electron(s). For instance, the sole valence electron of neutral hydrogen occupies the 1s orbital in the 1s subshell, and so hydrogen belongs to the s-block. T...
stackexchange_codegolf
I was doing some investigation into trig functions using compound angles recently, and noticed that the results are really long and tedious to write: $$ \cos(A+B) = \cos A \cos B - \sin A \sin B \\ \cos(A-B) = \cos A \cos B + \sin A \sin B \\ \sin(A+B) = \sin A \cos B + \sin B \cos A \\ \sin(A-B) = \sin A \cos B - \sin...
stackexchange_codegolf
You want to find the length shortest path between two points, on an 2d ASCII "map". The roads are made up of + characters, and the two endpoints are represented by #s (not counted in the length). This road can be arranged in any way, and any other characters can be ignored. You can assume the endpoints will always conn...
stackexchange_codegolf
The objective is to produce output of n squares (nxn) of random integers (0-9) with a moving * that rotates clockwise around the corners, starting from the top left. The squares should be side by side and separated by a single space. If n = 0, the output should be empty. Output for n=1: * Output for n=2: *3 4* 14 07 O...
stackexchange_codegolf
Given integers k and n, generate a sequence of n unique k-tuples of pairwise coprime integers. Every such tuple must occur once eventually, that is, for any existing k-tuple of pairwise coprime integers, some n will eventually generate it. The output may be printed or evaluated in any list/tuple-like form. Definitions ...
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
Write a piece of JavaScript code that calls alert with an array containing the first 50 Fibonacci numbers in order. You may only use the following characters: +!()[]. As a reference, your code must be functionally equal to the following: var fib = [], a = 1, b = 1; for (var _ = 0; _ < 50; _++) { fib.push(a); va...
stackexchange_codegolf
Challenge Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers (integers with absolute difference 1) are next to each other. Examples 4 → [1, 3, 0, 2] 5 → [0, 2, 4, 1, 3] 6 → [0, 2, 4, 1, 3, 5] 7 → [0, 2, 4, 1, 5, 3, 6] You may use 1-indexing instead...
stackexchange_codegolf
Write a cat program, a quine, and a Hello World in the same language such that when two specific programs of the three are concatenated in a certain order, you get the third program. It does not matter which program is the first, second, and third are as long as all three types are represented once each. e.g. if \$A\$ ...
stackexchange_codegolf
Objective Given a vertex figure consisting of regular convex polygons, determine whether it represents a convex uniform polyhedron. What is a uniform polyhedron? A uniform polyhedron is a polyhedron whose faces are regular polygons, while having the same vertex figure for each vertices. Generally a uniform polyhedron c...
stackexchange_codegolf
Given a "T" shape on an x * y number grid, with length W on the top bar and H on the stem of the T, with the bottom of the T on the square numbered n: calculate the total of all of the numbers in the T shape. W must be an odd number and all must be positive integers. Here are some examples of valid T's on a 9*9 grid: ...
stackexchange_codegolf
For a while now, I've been running into a problem when counting on my fingers, specifically, that I can only count to ten. My solution to that problem has been to count in binary on my fingers, putting up my thumb for one, my forefinger for two, both thumb and forefinger for three, etc. However, we run into a bit of ...
stackexchange_codegolf
Pyth is perhaps the most successful general-purpose golfing language. Though it is somewhat in decline as a result of newer languages, from 2014 to 2016 Pyth's concise syntax, constant updates, overloading, and (for its era) many builtins made it a favorite for the majority of questions. Pyth code is often difficult to...
stackexchange_codegolf
Input Your input is a single string, separated by newlines into 2n+1 lines of length 2n+1, for some integer n ≥ 0. The integer n is not part of the input; you'll have to compute it from the string. The lines are composed of the "direction characters" >^<v. If newlines pose a problem, you can replace them by vertical pi...
stackexchange_codegolf
Note: There are some rude words in this question. There's an implicit puzzle posed in this classic Monty Python sketch (you can also ready the script online). Various phrases are described as being 'woody' or 'tinny', and one is described as being 'PVC'. Given a phrase, respond with its type according to the following...
stackexchange_codegolf
Write a program or function that takes no input but prints or returns a constant textual depiction of a rectangle made of the 12 distinct pentominoes: The rectangle may have any dimensions and be in any orientation, but all 12 pentominoes must be used exactly once, so it will have area 60. Each different pentomino mus...
stackexchange_codegolf
Given a BF program consisting of only the characters +-[]<>., with the property that there's an equal number of < and > between every matching pair of []. You have to find the shortest program that can be achieved with the optimal memory layout (by rearranging the cells on the tape). If there are multiple such programs...
stackexchange_codegolf
or: Build a vertical quine Inspired by Take a stand against long lines. Your task is to build a vertical quine with as short a line length as possible. Scoring Shortest line length (excluding newlines) wins, with code-golf criteria as a tie-breaker. Line length is determined as the longest line in your program excludin...
stackexchange_codegolf
Miller-Rabin test Given a base \$b\$ and an odd number \$n\$: Write \$n\$ as \$2^{s}\times d + 1\$ where \$d\$ is odd \$n\$ is a strong probable prime if either: \$b^d\equiv 1 \pmod n\$ \$b^{d\cdot2^r}\equiv -1 \pmod n\$ for any non-negative \$r\$ strictly less than \$s\$. A strong probable prime which is composite ...
stackexchange_codegolf
Briefing You are a bot, in a 2D grid that extends infinitely in all four directions, north, south, east and west. When given a number, you must move the bot so that you get to the target number. Here's how the grid works: You can move in 4 directions: north, south, east or west. Once you move off a cell, you are not al...
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
Given a string that is one of the directions on a 16-point compass rose output the two directions that are immediately adjacent to the input direction, in clockwise order. Specifically, you need to handle these (and only these) input/output pairs: Input Output N NNW NNE NNE N NE NE NNE ENE ENE NE E E ...
stackexchange_codegolf
Let \$R, C\$ be positive integers and let \$0 < s \leq 1\$. Consider the \$R \times C\$ matrix \$\mathbf M\$ defined as \begin{equation} M(i,j) = \frac{\mathrm{mod}\,(j, i^s)}{R^s}, \quad i = 1, \ldots, R, \quad j = 1, \ldots, C \end{equation} where \$\,\mathrm{mod}\,\$ denotes the modulo operation: for \$a,b > 0\$ not...
stackexchange_codegolf
The following puzzle was asked in puzzling SE. This puzzle is quite hard to solve by hand because every answer depends on another answer. So, for example, a solution with all answers being A does not work because then the question 7 would contradict question 8, for example. One of the answers there at puzzling SE sugge...
stackexchange_codegolf
For a 2 dimensional array we will define the elements in either the first row or the last column to be the largest "J-Bracket" of the array. For example in the following array elements in the J-bracket are highlighted: \$ \begin{bmatrix} \color{red}{\underline 1} & \color{red}{\underline 2} & \color{red}{\underline 4}...
stackexchange_codegolf
Lets say your job is to paint poles, and a client asks you to paint a pole with 4 red sections and 3 yellow sections. You can do that pretty easily as follows: r y r y r y r With just yellow and red stripes. Now lets say your client asks you to paint a pole with 2 red sections, 2 yellow sections, and 1 green section...
stackexchange_codegolf
Challenge Output the person on PPCG who has cast the most upvotes and the person who has cast the most downvotes. Voters You should only look at the people who have cast more than 1000 votes in total. To find the person who upvotes the most, you should the find the person with the highest upvotes/total votes value. Sim...
stackexchange_codegolf
Goal: Write a program or function which prints an input string in a sinusoidal shape. The ASCII sinusoid Here is one period of the sinusoid: ....... ... ... .. .. . . ...
stackexchange_codegolf
In this challenge, you are given a map of a two-dimensional terrain, viewed from the side. Unfortunately, some parts of the terrain are floating in the air, which means they'll come crashing down. Your job is to predict where they land. The Input Your input is one or more newline-separated strings of equal lengths, con...
stackexchange_codegolf