Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Posts tagged code-golf

Code golf is a winning criterion, where users seek to solve the challenge in as few bytes of source code as possible.

This tag doesn't have a detailed wiki yet.

75%
+4 −0
Challenges Calculate a person's age

Challenge Given a date with day, month and year, calculate how old a person born on that day would be today. Input can be in any reasonable format (params, array, date object). Input will never ...

0 answers  ·  posted 4y ago by Razetime‭  ·  edited 7d ago by hydroxyl-radical‭

Question code-golf date
57%
+2 −1
Challenges Show order equivalence between the rationals and the binary fractions

Write a function $f$ which takes rational numbers and gives binary fractions (rational numbers whose denominator is a power of two) which is bijective and preserves order. That means: Different...

0 answers  ·  posted 9d ago by WheatWizard‭  ·  edited 8d ago by WheatWizard‭

Question code-golf math open-ended-function
83%
+8 −0
Challenges Compute the determinant

Challenge A simple challenge: Given a two-dimensional matrix (an array of arrays) of real numbers, compute the determinant. The determinant of a matrix is a mathematical construct used in many ap...

10 answers  ·  posted 3y ago by Moshi‭  ·  last activity 13d ago by CrSb0001‭

Question code-golf math
50%
+0 −0
Challenges Digit balanced numbers

Does a number have balanced numbers of distinct digits? That is, do the number's digits appear with equal frequency? Input A positive integer N. N will have no leading zeroes. Output An ...

4 answers  ·  posted 2mo ago by trichoplax‭  ·  last activity 18d ago by Shaggy‭

Question code-golf number
50%
+0 −0
Challenges Awkward Ordinals

Write code that takes a positive integer and outputs the awkward ordinal name from the test cases. Notice that these are not the conventional ordinal names. Input A positive integer from the te...

0 answers  ·  posted 1mo ago by trichoplax‭  ·  edited 20d ago by trichoplax‭

Question code-golf number string
66%
+2 −0
Q&A Transferable golfing skills

We have many questions about how to golf in a specific programming language. These result in tips that apply only to that language or closely related languages. What advice do you have on golfing ...

0 answers  ·  posted 23d ago by trichoplax‭  ·  edited 22d ago by trichoplax‭

Question code-golf tips language-agnostic
60%
+1 −0
Q&A Rust golfing tips

What tips do you have for saving bytes in Rust? Please post one tip per answer for ease of voting and commenting.

3 answers  ·  posted 1mo ago by trichoplax‭  ·  edited 24d ago by trichoplax‭

Question code-golf tips
75%
+4 −0
Challenges Caesar shift cipher

Introduction What is the Caesar shift cipher (ROT$n$)? It's basically a cipher sequence that changes a letter's value from the number chosen. If we use ROT1 on "games", we get "hbnft". The basic i...

9 answers  ·  posted 4y ago by General Sebast1an‭  ·  last activity 26d ago by CrSb0001‭

Question code-golf string sequence encryption decryption
50%
+0 −0
Sandbox Awkward Ordinals [FINALIZED]

posted 1mo ago by trichoplax‭  ·  edited 1mo ago by trichoplax‭

50%
+1 −1
Challenges Convert to Hexadecimal

Challenge Write a program that takes in a number greater than or equal to 0 and outputs its representation in hexadecimal (base 16). Examples 0 => 0 1 => 1 10 => A 15 ...

2 answers  ·  posted 1mo ago by CrSb0001‭  ·  last activity 1mo ago by CrSb0001‭

Question code-golf math base hexadecimal
77%
+5 −0
Challenges Ratio limits of fibonacci-like series

