Linked Questions

14 votes
28 answers
1k views

Am I a Sophie Germain prime? [duplicate]

A Sophie Germain Prime is a prime number P such that 2P+1 is prime as well. Given a prime number as input, your task is to determine whether it is a Sophie Germain Prime. Standard Input/Output rules ...
Mr. Xcoder's user avatar
  • 42.4k
9 votes
20 answers
1k views

Prime numbers between n and 2n [duplicate]

Bertrand's postulate states that there is always at least 1 prime number between n and 2n for all n greater than 1. Challenge Your task is to take a positive integer n greater than 1 and find all of ...
buttercrab's user avatar
6 votes
15 answers
994 views

Check If my String is Prime [duplicate]

We define a prime character as a character that has a prime ASCII value. We define a prime string as a String that only contains prime characters. Given a String that only contains printable ASCII, ...
Mr. Xcoder's user avatar
  • 42.4k
-2 votes
6 answers
365 views

Primes, as efficiently inefficient as possible [duplicate]

Write a program that tests if a number n is prime by checking that none of the integers between 2 and ...
Arcturus's user avatar
  • 7,387
-4 votes
5 answers
212 views

Prime decimal representations of prime binary numbers [duplicate]

Problem Statement: Consider a number n in base-10. Find the smallest base-10 integer i greater than ...
user192361237's user avatar
522 votes
985 answers
194k views

"Hello, World!"

So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most ...
Martin Ender's user avatar
244 votes
456 answers
65k views

Golf you a quine for great good!

Using your language of choice, golf a quine. A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output. No cheating -- that means ...
Rafe Kettler's user avatar
  • 2,717
145 votes
570 answers
47k views

Shortest infinite loop producing no output

Your task is to create the shortest infinite loop! The point of this challenge is to create an infinite loop producing no output, unlike its possible duplicate. The reason to this is because the code ...
user41805's user avatar
  • 13.1k
173 votes
495 answers
35k views

Implement a Truth-Machine

A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does: Gets a ...
a spaghetto's user avatar
  • 11.2k
196 votes
416 answers
77k views

1, 2, Fizz, 4, Buzz

Introduction In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other ...
Beta Decay's user avatar
  • 23.4k
79 votes
261 answers
25k views

Is this even or odd?

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), ...
Matthew Roh's user avatar
  • 5,347
81 votes
94 answers
18k views

Golf all the 16 logic gates with 2 inputs and 1 output!

For example, the gate A and B is a logic gate with 2 inputs and 1 output. There are exactly 16 of them, because: each logic gate takes two inputs, which can be ...
Leaky Nun's user avatar
  • 49.8k
65 votes
115 answers
18k views

List of primes under a million

This is my first code golf question, and a very simple one at that, so I apologise in advance if I may have broken any community guidelines. The task is to print out, in ascending order, all of the ...
Delan Azabani's user avatar
106 votes
39 answers
28k views

Tips for golfing in Java

Are there any useful shortcuts that can be used in Java? As shown below, import already adds at least 17 characters to a program. ...
user avatar
43 votes
116 answers
6k views

Divisibility test

Task Given two strictly positive integers n and d as input, determine whether n is evenly divisible by d, i.e., if there exists an integer q such that n = qd. You ...
Leaky Nun's user avatar
  • 49.8k
137 votes
29 answers
12k views

Making Future Posts Runnable Online with Stack Snippets [closed]

Stack Snippets were recently added to PPCG! Reminiscent of JSFiddle, Stack Snippets allow HTML, CSS, and JavaScript to be run directly in posts! Here is a very simple Stack Snippet: ...
Calvin's Hobbies's user avatar
49 votes
71 answers
7k views

An abundance of integers!

An Abundant number is any number where the sum of its proper divisors is greater than the original number. For example, the proper divisors of 12 are: ...
DJMcMayhem's user avatar
  • 59.3k
43 votes
57 answers
8k views

Catalan Numbers

