instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
This challenge is about computing the chromatic number of special types of graphs. Input The input will consist of two integers. A positive integer \$n > 1\$. A distance \$d < n\$. Task The two inputs values will define a graph with \$2^n\$ nodes. Each node corresponds to a different binary array of length \$n\$. Tw...
stackexchange_codegolf
I have read: Tips for golfing in Python I would like to golf this code further. Any more tips? x,y,q,w=[int(i) for i in raw_input().split()] while 1: a=int(input()) s=d="" if q>x: s="W" q-=1 elif q<x: s="E" q+=1 if w>y: d="N" w-=1 elif w<y: d="S" w+=1 print d+s The program: You move on a map whi...
stackexchange_codegolf
In the game of chess, there is piece called the queen that may attack any other piece that is on the same row, column or diagonal. In chess there are typically two sides, black and white, with each piece belonging to one of the teams. Pieces may not attack pieces belong to the same team. Your goal is to find out the ...
stackexchange_codegolf
Your challenge is to print x digits of pi where x is your code length. Examples: Source code (length) -> output foo! (4) 3.141 foobar (6) 3.14159 kinda long (10) 3.141592653 +++++ (5) 3.1415 123456789 (9) 3.14159265 You can use floor(π/10 * 10code_length) / 1...
stackexchange_codegolf
The name of the challenge was prompted by this GIF and the GIF also gave me the idea. Your challenge today is to take a input guaranteed to be \$2<=n<=100\$ and output a sequence of x and - characters. The output for a number N represents a sequence of operations applied to 1 where x means "multiply by 2" and - means "...
stackexchange_codegolf
Sandbox The major scale (or Ionian scale) is one of the most commonly used musical scales, especially in Western music. It is one of the diatonic scales. Like many musical scales, it is made up of seven notes: the eighth duplicates the first at double its frequency so that it is called a higher octave of the same note....
stackexchange_codegolf
Given: a 12 hour time t in hours and minutes, a rotation r in degrees, return the time shown when an analog clock that is displaying the time t is rotated r degrees clockwise. After rotation, the hour hand will not line up with the new position of the minute hand. To correct for this, the new hour can be derived fro...
stackexchange_codegolf
The task Given an ascii string, output a program in my esolang MAWP that outputs the inputted string when run. Useful functions in MAWP Numbers from 0-9: Pushes the number to stack M Takes the top two numbers off stack and pushes the sum to stack A Takes the top two numbers off stack and...
stackexchange_codegolf
The Euclidean GCD Algorithm is an algorithm that efficiently computes the GCD of two positive integers, by repeatedly subtracting the smaller number from the larger number until they become equal. It can be visualised as such: We start with a MxN grid, where M and N are the numbers. In this example I'll use M=12, N=5: ...
stackexchange_codegolf
4, 32, 317, 3163, 31623, 316228, 3162278, 31622777, 316227767, 3162277661, 31622776602, 316227766017, 3162277660169, 31622776601684, 316227766016838, 3162277660168380, 31622776601683794, 316227766016837934, 3162277660168379332, 31622776601683793320, 316227766016837933200, 3162277660168379331999, 31622776601683793319989...
stackexchange_codegolf
The rundown Create a program that generates an array of random length with random numbers, then apply a series of rules that alter the array. After the rules have been applied, print the sum of the array unless specified otherwise Array setup The array must be a random length between 5 and 10 inclusive, with random int...
stackexchange_codegolf
The first programming language I was exposed to was Sinclair BASIC. Like many BASIC dialects, it requires all source code lines to be numbered. As a result, use of the GO TO command was idiomatic and jumps execution to the given line number (no labels). Also there is a related GO SUB command which can be used as a rud...
stackexchange_codegolf
Your input will consist of an 18×18 image in any reasonable format, containing a horizontally and vertically centered 14px Roboto Mono character. This can be any of 94 printable ASCII characters (not including the space). But: you only need to be able to recognize some 80 character subset of your choice. Output should ...
stackexchange_codegolf
Inspired by this challenge Given an integer in the range 0 <= n < 2**64, output the minimum sized container it can fit in out of bit: 1 nibble: 4 byte: 8 short: 16 int: 32 long: 64 Testcases: 0 -> 1 1 -> 1 2 -> 4 15 -> 4 16 -> 8 123 -> 8 260 -> 16 131313 -> 32 34359750709 -> 64 This is code-golf, so the shortest ans...
stackexchange_codegolf
The aim is to parse a sentence and compress/encrypt it according to the rules below and then decrypt it using the key: Remove all letters in a word before the first vowel is encountered. Example: pigeon becomes igeon. All characters except alphabets should be kept in the sentence including numerals, punctuations, etc....
stackexchange_codegolf
In the fewest bytes possible, determine whether the two values given each match one of the following: First value 2 string or integer - whichever you prefer to case insensitive too case insensitive two case insensitive t0 case insensitive (t zero) Second value b case insensitive be case ins...
stackexchange_codegolf
Task Produce this 24kB ASCII art output: ________ \ \ ________ \____ \ ...
stackexchange_codegolf
I have 2 inputs: 1 single number and some numbers separated by whitespace: 1 1 2 3 4 5 I want to loop over the second input, and I don't need the first input. I did this, which works: input() for x in input().split():somecode() But can I go directly to the second input without doing the input() at the beginning or wi...
stackexchange_codegolf
A Window is an ASCII-art square with odd side length of at least 3, with a single character border around the edge as well as vertical and horizontal strokes in the middle: ####### # # # # # # ####### # # # # # # ####### An MS Window is a window where the border is made only of the characters M and S. Your tas...
stackexchange_codegolf
Try it online! currently has 680 listed languages, all of which are searchable. For most of those languages, when searching for it, you don't have to enter the entire string. For example, entering lega results in just 05AB1E (legacy) appearing, and entering d+ results in only Add++. However, for some languages, there i...
stackexchange_codegolf
Using the shortest JS (ES5) code possible, as measured in number of characters, gather all the ids on a page for foobar elements into a comma-delimited string. For example: <div> <foobar id="456"></foobar> <foobar id="aaa"></foobar> <foobar id="987"></foobar> <div> Should give "456,aaa,987" You cannot use ES6 o...
stackexchange_codegolf
Consider the following spiral of positive integers: We now define grambulation as a binary operation \$\lozenge : \mathbb N \times \mathbb N \to \mathbb N\$, using this grid. Some example inputs and outputs for grambulation are: \begin{align*} 1 & \lozenge 9 = 25 \\ 1 & \lozenge 2 = 11 \\ 11 & \lozenge 10 = 25 \\ 9 & ...
stackexchange_codegolf
Inspired by this tweet where a user stated the following: it's insane how much code would be cleaned up if JS got pipes and pattern matching i often do this since it's the best way to make use of TS inference and pattern matching would make it less hacky const result = (() => { if (scenario1) { return { t...
stackexchange_codegolf
In this challenge you will receive a list of pairs of non-negative integers representing a mushroom forest. Each pair represents a mushroom whose center is at that horizontal coordinate. The only part of the mushroom we care about is the cap (the flat bit at the top). The first integer in each pair represents which ro...
stackexchange_codegolf
Given: a 12 hour time t in hours and minutes, a rotation r in degrees, return the time shown when an analog clock that is displaying the time t is rotated r degrees clockwise. After rotation, the hour hand will not line up with the new position of the minute hand. To correct for this, the new hour can be derived fro...
stackexchange_codegolf
Suppose you have two six-sided dice. Roll the pair 100 times, calculating the sum of each pair. Print out the number of times each sum occurred. If a sum was never rolled, you must include a zero or some way to identify that that particular sum was never rolled. Example Output: [3, 3, 9, 11, 15, 15, 11, 15, 7, 8, 3] ...
stackexchange_codegolf
Input a datetime, format the datetime in YYYY-MM-DD HH:mm:ss format using 30-hour clock time. The 30-hour clock time works as: After 6 a.m., it is same as 24-hour clock time Before 6 a.m., it use date for previous day, and plus Hours by 24. For more examples, you may checkout the testcases. Rules To simplify the que...
stackexchange_codegolf
In 2015 the Portland International Airport began the replacement of their iconic carpet. I want you to write a program to draw their old carpet in as few bytes as possible. The carpet: Specifications Here is a link to a scalable pdf image of one tile. Your output should match the relative dimensions and placement o...
stackexchange_codegolf
Challenge Given a positive-length string \$S\$, a divisor of \$S\$ is another (not necessarily distinct) string for which there exists a number \$a\$ such that when we repeat the divisor \$a\$ times, we get the string \$S\$. For example, the string abcd is a divisor of the string abcdabcd with \$a=2\$. Your challenge i...
stackexchange_codegolf
Assume you're writing in one method, (or whatever you call them) with 3 inputs: the first string, a character that contains a +, - or * symbol, and the second string. Example in Java: public String strCalc(String str1, char sym, String str2) { //code... } What it should return: str1 sym str2 ans A + A = B ...
stackexchange_codegolf
The purpose of this challenge is to solve the original first Project Euler problem, but as the title suggests in constant time (with respect to the size of the interval). Find the sum of all the multiples from a list of numbers in some defined range, in such a way that the running time of your program runs in constant...
stackexchange_codegolf
Take a line of input (function arguments or stdin, etc.). Remove comments in it, where a comment starts and ends with ". Do not remove comments in string literals, which start and end with '. String literals do not contain escapes, because smalltalk has nice, easily lexable syntax ;). Output this string. The number of...
stackexchange_codegolf
The task is to write a radiation-hardened irradiator. What do I mean by that, exactly? An irradiator is a program that, when given a string as input, will output all possible versions of the string with one character removed. For example, given the input Hello, world!, the program should output: ello, world! Hllo, worl...
stackexchange_codegolf
What general tips do you have for golfing in Grass? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Grass (e.g. "remove no-op characters" is not an answer). Please post one tip per answer.
stackexchange_codegolf
Introduction An abstract syntax tree (AST) is a tree of tokens that shows their connection to each other and syntactical meaning. They are commonly used in compilers and static analysis tools, as parsing a language into an AST helps remove any ambiguity and can be helpful for optimizations. Many ASTs are large and comp...
stackexchange_codegolf
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. On the flight to Hawaii for vacation, I'm playing with a deck of cards numbered from 1 to \$n\$. Out of curiosity, I come up with a definition of "magic number" for a shuffled deck: The magic number of a shuffle is the minimum number ...
stackexchange_codegolf
Your task is to write a program that performs case conversion from plain text, and other case formats, into one of the specified formats below. Inputs will be either plain lowercase text, or one of the detailed cases below. You must remove non-alphabetic characters except (space), _ (underscore) and - (hyphen), then ...
stackexchange_codegolf
Implement the Discrete Cosine Transform (DCT). This may implemented as either a function or a program and the sequence can be given as either an argument or using standard input. Your program must be able to handle sequences of any length (assuming a hypothetical version of your language which has no limits on things l...
stackexchange_codegolf
Input A dictionary with string keys and string values. Output The 'inversedict' of this dictionary. How to make an inversedict An inversedict is a dictionary with string keys and string array values. The keys are the values from the original dictionary, and the values are the keys from the original dictionary with th...
stackexchange_codegolf
Given an 8086 segmented ("logical") memory address, output its actual linear physical address. A segmented memory address has format xxxx:xxxx, where each of x is one of 0-9A-F, and the two parts are parsed as hexadecimal integers. Both parts are exactly 4 digits. To get its actual linear address, multiply the first pa...
stackexchange_codegolf
This is a cops-and-robbers if you are not familiar with the format click the tag to go to the wiki. There will not be a robbers' thread for this question. Cops Your task as Cops is to select two sequences from the Online Encyclopedia of Integer Sequences and write a program that takes the nth element of one sequence a...
stackexchange_codegolf
First of all ... I would like to wish everyone a Merry Christmas (sorry if I am a day late for your timezone). To celebrate the occasion, we are going to draw a snowflake. Because the year is 2015 and Christmas is on the 25th (for a large portion of persons), we will draw a Pentaflake. The Pentaflake is a simple fracta...
stackexchange_codegolf
Two rows of a matrix are orthogonal if their inner product equals zero. Call a matrix with all rows pairwise orthogonal an orthogonal matrix. A circulant matrix is one where each row vector is rotated one element to the right relative to the preceding row vector. We will only be interested in matrices where the entries...
stackexchange_codegolf
Given a string of text that contains lowercase letters, encode it as follows: (I will be using abcdef) First, encode the alphabet cipher, but this time, 0-indexed. 000102030405 Reverse it. 504030201000 Loop through the string. If the next two digits together are 25 or smaller, encode those two numbers. 5 04 03 02 01...
stackexchange_codegolf
I would like to convert ASCII art to something that takes less bytes. I have string like this: my $string = ' ██ ████ █'; And I would convert this to something like this: print "█" x 1."█" x 1."█" x 1"█" x 1"█" x 1; So I would write this in one line and convert to using x operator. How can achieve ...
stackexchange_codegolf
Given three integers >= 2, create an ASCII cube in an orthogonal (cabinet) projection. The three integers represent height, width and depth (measured in visible characters) including the corners. The corners should be 'o's or '+', free choice. w: 10, h: 5, d: 4 Thus gives: o--------o / /| / / | o...
stackexchange_codegolf
I found this YouTube video with a table on it showing some card suits with ampersands. You might not understand what it is about, but I still want to make a challenge about it. The input is two suits, being one of the following: heart diamond spade club You can do anything for any other input. Then the output is their...
stackexchange_codegolf
Inspired by this challenge Goal: The goal is to draw waves crashing onto a beach. Input: You will be given 3 integers (in whatever format you want) as input. The first integer will be the length of the drawing The second integer will be the index of the sandbar, where the waves start to crest (at least 3 spaces from ...
stackexchange_codegolf
Your task is to create a program/function to replicate this word generator. Details Your program/function take two input. One input is the categories. The other input is the syllable types. Categories categories will consist of classes of letters. For example, V=aeiou means that the letters a, e, i, o, and u will be cl...
stackexchange_codegolf
The purpose of this challenge is to solve the original first Project Euler problem, but as the title suggests in constant time (with respect to the size of the interval). Find the sum of all the multiples from a list of numbers in some defined range, in such a way that the running time of your program runs in constant...
stackexchange_codegolf
Your task is to generate the nth term of the RATS sequence, where n is the input. The RATS sequence is also known as the Reverse Add Then Sort sequence. This sequence can also be found here: http://oeis.org/A004000. test cases: 0 > 1 1 > 2 2 > 4 3 > 8 4 > 16 5 > 77 6 > 145 7 > 668 For example, the output for 5 is 77 b...
stackexchange_codegolf
I'm new to ES6 and code-golfing. Here's the original function: function puzzle(n, x) { return n * Math.pow(2, x); } And here's what I have so far: let puzzle=(n,x)=>n*2<<(x-1) But the solution requires lesser characters. I went through the 'Code Golfing with ES6' thread, but couldn't find a better way. Any he...
stackexchange_codegolf
This challenge is simple: Take a path to an png image file as input and overwrite that file with a copy of itself rotated 90 degrees clockwise. You may assume that the file has dimensions of 128x128 pixels. You may not use image metadata modifications (like Exif) to rotate the image; the pixels themselves must be trans...
stackexchange_codegolf
Input no input for this challenge The Challenge Write a code that outputs: The first 10 prime numbers whose sum of their digits equal the number of bytes of your code Examples Let's say your code is Co&%423@k"oo" which is 13 bytes your code must output [67, 139, 157, 193, 229, 283, 337, 373, 409, 463] those are the fi...
stackexchange_codegolf
Task: Your task is to create two programs in different languages that can communicate one-way to each other. Your sending (tx) program will take input, for either stdin or a query, and send it along to the receiving (rx) program. Your rx program will then print out the data that it receives. Rules: The two programs mu...
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
Given a string of text that contains lowercase letters, encode it as follows: (I will be using abcdef) First, encode the alphabet cipher, but this time, 0-indexed. 000102030405 Reverse it. 504030201000 Loop through the string. If the next two digits together are 25 or smaller, encode those two numbers. 5 04 03 02 01...
stackexchange_codegolf
Inspired by this post over on Puzzling. Spoilers for that puzzle are below. Given three positive integers as input, (x, y, z), construct the inclusive range [x, y], concatenate that range together, then remove z not-necessarily-consecutive digits to produce the largest and smallest positive integers possible. Leading z...
stackexchange_codegolf
This is a potato: @@ @@@@ @@@@@@ @@@@@@ @@@@ @@ More generally, a size N potato is defined as the following shape: If N is even, it is 2 centered @ symbols, followed by 4 centered @ symbols, followed by 6 centered @ symbols, all the way up to N centered @ symbols; then, N centered @ symbols, followed by N-2 ce...
stackexchange_codegolf
Given a pattern representing a list of lengths, and a string representing those lengths, do they match? For those interested, this is question equivalent to verifying if a row or column of a Nonogram may be correct. However, I have omitted all language relating to Nonograms to make the question less confusing for those...
stackexchange_codegolf
One day in July 2020, I made the following C program: #define A m] a[9999],*m=a;main(){for(2[A=4[A=1;;){for(;4[A;putchar(6[m-=3]+48)); for(puts(a);7[A;2[A=4[A,4[A=1)if(4[A+=3[m+=3]-1,9<(3[A=2[A+=3[A))++ 5[A,7[A=1,3[A-=10;}} with three superfluous newlines removed, it's 167 bytes and it prints the fibonacci sequence (a...
stackexchange_codegolf
We define \$R_n\$ as the list of remainders of the Euclidean division of \$n\$ by \$2\$, \$3\$, \$5\$ and \$7\$. Given an integer \$n\ge0\$, you have to figure out if there exists an integer \$0<k<210\$ such that \$R_{n+k}\$ is a permutation of \$R_n\$. Examples The criterion is met for \$n=8\$, because: we have \$R_8...
stackexchange_codegolf
Here's a scenario: A grandmother and grandfather forget what their GMail password is. They know the word, but can't remember which letters are capitals. The challenge is to take a word given and print(stdout) every combination of capital letters possible, essentially "brute-forcing" but only on a given string. Example...
stackexchange_codegolf
Randomness is fun. Challenges with no point are fun. Write a function that, given integer input n, will output a set (unordered, unique) of exactly n random integers between 1 and n^2 (inclusive) such that the sum of all integers is equal to n^2. Randomness does not have to be uniform, provided each valid set has a non...
stackexchange_codegolf
Stuttering is a problem which many of us might have experienced or at least seen it. Although most of famous speech recognition softwares have serious issues with stuttered speaking, let's imagine a software which understands stuttering, but cannot fix them and only writes them as is. An example written text by such a ...
stackexchange_codegolf
People have written many things allowing one thing to be visualized as another. Now I propose being able to translate letters to music! Its your job to write a program that takes a text file and outputs a sound file with each letter converted to a specific note from C3-C8. Disclaimer - I don't actually expect the music...
stackexchange_codegolf
Background Supplementary reading 1, Supplementary reading 2 Linear lambda calculus is a limited form of lambda calculus, where every bound variable must be used exactly once. For example, \a b c d e -> a b (d c) e is a valid term in linear lambda calculus. When embedded as a logic system, this enforces each input to be...
stackexchange_codegolf
The JavaScript compressor RegPack uses a very simple string compression algorithm. Given a piece of code, it will make a list of characters that aren't used in that code and use them to delimit repeated strings that are inserted back into the string. To show how strings are compressed, it's necessary to show how the de...
stackexchange_codegolf
Text may be translated to a written version of TUT language by replacing each letter by the corresponding "TUT word", as given in the following table (adapted from the linked article)*: a e h hash o o u yu b bub i ay p pup v vuv c kut j jag q kwak w waks d du...
stackexchange_codegolf
Introduction We know that the factorial notation is valid for all natural numbers. However, Euler had extended it for all positive real numbers, as well as for complex numbers by defining a function, which is known as the Gamma Function. It is represented by Γ. Challenge You will be given a non-negative floating point ...
stackexchange_codegolf
Introduction Braincopter is an esoteric Brainf*** derivative that encodes a Brainf*** program as an image. As a 2D language, it uses two additional commands; they rotate the instruction pointer (initially pointing right) clockwise and counterclockwise. Braincopter is very similar to Brainloller, except that instead of ...
stackexchange_codegolf
Buzzby Berkeley Robot Hokey Pokey Task Write a program or function to produce an ASCII art animation depicting a line of robots dancing to the lyrics of the Hokey Pokey (or Cokey, if you prefer) in the style of a Busby Berkeley number! Example Output Input Accepts three arguments (assumed to be valid): N = number of r...
stackexchange_codegolf
Challenge Write a program that greets a user depending on what time of day (GMT) it is. Output A string (printed or returned) according to these rules: If the time is 06:00 to 11:59 the greeting has to be "Good morning" If the time is 12:00 to 17:59 the greeting has to be "Good afternoon" If the time is 18:00 to 19:5...
stackexchange_codegolf
Introduction There are lots of utilities out there capable of creating a high CPU load to stress-test your processor(s). On Microsoft Windows, you can even use the on-board calculator.exe, enter a large number like 999999999, and press n! several times to make your CPU(s) work overtime. But what’s in a solution if you ...
stackexchange_codegolf
Background It was a normal presentation that I were in as a audience, until the presenter gave a math problem about repeat taking 2 number out of a list a replacing them with average, claiming that there will be something special about it, and our math teacher, sitting at the end of classroom, exciting rushed to me, an...
stackexchange_codegolf
I know, a bit late. Challenge Your challenge is, given a date, output if it's not an Advent Sunday, or the Advent Sunday of the year. Rules The \$4^\text{th}\$ Advent is determined by the Sunday before Christmas day (the \$25^\text{th}\$ of December). The \$3^\text{rd}\$ Advent is the Sunday before the \$4^\text{th}\$...
stackexchange_codegolf
Background Match Land is a mobile game that falls into the Match-3 genre (think Bejeweled or Candy Crush Saga series): swap two orthogonally adjacent pieces to make a 3-in-a-row or longer. However, Match Land has an additional rule that makes the game much more interesting. Once you make a valid match-3 move, the match...
stackexchange_codegolf
You are an evil wizard, doing evil wizard business, when suddenly your crystal ball alerts you of a hero on their way to defeat you. To crush their hopes and dreams, you decide to trap the hero in a maze. You could just make a big maze but where would be the fun in that? Instead, you decide you want to make the maze as...
stackexchange_codegolf
The string tut-tutut-tut-tuttut-tut can be constructed with overlapping or concatenated instances of the word tut-tut: tut-tutut-tut-tuttut-tut tut-tut tut-tut tut-tut tut-tut The string tut-tututut-tutut-tut cannot: tut-tututut-tutut-tut tut-tut^ |tut-tut | tut-tut ...
stackexchange_codegolf
I have a series of binary switches, which I can represent as a bit string. The last person who used my switches left them in some arbitrary state without cleaning up, and it bugs me. I always keep the switches in one of four possible "tidy" configurations: All 1: e.g., 111111111 All 0: e.g., 000000000 Alternating 1 an...
stackexchange_codegolf
Introduction A hypercube/tesseract is the 4 dimensional equivalent of a normal cube. It's made by taking a cube net, extending it to the 3rd dimension, then – using the 4th dimension – folding it into a hypercube. It's basically a cube, where each side is a cube. To create a hypercube, you need 16 4d vectors (a vector ...
stackexchange_codegolf
Given a string containing some parentheses and some other ASCII printable characters, like this: (abc((123))(k)) your task is to remove any sets of parentheses that are redundant. A set of parentheses is redundant if: It encloses another set of matching parentheses, like ab((123)), or It encloses the entire string, li...
stackexchange_codegolf
Write a program that outputs all possible Tic Tac Toe positions including the corresponding game outcome. Avoid duplicate output of equal positions. The program takes no input. Rules: A position output must consist of 9 characters, using X and O for the taken squares, and an arbitrary non-whitespace character for the ...
stackexchange_codegolf
Using FTP's ASCII mode to transfer binary files is a bad idea. It is likely to corrupt your data. Badly. Let's simulate this corruption! Your task is to write a program which takes a file as input and outputs the corrupted version of the file. Because how exactly your file gets corrupted is dependent on both the FTP cl...
stackexchange_codegolf
This challenge has officially ended. Further submissions will not be competitive (but are still welcome!). View the scores here In this challenge, submissions ("bots") should be Javascript functions which try to win as many races as possible. In each race, bots will have a limited amount of energy which should be use...
stackexchange_codegolf
Take the decimal number \$0.70710678\$. As a fraction, it'd be \$\frac{70710678}{100000000}\$, which simplifies to \$\frac{35355339}{50000000}\$. If you were to make the denominator \$1\$, the closest fraction is \$\frac{1}{1}\$. With \$2\$, it'd be \$\frac{1}{2}\$, and with \$3\$ it's \$\frac{2}{3}\$. Because \$0.\bar...
stackexchange_codegolf
We are probably all used to the English alphabetical order: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z When we compare words in English for the sake of alphabetization we first compare the first letter, whichever word has the later first letter comes later. If they are the same we check the second letter and...
stackexchange_codegolf
We want to go on a night hike with the youth group, but of course not everyone has their torch, even though we told them we planned to split up. What options are there for group formation if n teens have m torches with them, but each group needs at least one torch? Example: Three teens with torches (X) and two without ...
stackexchange_codegolf
Given a list of words and a grid of letters, find all the words in the grid and remove any letters which are not part of any of the words. The words could be forwards, backwards, up, down or diagonal. You may assume that no word in the list will occur in more than one place in the grid. Input will always be: a list of ...
stackexchange_codegolf
Introduction Super Mario 64 has a heavily overcomplicated RNG, ably explained here by Pannenkoek. I thought it might be interesting to implement it. Challenge Implement the RNG function, except for the two special cases. (Not part of the below description; everything below is what you should implement.) Input and outp...
stackexchange_codegolf
Your task is to create a program that will, given an input image, create an output image of the same size, where all pixels are ordered by hex value. Your program may: Sort the pixels from left to right and then down or first sort down in columns and then right. In any case, the top left pixel is the smallest, and the...
stackexchange_codegolf
This challenge is related to some of the MATL language's features, as part of the May 2018 Language of the Month event. Introduction In MATL, many two-input functions work element-wise with broadcast. This means the following: Element-wise (or vectorized): the function takes as inputs two arrays with matching sizes. ...
stackexchange_codegolf
Let's assume that $$ f(x) = \frac{Ax+B}{Cx+D} $$ Where, \$x\$ is a variable and \$A\$,\$B\$,\$C\$,\$D\$ are constants. Now we have to find out the inverse function of \$f(x)\$, mathematically \$f^{-1}(x)\$, To do this first we assume, $$ y = f(x) \\\rightarrow y=\frac{Ax+B}{Cx+D} \\\rightarrow Cxy+Dy=Ax+B \\\rightarrow...
stackexchange_codegolf
The keitai input method is a method for writing Japanese kana on a 12-key phone keypad. Similar to Western keypads, each kana is assigned to a key; when the key is pressed multiple times, it cycles between all kana assigned to that key. You will be using the following key-kana assignments, with this order of kana (base...
stackexchange_codegolf
While implementing polynomial multiplication in Itr I found the following interesting operation on strings To compute the convolution of two strings (for instance Hello and World) first combine all pairs of letters with indices that add up to the same number (ordered by the index of the first element) 0 -> "HW" 1 -> "...
stackexchange_codegolf
Challenge: In the programming language of your choice, accept an integer as input in base 10, and output it in the negadecimal notation, which is also known as base -10 Example algorithm: This is an algorithm taken from Wikipedia to convert base 10 to any negative base in VB.NET: Function toNegativeBase(Number As Inte...
stackexchange_codegolf
BackStory Given a square matrix of alphabets which contain English letters in arbitrary manner. While searching a word in it, you can go left to right horizontally, vertically downwards or diagonally towards left (both upwards and downwards). You have to find the number of matches of a given word in the matrix. For exa...
stackexchange_codegolf
Take two lists of non-negative integers, and output an ASCII-box as it's defined below. Corners and intersections are pluses: + (ASCII-code 43) Vertical lines are bars | (ASCII-code 124) Horizontal lines are minuses - (ASCII-code 45) The first input list specifies the number of minuses between each plus sign, in the ...
stackexchange_codegolf
Home improvement for the Minotaur The cretan labyrinth is quite easy to draw. Just start with a symmetric shape (here in red). Let us call all the endpoints of those lines 'nodes'. Then you begin drawing the arches (black): The first one alway begins in the top middle node and connects to the node next to it on the rig...
stackexchange_codegolf
Halley's Comet is the only comet that may appear (i.e. become visible to the naked eye on Earth) twice in a human lifetime. The orbital period of Halley's Comet is not constant: it has varied between 75 to 79 Earth years since the first definite apparition was recorded in 240 BCE. This variability is mainly driven by g...
stackexchange_codegolf