instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
This challenge is one of the two challenges which were planned for Advent of Code Golf 2021, but didn't fit into the 25-day schedule. Related to AoC2020 Day 22, Part 2. Combat is a simple two-player card game played with a deck of cards. A unique positive integer is written on each card. The game proceeds as follows: ...
stackexchange_codegolf
An alphadrome is a word in which each letter in the first half of the word "reflects" its alphabetical "opposite" in the second half of the word. Write a program or function that returns truthy if the given word is an alphadrome and falsey otherwise. For example, BEEB is a palindrome. Its first letter B "reflects" its ...
stackexchange_codegolf
Your task will be to write a Haskell function that takes a list of integers and returns a sorted version of the same list. You are to do this without the use of builtins What are builtins? To keep ourselves from having to navigate edge case hell we are going to limit answers to Haskell (sorry if Haskell is not your fa...
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
Now that we know how to Square a Number my Way, we need an inverse operation, a way to Square Root a Number my Way. To square a number my way, you simply stack it on top of itself a number of times equal to the number of digits it contains, and then take read off every number that is formed both vertically and horizon...
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 list of N lists, each containing M positive integers, and a separate list of M positive integers (target values), return a list of N scalars (integers with a value of 0 or more) that correspond to each list in the lists of lists, such that when each value in a list is multiplied by it's scalar, and the values a...
stackexchange_codegolf
Damn, that's a lot of carrots. The Inspiration The Task You must create a program, that, in as many languages as possible, replaces every instance of ^ with a markdown formatted link (meaning that if I was to post it in an answer, it would automatically read it as an image and place the image instead of the words) ...
stackexchange_codegolf
In this challenge, your task is to decipher a string. Luckily, the algorithm is pretty simple: reading from left to right, each encountered digit N (0 to 9) must be replaced with the character which is N+1 positions before it. Example The input string "Prog2am0in6" would be decoded this way: Hence, the expected output...
stackexchange_codegolf
King of the Torus! Your job is to conquer the torus, but wait, there are multiple other players banded together in teams facing you! You will need to use your wit's to conquer the torus. There are three teams: red, blue and green. Teams are self-assigned arbitrarily. If the teams are even you may join the team of your ...
stackexchange_codegolf
Description Your task is to implement a simple UNIX command parser and file system. Your program will have to implement a file system that can be modified via commands. The starting directory of your file system is an empty root directory /, with no subdirectories or files. Your program must be capable of handling the ...
stackexchange_codegolf
Challenge Given a fraction with a surd (an irrational number) as the denominator, output the rationalised fraction. Rationalising the Denominator To rationalise the denominator, what you have to do is take the fraction and make one which is equal which does not have an irrational number in the denominator. Generally, t...
stackexchange_codegolf
Given two contiguous shapes of the same area, determine the optimal way to divide the first shape into a minimum number of contiguous segments such that they can be rearranged to form the second shape. In other words, find the minimum number of segments required that can form both of the shapes. "Contiguous" means that...
stackexchange_codegolf
Is there a better way to calculate the number of leap years between two given years? I want to make my code shorter (in Python). Do you have any suggestions? Here is my solution: i=int r=raw_input t=i(r()) while t: b,d=map(i,r().split()) c=0 for y in range(b,d+1): if y%400==0 or y%4==0 and y%100:c+=1 print c t-=...
stackexchange_codegolf
In this challenge, users will take turns completeing three fairly simple coding tasks in programming languages that are allowed to be progressively older. The first answer must use a programming language that was made in the year 2015. Once there is at least one answer from a 2015 language, answers may use programming ...
stackexchange_codegolf
Task Provide two programs/functions A and B (not necessarily in the same language) with the following properties: Either program, when given its own source code as input, produces an accepting output. Either program, when given the other program's source code as input, produces a rejecting output. It doesn't matter w...
stackexchange_codegolf
A counterstring is some sort of self-describing test data that is used in software testing. Not sure it was actually invented by James Bach, but I know it from there. The idea is as follows: the test data contains many asterisk (*). The number in front of the asterisk tells you how long the test data is at that point. ...
stackexchange_codegolf
This is my first codegolf question, so I apologize in advance if it's not appropriate, and I welcome any feedback. I have a file with this format: a | rest of first line b | rest of second line b | rest of third line c | rest of fourth line d | rest of fifth line d | rest of sixth line The actual contents vary, as do...
stackexchange_codegolf
Recently there have been a couple of ASCII pet snake challenges (e.g. here) 0 0 0 0 0 000 00 0 00 000 0 0 000 0 0 0 00 0 000 This challenge is to take a randomly generated horizontal pet snake (height of five line...
stackexchange_codegolf
A Diagonal Sudoku board is a special case of Latin squares. It has the following properties: The board is a 9-by-9 matrix Each row contains the numbers 1-9 Each column contains the numbers 1-9 Each 3-by-3 sub-region contains the numbers 1-9 Both diagonals contains the numbers 1-9 Challenge: Create a program or functi...
stackexchange_codegolf
Write a function or program that determines the cost of a given string, where the cost of each character equals the number of how many times the character has occurred up to this point in the string, and the cost of the string is the sum of its characters' costs. Example For an input of abaacab, the cost is computed...
stackexchange_codegolf
CGCC hasn't always had MathJax. Back in the dark ages, it would have been necessary to write \$x^2\$ as x² (the horror!). In this challenge, you will be given some math which may include superscripts, and you should convert it to MathJax. Input: Input will consist of one or more letters a to z, some with superscripts. ...
stackexchange_codegolf
Draw a simple ASCII art image containing a straight line. It's similar to this and this but with different specifications. Input You can modify this input format to suit your code. integer width integer height integer x0 integer y0 integer x1 integer y1 Output A filled ASCII art image of the specified width and heigh...
stackexchange_codegolf
Cops post A riffle shuffle is a way of shuffling cards where the deck is split into 2 roughly equal sections and the sections are riffled into each other in small groups. This is how to riffle shuffle a string: Split the string into equal sections. Reverse the string, and starting from the start of each string. Put ru...
stackexchange_codegolf
Write a program or function that alters the file at a user-specified filename via replacing all instances of UNIX line endings with Windows line endings and vice versa. Clarifications: For the purposes of this problem, a UNIX line ending consists of the octet 0A in hexadecimal, except when it is immediately preceded b...
stackexchange_codegolf
The other day, our team went to an escape room. One of the puzzles involved a board of six mechanical switches where you had to find the correct combination of on and off in order to unlock a box, somewhat like this: -v-v-v- -v-v-v- Being developers, we decided it would be more efficient to try every single one of 2^6...
stackexchange_codegolf
Some numbers, such as \$14241\$, are palindromes in base 10: if you write the digits in reverse order, you get the same number. Some numbers are the sum of 2 palindromes; for example, \$110=88+22\$, or \$2380=939+1441\$. For other numbers, 2 palindromes are not enough; for example, 21 cannot be written as the sum of 2 ...
stackexchange_codegolf
Note: this challenge has been posted on the sandbox. Introduction This challenge is inspired by 2009 Putnam B1, a problem in an undergraduate mathematics competition. The problem is as follows: Show that every positive rational number can be written as a quotient of products of factorials of (not necessarily distinct...
stackexchange_codegolf
Challenge Your task is to generate a string using this sequence: 1,1,2,1,1,2,3,2,1,1,3,2,4,2,3,1,.... Which is more understandable in this format: 1 1 2 1 1 2 3 2 1 1 3 2 4 2 3 1 1 4 3 2 5 2 3 4 1 The pattern increases the number of Digits in the string by two for each increment in the Value of N For each integer val...
stackexchange_codegolf
Mahjong is a tabletop game played using tiles. It features three "number" suits (pins, sous, mans, represented as p, s and m) from 1 to 9, and one "honor" suit z of seven distinct tiles. Note that contrary to western card games, tiles are not unique. To complete a hand and win, the 13 tiles in your hand are combined w...
stackexchange_codegolf
2fuck is a simple 2D variation on brainfuck. Like traditional brainfuck, there is an 1D memory tape that extends 30000 bytes to the right from its beginning, consisting of values between 0 and 255. Arithmetic should wrap around, adding 1 to 255 sets the cell to 0, and moving right from memory cell 29999 should move the...
stackexchange_codegolf
Input: An integer N which represents the polygon's vertices and a list of their x and y coordinates. Expected output: The smallest difference possible between the area of the(not necessarily convex) polygon and the triangle containing it. The triangle also has to share at least 2 vertices with the polygon. If there is ...
stackexchange_codegolf
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. Output how many letters would be used if all the numbers from 1 to 1000 (one thousand) inclusive were written out in words. NOTE: Do not count spaces or hyphens. For example, 342 (th...
stackexchange_codegolf
Challenge Create a function takes in two 2-dimensional arrays of characters (or strings if the programming language does not have characters as a datatype) as inputs: a and b. If your language does not support these inputs, you may use any other standard one-byte variable. Your task is to determine if b contains a. If ...
stackexchange_codegolf
This is thematically similar to Generate keyboard shortcuts for a menu, but its actually a pretty different challenge. Let's take PHPStorm's menu as an example: New Project New Open Directory Open Open URL New Project from Existing Files Save As Open Recent Close Project Rename Project We need to assign a single-lette...
stackexchange_codegolf
Figuring out whether a given number is prime, while not very complicated, is kind of hard. But making a guess doesn't need to be. Seeing whether a number is a multiple of 2 or 5 is easy - you can just look at the last digit. Multiples of 3 isn't much harder, just add up the digits and see if you end up with a multiple ...
stackexchange_codegolf
Background You have again x4 been given the task of calculating the number of landmines in a field. But this time, the field is not a number field... it's a field of letters. Our landmine letter operator is sick and requires you to cover for them. They left you the following note: Things work a little differently with...
stackexchange_codegolf
Your task, should you choose to accept it, is to take two input values \$a\$ and \$b\$, where \$a\$ and \$b\$ are in the set \$\{T, U, F\}\$, and compute and output their logical conjunction in a three-valued logic system. A three valued logical conjunction is this transformation: a b output U U U U F F F ...
stackexchange_codegolf
In this task, you will write a program/function that takes a Normalized Malbolge program and outputs the resulting Malbolge program. (This is a secret tool that all Malbolge programmers are using!) Input A data structure that (somehow) represents a Normalized Malbolge program. Output A data structure that represents th...
stackexchange_codegolf
This is a cross-post of a problem I posted to anarchy golf: http://golf.shinh.org/p.rb?tails Given two integers \$ n \$ and \$ k \$ \$ (0 \le k \le n) \$, count the number of combinations of \$ n \$ coin tosses with at least \$ k \$ tails in a row. For example, if \$ n = 3 \$ and \$ k = 2 \$, the answer is \$ 3 \$: HHH...
stackexchange_codegolf
Challenge Taken from my university code challenge contest This is actually Day 0 but yesterdays' challenge was too easy and can be a dupe of another question here. Tetris is a video game that became popular in the 80s. It consists of placing a series of pieces with different shapes that fall on a board, so that they f...
stackexchange_codegolf
Read this if you're confused. Challenge: The goal of this code-golf is based around the number 8675309... Your goal is to print out every prime number from 2 to 8675309, starting with the number 2 and then skipping 8 prime numbers, then skipping 6, then skipping 7, etc. In essence, skip a number of primes determined by...
stackexchange_codegolf
The Challenge Given a n x n matrix of integers with n >= 2 1 2 3 4 and a list of integers with exactly 2nelements [1,2,-3,-1] output the rotated matrix. This matrix is contructed in the following way: Take the first integer in the list and rotate the first row to the right by this value. Take the next integer and ...
stackexchange_codegolf
On CodingGame, there is a Puzzle that ask to write words with ascii art. I solve the puzzle then tried to golf it. What improvement can I do on it? INPUT >>> 20 >>> 11 >>> MANHATTAN >>> .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------...
stackexchange_codegolf
A sculptor is tasked to creating icicle sculptures for the new museum in Greenland. He has been given specifications by his boss, which consists of two numbers: [s, m] or size and melt. Size must be an odd number. He was given some photos of real icicles: vvvvv [5, 0] vvv v vvvvvvv [7, 0] vvvvv vvv v vvv...
stackexchange_codegolf
This is a different type of compression challenge. In a normal kolmogorov-complexity challenge, you are required to recreate a list exactly. Here, you are allowed to round the values in any way you wish. What's the catch? Your score is penalized based on how wrong your output is. At the bottom of this question is a...
stackexchange_codegolf
What general tips do you have for golfing in Scala 3? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Scala 3 (e.g. "remove comments" is not an answer). Please post one tip per answer. Also see Tips for golfing in Scala
stackexchange_codegolf
Hey guys, first time poster here. I went on Coderoulette recently and some guy posted this question. I looked around online but it doesn't seem to be anywhere. I figured I would post it here for anyone who is a fan of these types of problems. Enjoy! Alexa is a druid who loves Mathematics! She lives in the land of Alfa...
stackexchange_codegolf
Picolisp has a feature called "super parentheses": Brackets ('[' and ']') can be used as super parentheses. A closing bracket will match [all parentheses to and including] the innermost opening bracket, or [if there are no unmatched opening brackets] all currently open parentheses. src Taking a string containing only...
stackexchange_codegolf
Given \$x\$ distinguishable balls (say they have different colors), sample with replacement repeatedly until all the balls that have been seen, have been seen at least twice. Challenge The input is the integer value \$x \geq 2\$. The challenge is to compute the probability that you would have seen all the balls when yo...
stackexchange_codegolf
In Dungeons & Dragons 5th edition (as well as most other editions), there exists a magic item called the Deck of Many Things. It is an incredibly powerful item, as the cards all have very strong positive or negative effects. To use the deck, a character declares a number, and then draws up to that number of cards, with...
stackexchange_codegolf
As a fan of an at most moderately successful footballBE team, towards the end of the season I often wonder whether my favourite team still has any theoretical chance left of becoming champion. Your task in this challenge is to answer that question for me. Input You will recieve three inputs: the current table, the lis...
stackexchange_codegolf
This is a fairly simple challenge. Given a lower-case word, you must "interpolate" between letters. Here's some examples to hopefully clarify this: Input: test Output: tsrqponmlkjihefghijklmnopqrst Between letters you must add, in alphabetical order, the letters between those two letters. So if you have ad, you must ou...
stackexchange_codegolf
You just invited a liberal arts major to your house and you're telling him/her "You know, I am a great programmer and I can do x and y and z..." S/he quickly gets bored and asks you: "If you really are a great programmer, can you make a programme to let me draw, I just need to draw lines on the screen by using the ...
stackexchange_codegolf
The recent volume of MAA's Mathematics Magazine had an article "Connecting the Dots: Maximal Polygons on a Square Grid" by Sam Chow, Ayla Gafni, and Paul Gafni about making (very convex) \$n^2\$-gons where each vertex is a different point of the \$n \times n\$ grid. One is not allowed to have two consecutive segments ...
stackexchange_codegolf
You are probably familiar with the Cartesian product. It takes two lists and creates a list of all pairs that can be made from an element of the first and an element from the second: \$ \left[1,2\right] \times \left[3,4\right] = \left[(1,3),(1,4),(2,3),(2,4)\right] \$ Here the order of the result is such that the pair...
stackexchange_codegolf
The wizard is determined to pose the most challenging challenge yet for which he believes the previous solution techniques will not work. He decides to go multidimensional. If there is a number line with \$x = 10\$ then your task is to prove this. If you do so you win. In this situation, for your code to be correct, ...
stackexchange_codegolf
Chebyshev Polynomials are a family of orthogonal polynomials that pop up in all kinds of places in math, and they have a lot of quite interesting properties. One characterization of them is that they are the unique polynomials that satisfy \$T_n(\cos(x)) = \cos(nx)\$. Challenge Given an nonnegative integer \$n\$, you s...
stackexchange_codegolf
In this task you are given an odd number of white balls and the same number of black balls. The task is to count all the ways of putting the balls into bins so that in each bin there is an odd number of each color. For example, say we have 3 white balls. The different ways are: (wwwbbb) (wb)(wb)(wb) for the two differ...
stackexchange_codegolf
In particular, use each of these symbols at least once in your source code: ! " # $ % & ' () * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ Symbols inside comments, string literals, regexps (or any other kinds of literals etc.) don't count (but their delimiters such as /**/ or "" do count). The program should not perf...
stackexchange_codegolf
Randomly inspired by Numbers Increase While Letters Decrease Given a list of mixed letters and integers (e.g., ['a', 2, 3, 'b']) increase the letters by one position in the alphabet (wrapping at z to a) and decrease the numbers by 1. For the above example, the output should be ['b', 1, 2, 'c']. The input can be a mixe...
stackexchange_codegolf
Given an integer \$x_1\$ and some black box function \$f: ℤ → ℤ\$ find a fixed point of \$f\$ in the sequence defined by \$x_{k+1} := f(x_k)\$. Details A value \$x\$ is said to be a fixed point of \$f\$ if \$x = f(x)\$. For instance if \$f(x) = \text{round}(\frac{x}{\pi})\$ and we have a starting point \$x_1 = 10\$ t...
stackexchange_codegolf
Note: There is not been a vanilla parity test challenge yet (There is a C/C++ one but that disallows the ability to use languages other than C/C++, and other non-vanilla ones are mostly closed too), So I am posting one. Given a positive integer, output its parity (i.e. if the number is odd or even) in truthy/falsy va...
stackexchange_codegolf
On Math Stack Exchange, I asked a question about the smallest region that can contain all free n-ominos. I'd like to add this sequence to the On-Line Encyclopedia of Integer Sequences once I have more terms. Example A nine-cell region is the smallest subset of the plane that can contain all twelve free 5-ominoes, as i...
stackexchange_codegolf
It is common to start countdowns 100 days prior to an event, probably because of our base 10 system. Examples of this can be found everywhere: 100 days until your birthday 100 days until the wedding 100 days until the election 100 days until our graduation 100 days until her due date 100 days until football season 100...
stackexchange_codegolf
Problem Description We all love a Twix (because it is the best candy), but this is the kids' first Halloween --- we gotta grab at least one of each type of candy for them. Each Halloween all the residents of Numberline avenue send out an email saying what types of candy they'll be giving away this year. Oh! And we live...
stackexchange_codegolf
Introduction to Numerical Mathematics This is the "Hello, World!" of PDEs (Partial Differential Equations). The Laplace or Diffusion Equation appears often in Physics, for example Heat Equation, Deforming, Fluid Dynamics, etc... As real life is 3D but we want to say "Hello, World!" and not sing "99 bottles of beer,..."...
stackexchange_codegolf
Write the shortest program that prints the sound my alarm clock makes, and stops after an inputted number of beeps. For reference, here is the sound my alarm makes: beep beep beep beep beep beepbeep beepbeep beepbeep beepbeep beepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeep beepbeepbeepbeep bee...
stackexchange_codegolf
If you haven't played the game Baba is You, I think you really should. Whether you’ve played it or not, have a go at implementing it as a code golf. The idea behind this challenge is to have a bit more complicated, non-standard task with a bit longer answers. Game rules Alas, the challenge is not to implement the entir...
stackexchange_codegolf
In mathematics, tetration is the next hyper operator after exponentiation, and is defined as iterated exponentiation. Addition (a succeeded n times) Multiplication (a added to itself, n times) Exponentiation (a multiplied by itself, n times) Tetration (a exponentiated by itself, n times) The inverse relations of te...
stackexchange_codegolf
Task For a given base \$n \ge 3\$, find the smallest positive integer \$m\$, when written in base \$n\$ and rotated right once, equals \$2m\$. The base-\$n\$ representation of \$m\$ cannot have leading zeroes. The corresponding OEIS sequence is A087502, and its base-\$n\$ representation is A158877 (this one stops at \$...
stackexchange_codegolf
The "problem" Define a function log (or other 3 letter name) which when called will log/print/write (whatever is the default for the language in question) both the instruction (as source) and the first argument. In other words: i=777 j=333 log(i) //outputs: "log(i) 777" log(i+j+1) //outputs: "log(i+j+1) 1111" For all ...
stackexchange_codegolf
Task Any one of these two: Determine if a given position (an ordered non-empty collection of integers in the range ‒8 to 8, or ‒7 to 7 if you want) is a valid Dimensional Chess position. List all the valid positions in any order. Make sure to describe your input (if not listing all) and output formats. The 2368 vali...
stackexchange_codegolf
Getting the average of a list (e.g [2,6,7]) Get the length of the list: [2,6,7] -> 3 Sum the numbers in the list: 2 + 6 + 7 = 15. Divide the sum by their count: 15 / 3 = 5. You should compare the averages of two lists of positive integers N and M, by returning a value if N has a higher average, another value if M ha...
stackexchange_codegolf
This is a Cops and Robbers challenge. This is the cop's thread. The robber's thread is here. As a cop, you must pick any sequence from the OEIS, and write a program p that prints the first integer from that sequence. You must also find some string s. If you insert s somewhere into p, this program must print the second ...
stackexchange_codegolf
Write two functions/programs which take an ASCII code of character (8-bit unsigned integer) and one of them converts char to uppercase and other to lowercase. That is, they must be equivalent to following functions: unsigned char toUpper(unsigned char c){ if (c >= 97 && c <= 122) return c - 32; return c; } unsi...
stackexchange_codegolf
Where am I now? Given a string d, containing only the letters NSWE, determine the coordinates I've traveled (from left to right, consuming greedily) and the final coordinate where I reside. The rules for reading coordinates from left-to-right: If the next character is N or S: If the character after the N or S is anot...
stackexchange_codegolf
Task Your task is simple. Write a program or function which takes three positive integer arguments \$n\$, \$k\$, and \$b\$ in any order, such that \$2 ≤ b ≤ 36\$, and returns or outputs the nth (1-indexed) base-\$b\$ digit after the decimal point of the rational number (\$b^k-1)^{-2}\$. The output must be correct for \...
stackexchange_codegolf
Inspired by a challenge from the OUCC 2022 Seniors competition. Background Two teams are playing "capture the flag". They take turns invading each other's base and capturing their opposing team's flag in the shortest amount of time. The attacking players each have one soft ball they can throw at the defenders. Teams ge...
stackexchange_codegolf
Background I saw this very interesting Venn Diagram on wikipedia: https://simple.wikipedia.org/wiki/Alphabet#/media/File:Venn_diagram_gr_la_ru.svg It shows the letters (physical shapes) in different alphabets that are common between Russian, Greek and Latin alphabets. The Challenge Given an input string of characters f...
stackexchange_codegolf
My kids have an alphabet mat to play with, something like this: After months with the tiles of the mat randomly placed, I got tired and placed all the tiles of the mat grouped by sections according to their background colors. So, if the letters represent the background color, I got a mat like this: AABBCDDDE ABBCCCDEE...
stackexchange_codegolf
From Codidact with permission. Description APL trains are a series of functions, that get applied to an argument in this way: (f g) x = f g x here f and g are prefix functions (f g h) x = (f x) g (h x) here f and h are prefix functions, while g is an infix function (a b c d e f) x = (a (b c (d e f))) x = a (b x) c (d x...
stackexchange_codegolf
The challenge is simplistic, given an input time as a string in any one of the following formats: hh, hh:mm or hh:mm:ss with 0 ≤ hh ≤ 23, 0 ≤ mm ≤ 59 and 0 ≤ ss ≤ 59. Output what time it currently is using the following symbols: AA LABEL FOR CHARACTER CODE POINT HEXADECIMAL == ==================== ==========...
stackexchange_codegolf
I posted this challenge a while ago, which concerns how many elves Santa needs to deliver presents. Due to population increase, Santa is a little more pressed for time this year. Although in the past we operated very asynchronously, we are beginning to experiment with being more and more synchronized. So, Santa needs t...
stackexchange_codegolf
A demonic number is a positive integer whose decimal representation consists of only 6. The list of demonic numbers starts with 6, 66, 666, 6666. Given a positive integer, output the nearest demonic number. If there are two, output the bigger one. Testcases: n output 1 6 2 6 3 6 6 6 35 6 36 66 37 66 100 66...
stackexchange_codegolf
Given a compressed string \$s\$ made of printable ASCII characters (32 to 126), your task is to print or return the original text by applying this simple decompression algorithm: Start with \$k=0\$ Look for the first occurrence of the digit \$k\$ in \$s\$ and the sub-string \$s'\$ consisting of the \$2\$ characters pr...
stackexchange_codegolf
Make a program that simulates the basic logic gates. Input: An all-caps word followed by 2 1 digit binary numbers, separated by spaces, such as OR 1 0. The gates OR, AND, NOR, NAND, XOR, and XNOR are needed. Output: What the output of the entered logic gate would be given the two numbers: either 1 or 0. Examples: AND ...
stackexchange_codegolf
Your task is to make a script with the shortest byte count, that reverses a word then replaces each letter with the next letter next in the alphabet. Examples: input: hi output: ji input: hello output: pmmfi input: test output: utfu A few notes: Should the letter's value be 27 (z+1), assume it is an a. Symbols, num...
stackexchange_codegolf
Given a list of integers, such as {1, 4, 2, 8, 10}, TI-Basic's ΔList will determine the difference between every overlapping pair of items. In the given example, it would be {3, -2, 6, 2}. Task: Take a list of integers as input, in any reasonable way. All overlapping pairs {x, y} should become y - x, and the resulting ...
stackexchange_codegolf
Your task is to take an ASCII art image and output it rotated clockwise by 45 degrees and scaled by a factor of \$\sqrt 2\$. The scaling comes from using a lattice pattern which introduces space between the characters. To explain it visually, a \$3 \times 3\$ block would be processed like so: 123 456 789 becomes 1 ...
stackexchange_codegolf
This is a more difficult version of It's a find-a-movie challenge . Input Your code should take a BBFC rating and a number from 1 to 5 as input. It can do this in any way you find convenient. Output Your code should return the name of any movie which has a) that film rating and b) that number of stars in a Guardian fi...
stackexchange_codegolf
I'm currently converting a Float32Array to an Int32Array for input to a real-time audio raw PCM to MP3 recording application. new Int32Array([...new Float32Array(b)].map(f=>f<0?f*32768:f*32767) The examples in the wild I've seen convert each float individually to avoid static, gaps, glitches when the audio recording i...
stackexchange_codegolf
You are writing a screen scraper application monitoring a text-only chat window. Text is added at the bottom of the window. The application takes screenshot of the chat window. If a change has occurred since last screenshot (new_screenshot != old_screenshot), the screenshot is saved. After X time, all images are merg...
stackexchange_codegolf
Powers We define an important power as a number that can be represented as \$ x^y \$ where \$ x ≥ 2 \$ and \$ y ≥ 2 \$. Palindrome We define an important palindrome as a number that is the same written forwards and backward, and is greater than 10. Thus, the last digit must not be 0. Palindromic Power We define a Palin...
stackexchange_codegolf
To quote http://brainfuck.org/utm.b: A tag-system transforms strings over an alphabet A = {a[1], a[2], ... a[n], a[n+1]} as follows: a positive integer m is chosen, and so is a function P that maps each a[i] for 1<=i<=n to a string P(a[i]) over the alphabet A. Now: if the string being transformed has fewer than m ele...
stackexchange_codegolf
We've had lots of questions about quines, programs where the source code and output are identical. For compiled languages, there are other combinations: we've already had a question about writing a program where the executable and output are identical. But there's one combination left. The task Using a compiled languag...
stackexchange_codegolf
The challenge is to follow (draw) the path: ^n - up by n lines vn - down by n lines >n - right by n character positions <n - left by n characters positions n is an integer, greater than zero (i.e. you can't receive a command like >-2). There're no separators between the commands, the well-formed input looks like th...
stackexchange_codegolf
Let's say you have a 20-sided die. You start rolling that die and have to roll it a few dozen times before you finally roll all 20 values. You wonder, how many rolls do I need before I get a 50% chance of seeing all 20 values? And how many rolls of an n-sided die do I need to roll before I roll all n sides? After some...
stackexchange_codegolf
Introduction Write a solver for integer linear programming. Challenge Your task is write a solver for integer linear programming (ILP). In ILP, linear inequalities of a set of unknowns (all of which are integers) are given, and the goal is to find the minimum or maximum of a linear function. For example, for the inequa...
stackexchange_codegolf
Background (feel free to skip) Ordinals are the abstract representation of well-orders. A well-order of a set is a total order, which basically means that every element in the set can be compared against any other element in the set, and one of them is either smaller or larger. Also there are no cycles. The crucial dif...
stackexchange_codegolf