instruction_seed
stringlengths
34
53.1k
_source
stringclasses
1 value
Draw an ASCII-art rainbow! Input An integer between 0 and 1000, inclusive. Examples Input 0: /\ || Input 1: _ / \ | | Input 2: __ / \ | | Input 3: ___ / \ | | The first row is a space followed by n underscores. The second row is a slash followed by n spaces, and a backslash. The third row is a pipe follow...
stackexchange_codegolf
You are given three parameters: start(int), end(int) and list(of int); Make a function that returns the amount of times all the numbers between start and end are multiples of the elements in the list. example: start = 15; end = 18; list = [2, 4, 3]; 15 => 1 (is multiple of 3) 16 => 2 (is multiple of 2 and 4) 17 => 0 18...
stackexchange_codegolf
You must write a program or function that sorts a nested list. Here are the rules for sorting a nested list: Let's take this list as an example: ((5, 2), 2, 7, (2, 1, (3, 4)), 9) Each element in this list has a "priority". An element counts as a number or a sublist. First, get the priority of each element at the same ...
stackexchange_codegolf
We say two positive integers are anagrams of each other if the digits in one of them (in decimal representation) can be rearranged to form the other. Leading zeros don't count. For example, 110020222 is an anagram of 212102020, but not of 221100011; neither is 22002211 even though it can be written as 022002211. Intere...
stackexchange_codegolf
Challenge Here's a simple one. Write a function or program when given a number in base 10 as input, it will return or print that number's value in Hexadecimal. Examples 15 -> F 1000 -> 3E8 256 -> 100 Rules No built-in Hexadecimal functions whatsoever Letters may be lowercase or uppercase You will only need to worry a...
stackexchange_codegolf
I'm not sure if this is the right place to ask, but I found this similar question so I'll go ahead. I'm very new to code golfing, so keep your smothered laughs and throw-up emoji's to yourselves please ;). Anyway, someone recently posted a challenge (that was shortly deleted) to draw a 16x16 pixel image of the Old Man ...
stackexchange_codegolf
The title says it all; Given a number in the binary (base-2) number system, output the same number expressed in unary (base-1). You should take the binary number as a string (optionally with a separator), list, or equivalent structure of digits, using any number or digit you like for the digits. The unary output can us...
stackexchange_codegolf
As a child, my friend had a magic 8 ball that we would ask questions to and see what the fate of that question was. Challenge Your challenge is to write a program (or function) that when run (or called), outputs (or returns) a random answer from the possible answers below. (Random being: each output should have a nonze...
stackexchange_codegolf
A flowchart algorithm is a type of pseudocode designed for human readability and makes it easy to see the program flow. For this program, you need to output your own program as a flowchart. You may not read your own source code and the output must be a PNG of any size. The flowchat must be a step by step representation...
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
Challenge We all know about normal Christmas trees - but how about an upside-down Christmas tree! This is a fairly easy, Christmas themed challenge. The objective of this challenge is to make me an ASCII upside-down Christmas tree. Here are the rules for this challenge: Accept an odd, positive integer. You can assume ...
stackexchange_codegolf
Key links: Troll question Chat room Game Controller Interface Dwarf league table <script src="https://ajfaraday.github.io/Thud/dist/data/tables.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><table> <thead> <tr> <th>Client</th> <th>Wins</th><th>Loses</th> <th>S...
stackexchange_codegolf
As of 27/12/20, the challenge is over as no new answers were posted on the 26th. With an astounding 55 points (and 21 answers), the winner is pppery! A quick shout out to the top 5 scorers as well: 1st. pppery with 55 points across 21 answers 2nd. tsh with 50 points across 21 answers 3rd. SunnyMoon with 21 points acr...
stackexchange_codegolf
You're playing TF2, and you want to make a bot that will just put voice commands into the chat box. Typically, to "call" a voice command, one would press a key (Z, X, or C) and a number (1-8) to create an audio dialogue. Here are the text equivalents of the audios displayed when pressing these keys: Voice Menu 1 Defaul...
stackexchange_codegolf
There have been a couple of challenges involving doubling source code: here and here. The task we have here is a bit harder, but should be doable in almost every language. In this challenge, you will take in an arbitrary positive integer. Your program must output that integer doubled. When your source code is doubled, ...
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 A bound m <= 4294967295. Output Consider values sampled uniformly at random from integers in the range 0 to m, inclusive. Your output should be the expected (average) number of trailing zeros in the binary representation of the sampled value. Your answer should be exact, for example given as a fraction. Example ...
stackexchange_codegolf
Given an ASCII art with simple closed paths using | and - (pipes and dashes), output a random point inside the boundary. Eg. given: ---- ---- | |- --- => |12|- --- | | | | |345| |6| ----- --- ----- --- Any point 1-6 should have an equal probability of being printed. Specs T...
stackexchange_codegolf
Given one line that consists of only letters, process as following: You maintain a string that's empty at the beginning. If the next input character is in the string, remove it from the string. If the next input character isn't in the string, append it to the string. Output the final state of the string. You can saf...
stackexchange_codegolf
Your task is to create a program or function which randomly errors. Specifically, there must be a nonzero probability of erroring, but also a nonzero probability of running without error. An error is anything that causes a program to terminate abnormally, such as dividing by zero or using an uninitialized variable. Thi...
stackexchange_codegolf
Your challenge, should you choose to accept it, is, given an integer K >= 1, find non-negative integers A and B such that at least one of the two conditions following hold: K = 2^A + 2^B K = 2^A - 2^B If there does not exist such A and B, your program may behave in any fashion. (To clarify, A and B can be equal.) Te...
stackexchange_codegolf
(Inspired by this question) Objective Your task is to write a program or function to print an ASCII version of the Stack Overflow logo to STDOUT \|/ (-) (-) (-) (-) Your program should take two inputs, referred to here as H and N. The height of the stack "container" (the parentheses) is determined by H. The number of...
stackexchange_codegolf
Your challenge is to create the longest run of characters with incrementing Unicode codepoints in a pristine program as you can. To keep things simple, I'll abridge the definition for this challenge to be "any program which produces no errors but will error if any one character is removed". Let's define a codepoint run...
stackexchange_codegolf
Chinese Hearts, also known as Gong Zhu (拱猪, Chase the Pig), is a variance of the Hearts game. It is a 4 player card game with the aim to earn the highest amount of points. You may read more about it on Wikipedia. This time, we want implement a program (full or function) to calculate ones score. Scoring The player who p...
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
Related, related Introduction The ruler sequence is the sequence of the largest possible numbers \$a_n\$ such that \$2^{a_n}\mid n\$. It is so-called because its pin plot looks similar to a ruler's markings: However, with a slight modification, we can also get a similar sequence. This sequence is \$\{a_1,a_2,a_3,…\}\$...
stackexchange_codegolf
Task Given a string s, output a truthy value if the ASCII code of each letter is divisible by the length of s, and a falsey otherwise. Input/Output Input is a nonempty string containing only ASCII [32-126]. Output is a standard truthy/falsey value. Note that you can switch the values, for example returning 0/False if d...
stackexchange_codegolf
I use "suffix" loosely here to mean "any sub-string that follows the prefix". "Prefix" here means the START of a word, where a word's start is defined as either after a space or from the first character of the input text (for the first word). A "prefix" in the middle of a word is ignored. E.g. if your input prefix is "...
stackexchange_codegolf
A simple graph is toroidal if it can be drawn on the surface of a torus without any edges intersecting. Your task is to take a simple undirected graph via any reasonable method (adjacency matrix, edge vertex sets, etc.) and decide whether or not it is a toroidal graph. You should output one of two distinct values for...
stackexchange_codegolf
An "Egyptian fraction" is a list of distinct fractions with a numerator of \$1\$. For example: \$ \frac 1 1+ \frac 1 2 + \frac 1 3 + \frac 1 6 \$ The "size" of an Egyptian fraction is just the number of terms involved. Your task is to take a positive integer \$n\$ and output the smallest Egyptian fraction that sums t...
stackexchange_codegolf
Background Related: a golflang theory I posted in TNB a while ago At-most-\$n\$-ary trees are rooted trees where each internal node has between 1 and \$n\$ children (inclusive). Two trees are considered identical only if the shapes exactly match without re-ordering each node's children. In other words, the left-to-righ...
stackexchange_codegolf
For this challenge a "binary tree" is a rooted tree where each node has 0 children (leaf) or 2. The children of a node are unordered, meaning that while you might draw the tree with left and right children there isn't a distinction between them and mirroring the tree or a sub-tree does not produce a new tree. In this...
stackexchange_codegolf
Given an integer greater than 1, output the number of ways it can be expressed as the sum of one or more consecutive primes. Order of summands doesn't matter. A sum can consist of a single number (so the output for any prime will be at least 1.) This is code-golf. Standard rules apply. See this OEIS wiki for related i...
stackexchange_codegolf
Challenge: Given an expressions made of additions and multiplications, output an expression that is a sum of products. The output must be equivalent to the input modulo the law of distribution. For example, \$1 + ((2 + 5\times 6) \times(3+4))\$ becomes \$1 + 2 \times 3 + 2 \times 4 + 5\times6\times3 + 5 \times 6 \times...
stackexchange_codegolf
If you are not familiar with Braid-Theory I recommend that you read this first. This question assumes that you are at least familiar with the concepts at hand and assumes you are well familiar with group-theory Let us define \$\sigma_n\$ to be the braid in which the \$n\$th strand (One indexed) from the top crosses ...
stackexchange_codegolf
Task The letters spell out actual words, but if you replace each letter with a digit from 0–9, it also “spells” an arithmetic equation. The trick is to figure out which letter maps to each digit. All the occurrences of each letter must map to the same digit, no digit can be repeated, and no “word” can start with the di...
stackexchange_codegolf
Recently I read the novel "The Solitude of Prime Numbers" where the main characters are somewhat compared to twin prime numbers ("always together, but never touching"). A twin prime is a prime number that is either \$\require{cancel}2\$ less or \$2\$ more than another prime number —for example, the twin prime pair \$(...
stackexchange_codegolf
I have the code below working. But there must be a better way. file <- "http://s3.amazonaws.com/assets.datacamp.com/production/course_1127/datasets/tmp_file.csv" x <- read.csv(file = file) ts <- xts(x = x, order.by = as.Date(rownames(x), "%m/%d/%Y")) cd=coredata(ts) for (j in 1:length(names(ts))) cd[,j]<-cd[,j]/cd[1,...
stackexchange_codegolf
Challenge Given an integer, n, as input where 36 >= n >= 2, output how many Lynch-Bell numbers there are in base n. The output must be in base 10. Lynch-Bell Numbers A number is a Lynch-Bell numbers if: All of its digits are unique (no repetition of digits) The number is divisible by each of its digits It doesn't cont...
stackexchange_codegolf
This code-challenge is based on OEIS sequence A261865. \$A261865(n)\$ is the least integer \$k\$ such that some multiple of \$\sqrt{k}\$ is in the interval \$(n,n+1)\$. The goal of this challenge is to write a program that can find a value of \$n\$ that makes \$A261865(n)\$ as large as you can. A brute-force program ...
stackexchange_codegolf
In this challenge, players need to tamper with a time bomb as late as possible without getting blasted in the face. Mechanics Let N be the number of bots plus one. Each round, each bot receives the following arguments: numbers played by all bots last round in ascending order. number of points it received last round. N...
stackexchange_codegolf
Background BitCycle is a two-dimensional Turing-complete programming language involves moving bits around a playfield. Because I am too lazy to write BitCycle programs myself, you will be writing a program which outputs BitCycle programs for me! Unfortunately, the storage space on my computer is only about a bit, so yo...
stackexchange_codegolf
Part of Advent of Code Golf 2021 event. See the linked meta post for details. Related to AoC2017 Day 3, Part 2. You come across an experimental new kind of memory stored on an infinite two-dimensional grid. Each square on the grid is allocated in a spiral pattern starting at a location marked 1 and then counting up wh...
stackexchange_codegolf
Pure data is a graphical programming language designed for audio processing. This makes it unsuitable for most general programming but especially unsuitable for code-golf. It would then be nice to have a tips question so that people can get a first foot up in this language. What tips are there for golfing in Pure Data...
stackexchange_codegolf
The cosine similarity of two vectors \$A\$ and \$B\$ is defined using their dot product and magnitude as: \$\frac{A\cdot B}{\|A\|\|B\|}\$ Or in other terms \$\frac{\sum_{i=1}^nA_iB_i}{\sqrt{\sum_{i=1}^nA_i^2}\sqrt{\sum_{i=1}^nB_i^2}}\$ Challenge Given two nonempty, nonzero vectors containing only integers (can be taken...
stackexchange_codegolf
This originally came from Give the best Chaitin incompleteness bound, but I realized that there was a fragment of this problem which still potentially gives a good coding challenge. First Order Logic With Equality First, I will need to fix an encoding of first order formulas ('For all x there exists y such that ...'). ...
stackexchange_codegolf
Your program should take an array as input. The array: Will always be 1 dimensional Will only contain integers Can be empty The program should reverse the array, and then add up the elements to the original for example: Input: [1, 2, 3] Original: [1, 2, 3] Reversed: [3, 2, 1] [1, 2, 3] + + + [3, 2, 1] [1+3, 2+2,...
stackexchange_codegolf
Create a program that interprets the programming language Bucket. Bucket works on two buckets: the first can hold A and the second can hold B units of liquid. The things you can do with these buckets are: f: fill bucket A F: fill bucket B e: empty bucket A E: empty bucket B p: pour units of liquid from A to B until one...
stackexchange_codegolf
I'm making a page selector for my super cool terminal-based blog program. In order for it to fit correctly into the design, it has to have some constraints. The page selector can only display a certain number of numbers at a time due to the constraints of the UI system. If there are more characters then can fit, they m...
stackexchange_codegolf
So I have the situation where I have one boolean value a and, if that one is true and b<c I want it to end up as true, if a is false and b>c I want it to resolve as true as well. If b=c I want it to be always false, no matter the value b and c are both numbers. My best approach so far is a?b<c:b>c or maybe b^c^a^b<c. I...
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
Background You know how in text editors and just text fields in general, there's always that blinking bar where you type? Yeah, simulate typing there. You'll be given 3 inputs: The current text field, the position of the cursor, and the input sequence. Here's an example: Hello, World! 5 [U];[U];[B];[B];[B];[B];[B];[U];...
stackexchange_codegolf
A quote from MO.SE answer: Although it is well known that Conway was able to quickly calculate the day of the week of any given date, it is less well known that one part of the algorithm is easy to remember and useful in practice: In any given year, the following dates all fall on the same day of the week: 4/4, 6/6, 8...
stackexchange_codegolf
Write a program that takes in a string containing only spaces, newlines, and angle brackets: <, > (chevrons). Output a string of spaces, newlines, and slashes: /, \ (soliduses) whose shapes correspond to the input, but rotated a quarter turn clockwise, with a column of spaces inserted between each row of the original i...
stackexchange_codegolf
Input: A three digit number from stdin or as an argument not all digits are the same may start with one or two zero's Process Order the input-digits ascending and descending to form two new numbers. Subtract the smallest from the largest. Use the difference as new input. NB: This process needs 3 digits, so 10 has to...
stackexchange_codegolf
A "qruine" if you will :) Design a QR code that legibly spells with its pixels (or the space between them) the text that it scans to. For example, this QR code scans to the letter A, and also spells out A in white: There are 4 categories, one for each mode of QR code: numeric, alphanumeric, byte, and kanji. Please sta...
stackexchange_codegolf
This king-of-the-hill game is a strategy game in which you must throw around a water balloon and avoid getting splashed by water. The goal is to obtain the most points. You will be given a map of the field and the location of the water balloon. You can either return that you want to hit the water balloon (if you are cl...
stackexchange_codegolf
About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You can find the leaderboard along with some more information about the series in the first post. Although I have a bunch of i...
stackexchange_codegolf
You have been hired by the American embassy in the UK to act as a translator. Being a programmer, you decide to write a program to do a bit of the work for you. You've found out that often just doing the following things can satisfy Word's spellcheck, which has been set to "English (United States)", somewhat, so you do...
stackexchange_codegolf
Synopsis Your goal is to implement the (asymptotically) fastest growing function within bounded code on a fictional CPU utilizing a quite limited, yet (probably) turing-complete instruction set. Environment The CPU utilizes unbounded RAM as well as two registers, the accumulator A and the program counter C, with words ...
stackexchange_codegolf
The goal of this challenge is to extend the On-Line Encyclopedia of Integer Sequences (OEIS) sequence A038375. Maximal number of spanning paths in tournament on n nodes. A tournament on \$n\$ vertices is a directed graph where for each pair of vertices \$(v_i, v_j)\$ there is either a directed edge \$v_i \rightarrow ...
stackexchange_codegolf
Your task is to write a function that takes an even-digit integer and compares the 2 halves of the integer. If the sum of the digits in the first half is greater than the sum of the digits in the second half, output a truthy value, otherwise, output falsey. For example: 12345678 1234 5678 (1+2+3+4)>(5+6+7+8) 10>26 Out...
stackexchange_codegolf
Choose any five characters your language supports. There are 5! = 5×4×3×2×1 = 120 ways these can be arranged into a 5-character string that contains each character once; 120 permutations. Choose your characters such that, when each of the 120 strings is run in your language, the 120 outputs produced will be as many uni...
stackexchange_codegolf
This is a copy cat question of Simplify ijk string applied to the other nonabelian group of order 8. See also Dihedral group composition with custom labels. Challenge Given a string made of r and s interpret it as the product of elements of the dihedral group \$D_8\$ and simplify it into one of the eight possible value...
stackexchange_codegolf
Task Given a string of English names of digits “collapsed” together, like this: zeronineoneoneeighttwoseventhreesixfourtwofive Split the string back into digits: zero nine one one eight two seven three six four two five Rules The input is always a string. It always consists of one or more lowercase English digit nam...
stackexchange_codegolf
Write a program or function that: Takes as input a list or array of 128 numbers. Sends that array to a GPU Performs a calculation on the GPU to square each element of the array and then sum them Gets the answer from the GPU, and returns or displays it So your program will simply return the sum of the squares of its i...
stackexchange_codegolf
This task is simple: Write a program or function that outputs the list of all musical notes (using English note names) from A♭ to G♯. All notes without a name consisting of a single letter (i.e. black notes on a musical keyboard) should have their name printed twice, once as the sharp of a note, once as the flat of one...
stackexchange_codegolf
Inspired by this video of Infinite Series. Introduction Pi is defined as the ratio of the circumference to the diameter of a circle. But how is a circle defined? Usually a circle is defined as the points with constant distance to the centerpoint (let us assume that the center is at (0,0)). The next question would be: H...
stackexchange_codegolf
Code Golf Measurer © 2019 Hexdumps used with xxd look something like this: 00000000: 666f 6f20 6261 7220 7370 616d 2065 6767 foo bar spam egg 00000010: 730a s. Your task is to convert a hexdump in this form in to the number of bytes used. Rules: Usual loopholes forbidden. This is ...
stackexchange_codegolf
Andrew is a chemist, interested in the acidity of solutions and in agriculture. After months of research (Google is not his friend), he came up with the following table* regarding the human-readable level of acidity in terms of the pH (potential of Hydrogen): Denomination | pH range ...
stackexchange_codegolf
Four-In-A-Row AI Tournament Today, we will be playing a Four-In-A-Row tournament. However, it is not us humans playing... instead, we must have our computers battle instead! This challenge is completely in C#. Rules Basic Game Rules If you have never played, there are simple rules. 2 players take turns putting pieces i...
stackexchange_codegolf
Given two numbers n and m, evaluate the infinite power tower: n^(n+1)^(n+2)^(n+3)^(n+4)^... mod m Keep in mind that ^ is right-associative. So 2^3^4 = 2^(3^4). Now how can you possibly assign a value to an infinite sequence of right-associative operators? Define f(n,m,i) as the power tower containing the first i ter...
stackexchange_codegolf
Context Consider square matrices with n columns and rows containing the first n^2 (i.e. n squared) positive integers, where n is odd. The elements of the matrices are arranged such that the integers 1 through n^2 are placed sequentially in a counterclockwise spiral starting at the center and initially moving to the lef...
stackexchange_codegolf
Background I was working on a StackOverflow helper program (that sends me notifications) when I noticed something rather interesting in StackOverflow's Network tab: StackOverflow uses WebSockets (not too surprising, but good to know)! For this challenge, we will be conquering StackOverflow's web socket server. This p...
stackexchange_codegolf
A few hours earlier, I got this puzzle: Suppose, you toss a coin n times, then what is the probability of getting m number of heads? ( where m belongs to the set of all prime numbers) For instance, take n = 2, then SS = { HH, HT, TH, TT } So, output is 1/4 (for HH case) Then, for n = 3, SS = { HHH, HHT, HTH, THH, HTT...
stackexchange_codegolf
Pascal's triangle is generated by starting with 1 and having each row formed from successive additions. Here, instead, we're going to form a triangle by alternating multiplication and addition. We start row 1 with just a solitary 1. Thereafter, addition is done on the odd rows, and multiplication is done on the even r...
stackexchange_codegolf
Output the infinite list of pairs of integers (a, b), where both \$ a > 1 \$ and \$ b > 1 \$, ordered by the value of \$ a^b \$. When there are multiple pairs where \$ a^b \$ is equal, they should be ordered lexicographically. For example, \$ 2^4 = 4^2 = 16 \$, but (2, 4) should come before (4, 2), because it is lexico...
stackexchange_codegolf
You will be given 3 integers as input. The inputs may or may not be different from each other. You have to output 1 if all three inputs are different from each other, and 0 if any input is repeated more than once. This is code-golf, so make your code as short as possible!
stackexchange_codegolf
I was wondering if there are any esoteric or golfing languages which specifically target text output and ASCII art? For example, 05AB1E at least started by targeting base conversions. Are there any golfing languages targeting text output and text output art? If so, do they have tip pages here, and are they in common ...
stackexchange_codegolf
Introduction In this challenge, you are given a directed graph with self-loops, and your task is to convert it to an undirected graph without self-loops. Input Your input is a directed graph with vertex set {0, 1, ..., n-1} for some natural number n ≥ 0 (or {1, 2, ..., n} if you use 1-based indexing). The graph is give...
stackexchange_codegolf
This is Hole-3 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here. Given: a number of turns (please state if no movements is 0, otherwise we'll assume it is called 1) and a list of one or more starting positions (in any form, e.g. 0 or 1 ind...
stackexchange_codegolf
Your goal in this code golf is to take two strings, language and code (if the golfed code you wrote for this is multiline, then this variable would be multiline.), and one integer, bytes. They represent the variables for a programming language, number of bytes it takes, and the code itself. After that, you are going to...
stackexchange_codegolf
In this question I will talk about programs as strings, this is strings of bytes, not characters. How your resultant program is rendered or displayed is not important to this challenge, only how it appears in memory matters. A pristine program is a program \$S\$ that when run does not error, however it will error when...
stackexchange_codegolf
The Cantor function is continuous everywhere and constant almost everywhere, but has an average slope of 1: The function can be found recursively: \$f_0(x)=x\$ \$f_{n+1}(x)=\left\{\begin{matrix}\frac{1}{2}f_n(3x)&x\in[0,\frac{1}{3})\\ \frac{1}{2}&x\in[\frac{1}{3},\frac{2}{3})\\ \frac{1}{2}+\frac{1}{2}f_n(3x-2)&x\in[\f...
stackexchange_codegolf
The challenge Write a function that returns the nth element of an array even if its out of bound. function safeGet(index, arr) { const safeIndex = ??? return arr[safeIndex] } const arr = ["a", "b", "c"]; safeGet(0, arr) // "a" safeGet(1, arr) // "b" safeGet(2, arr) // "c" safeGet(3, arr) // "a" go back to the be...
stackexchange_codegolf
A fun pair of equivalences is 1 + 5 = 2 · 3 and 1 · 5 = 2 + 3. There are many like these, another one is 1 + 1 + 8 = 1 · 2 · 5 and 1 · 1 · 8 = 1 + 2 + 5. In general a product of n positive integers equals a sum of n positive integers, and vice versa. In this challenge you must generate all such combinations of positive...
stackexchange_codegolf
Write a program or function that prints or outputs this exact text (consisting of 142 characters): ()()()()()() |\3.1415926| |:\53589793| \::\2384626| \::\433832| \::\79502| \::\8841| \::\971| \::\69| \::\3| \__\| Your program must take no input (except in languages where this is impossible...
stackexchange_codegolf
So I have the situation where I have one boolean value a and, if that one is true and b<c I want it to end up as true, if a is false and b>c I want it to resolve as true as well. If b=c I want it to be always false, no matter the value b and c are both numbers. My best approach so far is a?b<c:b>c or maybe b^c^a^b<c. I...
stackexchange_codegolf
33 is a simple esolang I created. You may have seen me use it in a few questions. You're not going to be writing a full interpreter. The interpreter you will be writing is for a simplified version of 33. This simplified 33 has two numeric registers: the accumulator and the counter. The accumulator holds all the post-ar...
stackexchange_codegolf
Your task: given a nonzero positive number i, calculate pi using the Nilakantha series unto i terms. The Nilakantha series is as follows: $$\text 3 + \frac{4}{2 \times 3 \times 4} - \frac{4}{4 \times 5\times 6}+\frac{4}{6 \times 7 \times 8} - ...$$ 3 is the first term, 4/2*3*4 is the second, -4/4*5*6 is the third, and...
stackexchange_codegolf
Suppose we have an array \$\texttt{ps}\$ of length \$n\$ with pointers pointing to some location in the array: The process of "pointer jumping" will set every pointer to the location the pointer it points to points to. For the purpose of this challenge a pointer is the (zero-based) index of an element of the array, thi...
stackexchange_codegolf
Given an input of a string, output the partial fraction in string form. The partial fraction decomposition of a rational fraction of the form \$\frac{f(x)}{g(x)}\$, where \$f\$ and \$g\$ are polynomials, is its expression as: $$\frac{f(x)}{g(x)}=p(x)+\sum_j\frac{f_j(x)}{g_j(x)}$$ In this case \$p\$ is 0, because we ass...
stackexchange_codegolf
Challenge: Take a vector / list of integers as input, and output the largest number that's adjacent to a zero. Specifications: As always, optional input and output format You may assume that there will be at least one zero, and at least one non-zero element. Test cases: 1 4 3 6 0 3 7 0 7 9 4 9 0 9 0 9 15 -2 9 -4 -6...
stackexchange_codegolf
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. Santa has a bunch of presents wrapped in cuboid boxes of various sizes. As his sled flies above a chimney, a stack of presents will be automatically dropped through it. Santa wants to carefully choose the presents so that all of them f...
stackexchange_codegolf
Challenge Given a positive integer \$n\$, count the number of \$n\times n\$ binary matrices (i.e. whose entries are \$0\$ or \$1\$) with exactly two \$1\$'s in each rows and two \$1\$'s in each column. Here are a few examples of valid matrices for \$n=4\$: 1100 1100 1100 1100 0011 01...
stackexchange_codegolf
It seems we've managed to go all this time without a plain vanilla Number-To-Binary challenge! Whilst this will inevitably be only one element in many languages, it should put a few esolangs through their paces. I truly looked for this challenge to no avail. If it already exists, comment as such and I'll delete this po...
stackexchange_codegolf
One day you awake only to find yourself caught in an array. You try to just walk out of there, taking one index at the time, but it seems there are other rules: The array is completely filled with natural numbers. If you find yourself on an index n, you go to the index array[n], except: If you find yourself on an inde...
stackexchange_codegolf
Write a function or program that takes two words as input and outputs variants of the popular English tongue-twister "How much wood would a woodchuck chuck if a woodchuck could chuck wood?". The output will use the first word four times How much wood would a woodchuck chuck if a woodchuck could chuck wood? and the se...
stackexchange_codegolf
The Task Build a function that takes a string of coins ending with an item index, and generates change as a string of coins using the least amount of coins possible. The following are the items that can be bought (0-indexed): [0.45, 0.60, 0.75, 0.95, 1.10, 1.25, 1.40, 1.50, 1.75, 2.00] The following are the coins that ...
stackexchange_codegolf
Given a string s and a non-negative number n less than the length of s, output the character at the n-th position of s. 0-indexing and 1-indexing are allowed. For 1-indexing, n will be positive and less than or equal to the length of s. s will consist of printable characters only. Any reasonable input/output is permitt...
stackexchange_codegolf