Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

Filter by
Sorted by
Tagged with
-5
votes
9answers
46 views

Lists of power!

Generate the following list of lists consisting of the unique last digits of the powers from 1 to 9 for the numbers [0..9] ...
9
votes
15answers
158 views

Semidivisibility

NOTE: Some terminology used in this challenge is fake. For two integers n and k both greater than or equal to 2 with ...
17
votes
25answers
594 views

Reconstruct an integer from its prime exponents

All integers \$n > 0\$ can be expressed in the form $$n = \prod_{\text{prime } p} p^e = 2^{e_2} 3^{e_3} 5^{e_5} 7^{e_7} \cdots$$ This form is also known as it's prime factorisation or prime ...
5
votes
1answer
72 views

Filetype Color Codes

On Unix-like systems, the ls command lists files. GNU's version of ls also colors them according to their properties and the ...
6
votes
4answers
565 views

Three, Three, No

Given a non-empty sequence of non-negative integers, output any permutation of it in which no two adjacent elements have a sum that is divisible by 3. If it is impossible, either crash the program, ...
4
votes
14answers
163 views

Which th second now in this year [closed]

In this challenge you have to find out which nth second it is now in this year, current date and time now. Or in other words, how many seconds have passed since New Year. An example current Date is (...
18
votes
1answer
264 views

Is this Game of Go configuration fully alive?

Background This challenge is about the Game of Go. Here are some rules and terminology relevant to this challenge: Game of Go is a two-player game, played over a square board of size 19x19. One of ...
26
votes
23answers
2k views

First sequence with no square differences

Consider the sequence \$(a_n)\$ defined in the following way. \$a_0=0\$ For all \$n=1, 2, 3, \dots\$, define \$a_n\$ to be the smallest positive integer such that \$a_n-a_i\$ is not a square number, ...
-2
votes
0answers
157 views

Any shorter way to golf ((123&b)==123) or ((5&b)==5) for integers b in javascript?

The small code sample (42&x)==42 which checks if a certain bit or all bits in a bitmask is set in an int feels like something that should be golf-able, but I'm ...
-13
votes
20answers
330 views

“Simple” Programming Homework

Your friend has been caught sleeping in class again! As punishment, his computer science teacher has assigned him homework, knowing that he will not be able to solve it due to not having paid any ...
10
votes
10answers
991 views

Autogrammatic pairs

For today's task, we have two programs, P and Q, both in the same language. Each of them receives a single-character input. If P receives character K, P says how many times K appeared in Q. (You can ...
14
votes
5answers
569 views

Convert Gemtext to HTML

Gemtext is a very simple markup format used by the alternative web protocol Gemini. Write a Gemtext to HTML converter. From the Wiki: A line of text is a paragraph, to be wrapped by the client. It is ...
15
votes
15answers
1k views

Generalise perfect numbers

Let \$\sigma(n)\$ represent the divisor sum of \$n\$ and \$\sigma^m(n)\$ represent the repeated application of the divisor function \$m\$ times. Perfect numbers are numbers whose divisor sum equals ...
-4
votes
3answers
157 views

Draw This ASCII art In The Least Amount Of Bytes(edited) [closed]

your challenge is to draw this ASCII art: ...
-6
votes
0answers
105 views

Assembly Fork Bomb boot virus [closed]

Create an Assembly Fork Bomb virus that runs at boot. Rules Works on DOS Compile with nasm -f bin The shortest code will be accepted.
-5
votes
0answers
97 views

Assembly “Hello, World!” without loop (bootloader) [closed]

Create a bootloader that prints "Hello, world!" without loop. Loop is not allowed in this example: func: jmp func The shortest code will be accepted.
16
votes
21answers
2k views

Primes and Twin Primes

Your challenge is to write a program to print all the primes (separated by one or more whitespace characters) less than a given integer N with an asterisk (...
-3
votes
1answer
126 views

Python Prime Problem [duplicate]

Your challenge is to write a Python program to print all the primes (separated by whitespace) less than a given integer N with an asterisk (...
-2
votes
31answers
438 views

Print A-Z and their alphabet index without using 1,2,4,6

You need to print A-Z like this: ...
3
votes
0answers
73 views

Continuous Port Ranges [duplicate]

Background Network discovery tool Nmap takes a list of TCP/UDP port numbers as input and performs a security audit against the listed ports. The target port listing on the command line includes ...
-6
votes
18answers
154 views

Reverse and error!

You have to write a program, if its source code is reversed, then it will error. For example, if your source is ABC, then reversing it and writing ...
19
votes
24answers
2k views

Is it zero- or one- indexed?

Your task is to determine whether some arbitrary programming language has zero-indexed or one-indexed arrays based on sample inputs and outputs Inputs An array of integers with at least 2 elements A ...
-2
votes
17answers
405 views

Write an interpreter for “interpreter”

I just created a language on the spot, and it's called "interpreter". Called as such because the only valid word is "interpreter"! A sample program in "interpreter" looks ...
-8
votes
9answers
130 views

Write an interpreter for A programming language is a formal language comprising a set of instructions that produce various kinds of output [closed]

A programming language is a formal language comprising a set of instructions that produce various kinds of output is a very simple "programming" langauge. The sentence "A programming ...
-6
votes
0answers
83 views

Reverse error quine [duplicate]

Based on this Write a quine that prints it own source code in reverse, but to STDERR. Penalties +200 using other files I.E. reverse.txt +150 internet usage +100 ...
25
votes
21answers
2k views

BalancE the UppercasE

Oh, No! the sentences are out of balance. Quick! balance them. A word is defined as follows: A sequence of letters [A-Za-z] separated by any non-letter character ([0-9] ~+- etc.) A word is BaLanCeD ...
17
votes
18answers
1k views

Determine the degree of a polynomial

Background: For this challenge, a polynomial looks like this: $$P(x)=a_nx^n+a_{n-1}x^{n-1}+\dots+a_2x^2+a_1x+a_0$$ The degree, \$n\$, is the highest power \$x\$ is raised to. An example of a degree 7 ...
21
votes
32answers
2k views

Remove excessive occurrences

Given an array \$A\$ of positive integers between \$1\$ and \$9\$ inclusive and a positive integer \$n\$, remove all integers in \$A\$ which appear more than \$n\$ times. For example: ...
29
votes
83answers
8k views
+50

Print 0 to 100 without 1-9 characters

Print 0 to 100 without using characters 1,2,3,4,5,6,7,8,9 in your code. Seperator of numbers can be comma, whitespace or newline. Shortest code wins.
6
votes
11answers
430 views

Constrained integer partition

Challenge In this challenge, all numbers are in \$\mathbb{N}_0\$. Create a function or program that, when given a number \$N\$ and a tuple of \$k\$ numbers \$(n_i)\$ (all ≤ \$N\$), returns the number ...
18
votes
11answers
2k views

What's next, Achilles?

Powerful numbers are positive integers such that, when expressed as a prime factorisation: $$a = p_1^{e_1} \times p_2^{e_2} \times p_3^{e_3} \cdots \times p_k^{e_k}$$ all exponents \$e_1, e_2, ...\$ ...
18
votes
2answers
2k views

Can you spot the liar?

It's the end of the year, you and your friends have just received your grades and ranks for the GOLF101 class. On a chat group, everyone sends their grade and rank to see who's got the best one. ...
-5
votes
1answer
191 views

Johny Johny yes papa [duplicate]

We (nearly) all know about the rhyme "Johny Johny yes papa", that's johny johny yes papa eating sugar no papa telling lies no papa open your mouth hahaha ...
15
votes
39answers
5k views

1, 2, miss a few, 99, 100

When I was a kid, there was a "really cool" shortcut to count to 100: 1, 2, miss a few, 99, 100 Output the exact string above, in the fewest characters ...
0
votes
0answers
102 views

Is this an anagram of its own source code? [duplicate]

I like anagrams. I like programs that reference their own source code. So this challenge combines them! Input. The input to the program could be anything, including letters, numbers, symbols, you name ...
-6
votes
2answers
162 views

Your challenge is to make a script that reverses a word then replaces letters

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: ...
9
votes
11answers
768 views

Elias omega coding: decoding

Related: Elias omega coding: encoding Background Elias omega coding is a universal code which can encode positive integers of any size into a stream of bits. Given a stream of bits \$S\$, the decoding ...
-1
votes
0answers
48 views

Write a linux “figlet” program implementation [duplicate]

From Wikipedia FIGlet is a computer program that generates text banners, in a variety of typefaces, composed of letters made up of conglomerations of smaller ASCII characters (see ASCII art). The ...
0
votes
1answer
147 views

Spot the different [closed]

Introduction This challenge was originally the "Among Us" challenge in the "Misc" category of YASCON CTF 2020. (The link includes an answer to that challenge. Click at your own ...
-6
votes
36answers
474 views

Print a string without using quotes in your source code [closed]

The challenge is as simple as it suggests, you have to print a string without using single/double quotes in source code. The string is: ...
17
votes
5answers
885 views

Count all binary relations

A binary relation on a set \$X\$ is simply a subset \$S \subseteq X \times X\$; in other words, a relation is a collection of pairs \$(x,y)\$ such that both \$x\$ and \$y\$ are in \$X\$. The number of ...
16
votes
12answers
1k views

Package distribution

While at work I spotted a nice and simple challenge. The job was to stock products in cargo units with a certain capability. Since an order can have various batches, coming in sequence from the ...
11
votes
1answer
181 views

Generating minimal regular expression character classes

Background Character classes are a standard way to indicate a set of characters to match in regular expressions. For example, the class [ab] matches a or b, ...
14
votes
21answers
1k views

N-dimensional pyramid numbers [duplicate]

Given two inputs, a number n and a dimension d, generate the nth d-dimensional pyramid number. That was confusing, let me try again. For d = 1, the numbers start 1,2,3,4,5 and is the number of points ...
14
votes
11answers
2k views

Make a !!!Batch compiler/translator

!!!Batch is another derivative of the Windows Batch programming language, its wiki is here Your challenge is to create an compiler/translator that reads a !!!Batch program and returns a Windows Batch ...
0
votes
11answers
217 views

Check if a server is online or not for you? [closed]

Inspired from Is this site down or is it just me? Challenge You have to print if a website server is online or not, for you. Input The domain name, like ...
15
votes
23answers
2k views

Get the IP address of google.com [closed]

Challenge In this simple challenge, you have to print the public IP address of google.com. Rules You have to output either the IPv6 or IPv4 address, and do it by ...
1
vote
6answers
216 views

Maximum distance to station

Looking at the following hackerrank problem: https://www.hackerrank.com/challenges/flatland-space-stations You are given a number n where cities can be at indices 0 to n-1 and also given an unsorted ...
3
votes
5answers
227 views

Write A Book Cipher [closed]

Introduction Book cipher A Book cipher is a very unique method of a encipher. Here's how's it done: You have a book / a document or a article (something full of text, the more pages of text the ...
11
votes
14answers
1k views

Verify the inequality!

Left in sandbox for at least 3 days. I want to verify if this inequality is true: for \$n\geq4\$, if \$a_1,a_2,a_3,\dots,a_n\in R_+\cup\{0\}\$ and \$\sum_{i=1}^na_i=1\$, then \$a_1a_2+a_2a_3+a_3a_4+\...

1
2 3 4 5
204