Definition $F_{n}\left(0\right)=0$ $F_{n}\left(1\right)=1$ $F_{n}\left(x\right)=n\cdot F_{n}\left(x-1\right)+F_{n}\left(x-2\right)$ For example: $F_{1}=\left[0,1,1,2,3,5,8,13,21,34,55,89...\ri...

4 answers  ·  posted 4y ago by rak1507‭  ·  last activity 1mo ago by CrSb0001‭

Question code-golf sequence
87%
+12 −0
Challenges Cumulative Counts

Challenge Given an array of numbers return the cumulative count of each item. This is the number of times an item has occurred so far. Examples [1,1,2,2,2,1,1,1,3,3] -> [1,2,1,2,3,3,4,5,1,2]...

21 answers  ·  posted 4y ago by rak1507‭  ·  last activity 1mo ago by CrSb0001‭

Question code-golf
57%
+2 −1
Challenges Give the fool's fibonacci sequence

Recently I asked for tips on improving some code-golf of mine. The code was supposed to output every third value of the Fibonacci sequence starting with 2: 2,8,34,144,610,2584,10946,46368,196418,...

2 answers  ·  posted 2y ago by WheatWizard‭  ·  last activity 1mo ago by CrSb0001‭

Question code-golf sequence open-ended-function fibonacci
71%
+3 −0
Challenges Prove commutativity on this monoid presentation.

Given two binary strings $A$ and $B$ such that $A$ is an anagram of $B$, output a third binary string $S$ such that both $A$ and $B$ can be created by iterated removals of the substring $10101$ fro...

2 answers  ·  posted 2y ago by WheatWizard‭  ·  last activity 1mo ago by m90‭

Question code-golf abstract-algebra
81%
+7 −0
Challenges Bytes to Segfault

Challenge Cause the currently running program to receive the SIGSEGV signal (on Linux or other *nix systems) as fast as possible. What it does with the signal doesn't matter as long as it receives...

11 answers  ·  posted 4y ago by moony‭  ·  last activity 1mo ago by m90‭

Question code-golf *nix
60%
+4 −2
Challenges "Hello, {name}!"

Background While we do have a "Hello, World!" challenge, we still don't have one regarding input. So let's do one! Challenge Create a program that takes an input (not as a function argument) the...

17 answers  ·  posted 3y ago by General Sebast1an‭  ·  last activity 1mo ago by CrSb0001‭

Question code-golf string
66%
+2 −0
Q&A Tips for golfing in Python

If you have any tips for golfing in Python, add them as answers to this post.

19 answers  ·  posted 3y ago by celtschk‭  ·  last activity 1mo ago by trichoplax‭

Question code-golf tips
71%
+3 −0
Q&A Tips for golfing in Lean

Lean is an interactive theorem prover and a functional programming language created in 2013. What tips do you have for golfing in Lean? Tips should be specific to Lean ("remove comments" is not an...

0 answers  ·  posted 1mo ago by CrSb0001‭

Question code-golf tips
83%
+8 −0
Challenges Integer to Roman numeral

The task is to take a decimal integer as input and print the corresponding Roman numeral with capital letters. The program must handle all positive integer numbers between 1 and 1000. Input can be...

3 answers  ·  posted 4y ago by Lundin‭  ·  last activity 1mo ago by Lundin‭

Question code-golf
92%
+24 −0
Challenges "Hello, World!"

Introduction The classic "Hello, World" challenge. What more can I say? Rules Program takes no input. Program outputs Hello, World! with an optional trailing newline. No other output is accep...

63 answers  ·  posted 4y ago by anna328p‭  ·  last activity 2mo ago by CrSb0001‭

Question code-golf kolmogorov-complexity
60%
+1 −0
Sandbox Digit balanced numbers [FINALIZED]

posted 2mo ago by trichoplax‭  ·  edited 2mo ago by trichoplax‭

62%
+3 −1
Challenges Print the modular multiplicative inverse / virtual fractions

Goal Print the modular multiplicative inverse with a modulus of 65536 (or a higher exponent of 2) for odd numbers 1-97. Example output Print these values (or an extension of them): 1 43691 52...

2 answers  ·  posted 1y ago by H_H‭  ·  last activity 2mo ago by CrSb0001‭

Question code-golf math
66%
+2 −0
Challenges Is it part of the mandelbrot set?

Input is a number, you have to decide if it is part of the mandelbrot set or not, after at least 16 iterations. This is done by applying this formula: $z_n = z_{n-1}^2 + c$ repeatedly. $c$ is the ...

2 answers  ·  posted 1y ago by H_H‭  ·  last activity 2mo ago by CrSb0001‭

Question code-golf
75%
+4 −0
Challenges Expand a polynomial

Challenge Given the roots of a polynomial (that is, the $x$ values where the polynomial evaluates to zero), as an array of real numbers, return the polynomial's coefficients. That is, given real ...

5 answers  ·  posted 3y ago by Moshi‭  ·  last activity 2mo ago by panadestein‭

Question code-golf math
60%
+1 −0
Challenges Find all unique quintuplets in an array that sum to a given target

Inspiration: Leetcode's [3Sum] linkLink on CG&CC Problem Given an array nums of n (not necessarily distinct) integers, and given a target number target, return an array of all of the unique...

2 answers  ·  posted 5mo ago by CrSb0001‭  ·  last activity 2mo ago by panadestein‭

Question code-golf array arithmetic
88%
+13 −0
Challenges Partial Sums of Harmonic Series

Given an positive integer $n$, return the least positive integer $k$ such that the $k$th partial sum of the harmonic series is greater than or equal to $n$. For example, if $n = 2$, then $k = 4$, b...

13 answers  ·  posted 4y ago by Quintec‭  ·  last activity 2mo ago by panadestein‭

Question code-golf
80%
+6 −0
Challenges Display a Progress Bar

The goal of this challenge is simple: given a ratio of whole numbers, output a 50-character long progress bar representing the ratio. Rules Input Your program must take two numbers as input. T...

7 answers  ·  posted 6mo ago by Sylvester‭  ·  last activity 2mo ago by panadestein‭

Question code-golf
71%
+3 −0
Challenges Borromean coprimes

Given 3 positive integers, indicate whether they are Borromean coprimes. Definition 3 positive integers are called Borromean coprimes if both of the following are true: Their greatest common d...

5 answers  ·  posted 1y ago by trichoplax‭  ·  last activity 2mo ago by panadestein‭

Question code-golf math
66%
+2 −0
Challenges Expand a greyscale/colour hex code

Consider a type of hexadecimal colour code that supports shorthand for both greyscale and colour: A 6 digit code is interpreted as 2 digits for red, followed by 2 for green, then 2 for blue. A ...

5 answers  ·  posted 4mo ago by trichoplax‭  ·  last activity 4mo ago by Shaggy‭

Question code-golf string
50%
+0 −0
Sandbox Expand a greyscale/colour hex code [FINALIZED]

posted 4mo ago by trichoplax‭  ·  edited 4mo ago by trichoplax‭

71%
+3 −0
Sandbox Display a Progress Bar [FINALIZED]

posted 7mo ago by Sylvester‭  ·  edited 5mo ago by trichoplax‭

80%
+6 −0
Challenges Find the IP address class

Task Given an IP address as a string, find its IP address class. For reference, here is a table: Class Leadingbits Numberof networks Addressesper network Total addressesin class Start...

8 answers  ·  posted 3y ago by Razetime‭  ·  last activity 5mo ago by Lundin‭

Question code-golf
64%
+7 −3
Challenges Make $2 + 2 = 5$

In this challenge, add 2 integers, but if both the integers are 2, output 5. Shortest code in each language wins! Example ungolfed program in Python 3.x def add(x, y): if x == 2 and y == 2: ...

23 answers  ·  posted 3y ago by General Sebast1an‭  ·  last activity 6mo ago by arutonee‭

Question code-golf math number
75%
+4 −0
Challenges Source with the whole alphabet in order of appearance

The challenge is to write as short a source as possible, where the English alphabet (in alphabetical order from top to bottom) "abcdefghijklmnopqrstuvwxyz" is a sub-sequence of the source code. Th...

5 answers  ·  posted 7mo ago by Lundin‭  ·  last activity 7mo ago by Sylvester‭

Question code-golf
71%
+3 −0
60%
+1 −0
Challenges How many odd digits?

Given a positive integer, count its odd digits. Input An integer from 1 to 999,999,999, inclusive, in any of the following formats: A number (such as an integer or floating point number), li...

6 answers  ·  posted 9mo ago by trichoplax‭  ·  last activity 7mo ago by Shaggy‭

Question code-golf number
60%
+1 −0
Sandbox Product of polynomials modulo 2 in integer representation

posted 7mo ago by celtschk‭  ·  edited 7mo ago by celtschk‭

Article code-golf math
50%
+0 −0
Sandbox 3D compass point from 3D coordinates

posted 2y ago by trichoplax‭  ·  edited 7mo ago by trichoplax‭

60%
+1 −0
Sandbox Plain ​​spheres

posted 10mo ago by trichoplax‭  ·  edited 7mo ago by trichoplax‭

83%
+8 −0
Challenges The 50 substrings that validate any string of Roman numerals

Given a string of Roman numerals, decide whether it forms a valid Roman number. If not, output the substring that proves this, from the list of 50 strings described below. Relevant fact This chal...

7 answers  ·  posted 1y ago by trichoplax‭  ·  edited 7mo ago by trichoplax‭

Question code-golf math number string
50%
+0 −0
Challenges Multiplicative perfection

Given a positive integer, indicate whether it is the product of its proper divisors. Integers equal to the product of their proper divisors can be found on the Online Encyclopedia of Integer Seque...

4 answers  ·  posted 8mo ago by trichoplax‭  ·  last activity 7mo ago by celtschk‭

Question code-golf math number decision-problem
50%
+0 −0
57%
+2 −1
Challenges Fibonacci without consecutive digits

Output the Nth number in the list of Fibonacci numbers that have no consecutive digits. Input A non-negative integer (if you treat the Fibonacci numbers as zero-indexed) or a positive integer (...

4 answers  ·  posted 1y ago by trichoplax‭  ·  last activity 8mo ago by Andrew Ray‭

Question code-golf math number sequence fibonacci
50%
+0 −0
Sandbox Digits with subsets of unique probability

posted 9mo ago by trichoplax‭  ·  edited 9mo ago by trichoplax‭

50%
+0 −0
Sandbox How many odd digits? [FINALIZED]

posted 9mo ago by trichoplax‭  ·  edited 9mo ago by trichoplax‭

60%
+1 −0
Challenges Hex ​​​detector

Given an integer from 1 to 1000, indicate whether it is a centered hexagonal number[1] (also known as a hex number). What is a hex number? The hex numbers can be visualised as follows: On a he...

4 answers  ·  posted 11mo ago by trichoplax‭  ·  last activity 9mo ago by trichoplax‭

Question code-golf math number
85%
+10 −0
Challenges Looping counter

Looping counter Create an infinite loop that outputs lines of asterisks, with each line containing one more asterisk. Instead of the asterisk, any printable, non-whitespace character can be used. ...

21 answers  ·  posted 3y ago by celtschk‭  ·  last activity 9mo ago by xrs‭

Question code-golf
66%
+2 −0
Challenges Substring factor

Does a positive integer have a substring as a factor? Input A positive integer. Output One of 2 distinct values to indicate whether the input has a factor that is a strict substring of it...

3 answers  ·  posted 11mo ago by trichoplax‭  ·  last activity 9mo ago by Shaggy‭

Question code-golf math number string
66%
+2 −0
Sandbox Net​​ or​​ not? [FINALIZED]

posted 10mo ago by trichoplax‭  ·  edited 10mo ago by trichoplax‭

50%
+0 −0
Challenges Net​​ or​​ not?

Given a hexomino, indicate whether it is a net of a cube. Input A 6 by 6 grid containing exactly 6 filled squares. The 6 filled squares will be in a single edge connected set (a hexomino). Th...

0 answers  ·  posted 10mo ago by trichoplax‭

Question code-golf math