The Catalan numbers (OEIS) are a sequence of natural numbers often appearing in combinatorics. The nth Catalan number is the number of Dyck words (balanced strings of parenthesis or brackets such as <...
a spaghetto's user avatar
  • 11.2k
33 votes
68 answers
6k views

Count the divisors of a number

Introduction This is a very simple challenge: simply count the divisors of a number. We've had a similar but more complicated challenge before, but I'm intending this one to be entry-level. The ...
jqkul's user avatar
  • 2,272
37 votes
61 answers
5k views

Sum of primes between given range

Write the shortest code for finding the sum of primes between \$a\$ and \$b\$ (inclusive). Input \$a\$ and \$b\$ can be taken from command line or stdin (space seperated) Assume \$1 \le a \le b \le ...
st0le's user avatar
  • 2,218
136 votes
11 answers
14k views

(-a) × (-a) = a × a

We all know that \$(-a) \times (-a) = a \times a\$ (hopefully), but can you prove it? Your task is to prove this fact using the ring axioms. What are the ring axioms? The ring axioms are a list of ...
Wheat Wizard's user avatar
  • 98.8k
34 votes
51 answers
4k views

Prime counting function

Introduction The Prime Counting Function, also known as the Pi function \$\pi(x)\$, returns the amount of primes less than or equal to x. Challenge Your program will take an integer x which you can ...
Pavel's user avatar
  • 9,377
97 votes
15 answers
12k views

Create a programming language that only appears to be unusable

Robbers' challenge thread is here. Cops' challenge: Design a programming language that appears to be unusable for programming, but admits computation (or at least completion of the task) through some ...
feersum's user avatar
  • 31.4k
35 votes
54 answers
4k views

Generating a random alphanumeric string of length N

What is the shortest way of generating a random string with a given length and with only alphanumeric characters allowed? example of a random string: with N = 9 output would be ...
m13r's user avatar
  • 455
36 votes
41 answers
4k views

Is it a Mersenne Prime?

A number is a Mersenne Prime if it is both prime and can be written in the form 2n-1, where n is a positive integer. Your task is to, given any positive integer, determine whether or not it is a ...
FlipTack's user avatar
  • 14.7k
49 votes
35 answers
2k views

PPCG Jeopardy: Cops

How well do you know the site? Let's find out. This is a cops-and-robbers challenge. Robber's thread. As a cop, you need to: Find a non-deleted, non-closed challenge on this site to answer. The ...
Nathan Merrill's user avatar
87 votes
6 answers
42k views

Hard code golf: Regex for divisibility by 7

Matthias Goergens has a 25,604-character (down from the original 63,993-character) regex to match numbers divisible by 7, but that includes a lot of fluff: redundant parentheses, distribution (...
Charles's user avatar
  • 2,771
27 votes
43 answers
2k views

A prime test that's LITERALLY prime

Write a program that will test the primality of a specified number, and give the output as a Boolean value (True is prime). Your prime test can (but doesn't have to) be valid for the number 1. Here'...
Noah L's user avatar
  • 861
39 votes
30 answers
5k views

Can the number reach 1 by repeatedly subtracting the largest prime less than it?

Challenge: Given a number, take the largest prime strictly less than it, subtract it from this number, do this again to this new number with the biggest prime less than it, and continue doing this ...
xenia's user avatar
  • 8,142
33 votes
30 answers
5k views

Ah, why is there a bug in my program?

This challenge is inspired by @LuisMendo's MATL answer to my "binary multiples" challenge. Task Pick a code-golf challenge that is open and that has been posted before this one; let me call it the "...
RGS's user avatar
  • 14.1k
19 votes
50 answers
3k views

What's the time, chap?

I honestly cannot believe that this is not a question yet on Code Golf, but.... Print the local time (with a.m. or p.m.) as a string to the console, preceded by "It's ". Example: ...
Daniel's user avatar
  • 6,719
27 votes
36 answers
3k views

Primes with prime bit-counts

Task Find all the non-negative integers up to and including a given non-zero positive integer n, that are prime and the count of 1's and ...
Gurupad Mamadapur's user avatar
46 votes
15 answers
4k views

Tips for Creating/Maintaining a Golfing Language

Creating a golfing language can be hard. Let's help budding golfing language creators out and provide some helpful tips on how to create one. I'm looking for tips on: The design process ...
lyxal's user avatar
  • 33.6k
31 votes
29 answers
4k views

Is this a Smith number?

Challenge description A Smith number is a composite number whose sum of digits is equal to the sum of sums of digits of its prime factors. Given an integer N, ...
shooqie's user avatar
  • 5,652
39 votes
24 answers
3k views

Print the nth prime that contains n

This question will be a twist on finding the nth prime number. Challenge You must write a program that will take one input n, ...
ericw31415's user avatar
  • 2,302
26 votes
31 answers
2k views

Magnanimous numbers

Given an positive integer as input determine if it is a magnanimous number. A magnanimous number is a number such that any insertion of a + sign between any two ...
Wheat Wizard's user avatar
  • 98.8k
22 votes
26 answers
10k views

List Prime Numbers [duplicate]

Introduction Prime numbers are simple, right? Well, now you get your chance to find out! Challenge You must write a program or function that takes an input n and ...
Elliot A.'s user avatar
  • 454
17 votes
34 answers
6k views

The program that will find the next prime number

Intro: You accidentally corrupted the flow of time with a device you made for fun, that turned out to be a time machine. As a result, you got pushed to the far future. You realized that computing, ...
Offtkp's user avatar
  • 3,062
26 votes
26 answers
2k views

Get thee behind me Satan-Prime!

Satan-Primes who are they? they are Primes containing 666 these are Satan-Primes:...
user avatar
27 votes
21 answers
5k views

It almost works (Cops' Thread)

Robbers' Thread Your challenge is to find an existing challenge, and implement it in a way such that certain inputs fail. At least one input must not produce the correct output (use the other ...
emanresu A's user avatar
  • 38.8k
15 votes
36 answers
4k views

Generate Sexy Primes

Sexy Primes are pairs of numbers \$(n, n+6)\$ such as \$n\$ and \$n+6\$ are both prime You need to create a function which will take an integer, check for sexy primes from 0 to that integer, and ...
Rohit's user avatar
  • 263
46 votes
12 answers
3k views

Prime parity peregrination

The purpose of this challenge is to graphically depict a walk on the plane, where the direction of each step \$k\$ is determined by the primality of \$k\$ and the parity of its binary expansion. ...
Luis Mendo's user avatar
  • 105k
19 votes
30 answers
7k views

Cops and Robbers: Redacted Primality (Cops' Thread)

This challenge was originally sandboxed by Magic Octopus Urn; I adopted and posted it with his permission. This is the cops' thread. The robbers' thread is here. The challenge Step One: Write a ...
MD XF's user avatar
  • 13.9k
18 votes
31 answers
2k views

Finding Not-Quite-Prime Numbers

Your challenge, should you chose to accept it, is to code-golf a function that returns true or false (or some similar meaningful representation of yes and no) if a number meets the following criteria: ...
Mr. Llama's user avatar
  • 2,429
36 votes
17 answers
4k views

Primes other than Optimus

Challenge Given an input integer n > 0, output the number of primes (other than n, if n ...
AdmBorkBork's user avatar
  • 43.5k
15 votes
27 answers
2k views

Prime or highest factor

Challenge: Given an array of non-negative whole numbers numbers in the range of 0 to Infinity, Check whether all of them are primes or not. (You can take input as ...
user avatar
19 votes
23 answers
2k views

Additive Primes amongst first x Primes

Definition of Additive Primes: Numbers which have exactly 2 divisors are called Prime numbers. Numbers which are prime and their sum of digits is also a prime number are called Additive Primes Task:...
Mr. Xcoder's user avatar
  • 42.4k
26 votes
8 answers
3k views

Create a programming language that only appears to be unusable (Robbers' thread)

See the cop thread for more information. Each answer to this question should crack an answer there. That is to say, it should be code to find the third-largest integer in the input when run in the ...
feersum's user avatar
  • 31.4k
31 votes
14 answers
2k views

Array Escape - get out of there

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 ...
Michael Kunst's user avatar
22 votes
16 answers
3k views

​Cuban​ ​Primes

Given a natural number \$n\$, return the \$n\$-th cuban prime. Cuban Primes A cuban prime is a prime number of the form $$p = \frac{x^3-y^3}{x-y}$$ where \$y>0\$ and \$x = 1+y\$ or \$x = 2+y\$ ...
flawr's user avatar
  • 43.8k

15 30 50 per page