text:
Find all \$k\$-smooth pairs
Introduction
In number theory, we say a number is \$k\$-smooth when its prime factors are all at most \$k\$. For example, 2940 is 7-smooth because \$2940=2^2\cdot3\cdot5\cdot7^2\$.
Here, we define a \$k\$-smooth pair as two consecutive integers which both are \$k\$-smooth. An example of 7-smooth pair will be \$(4374,4375)\$ because \$4374=2\cdot3^7\$ and \$4375=5^4\cdot7\$. Fun fact: This is actually the largest 7-smooth pair.
Størmer proved in 1897 that for every \$k\$, there are only finitely many \$k\$-smooth pairs, and this fact is known as Størmer's Theorem.
Challenge
Your task is to write a program or function that, given a prime number input \$k\$, outputs or returns all \$k\$-smooth pairs without duplicate (order within the pair does not matter) in any order you want.
Please be noted that for prime numbers \$p\$ and \$q\$, assuming \$p<q\$, all \$p\$-smooth pairs are also \$q\$-smooth pairs.
Sample I/O
Input: 2
Output: (1, 2)

Input: 3
Output: (1, 2), (2, 3), (3, 4), (8, 9)

Input: 5
Output: (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (8, 9), (9, 10), (15, 16), (24, 25), (80, 81)

Input: 7
Output: (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10), (14, 15),
        (15, 16), (20, 21), (24, 25), (27, 28), (35, 36), (48, 49), (49, 50), (63, 64),
        (80, 81), (125, 126), (224, 225), (2400, 2401), (4374, 4375)

Restriction
The program or function should theoretically terminate in finite time for all inputs. Standard loopholes are disallowed by default.
Winning Criteria
As this is a code-golf challenge, shortest valid submission for each language wins.

Could you please add test cases for 2, 3, and 5?

@JonathanAllan 2-, 3- and 5- smooth pairs are included in the 7-smooth pairs, but I will add the cases for clarity

Is having (1, 2) part of the output mandatory?..

@KevinCruijssen Yes, all outputs should contain the (1, 2) pair.

JavaScript (ES7),  234  232 bytes
Finds the solutions by solving Pell equations of the form \$x^2-2qy^2=1\$, where \$q\$ is a \$P\$-smooth square free number.
This is an implementation of Derrick Henry Lehmer's procedure, derived from Størmer's original procedure.
Returns an object whose keys and values describe the \$P\$-smooth pairs.
P=>[...Array(P**P)].map((_,n)=>(s=(n,i=0,k=2)=>k>P?n<2:n%k?s(n,i,k+1):s(n/k,i,k+i))(n,1)&&(_=>{for(x=1;(y=((++x*x-1)/n)**.5)%1;);(h=(x,y)=>k--&&h(X*x+n*Y*y,X*y+Y*x,x&s(x=~-x/2)&s(x+1)?r[x]=x+1:0))(X=x,Y=y,k=P<5?3:-~P/2)})(),r={})&&r

Try it online!
How?
The helper function \$s\$ tests whether a given integer \$n\$ is a \$P\$-smooth number when it's called with \$i=0\$, or a square free1 \$P\$-smooth number when it's called with \$i=1\$.
s = (
  n,
  i = 0,
  k = 2
) =>
  k > P ?
    n < 2
  :
    n % k ?
      s(n, i, k + 1)
    :
      s(n / k, i, k + i)

We look for all square free1 \$P\$-smooth numbers in \$[1..P^P-1]\$, where \$P^P\$ is used as an upper bound for \$P!\$.
P=>[...Array(P ** P)].map((_, n) => s(n, 1) && (...))

For each number \$n\$ found above, we look for the fundamental solution of the Pell equation \$x^2-ny^2=1\$:
(_ => {
  for(x = 1; (y = ((++x * x - 1) / n) ** .5) % 1;);
  ...
})()

(the above code is the non-recursive version of my answer to this other challenge)
Once the fundamental solution \$(x_1,y_1)\$ has been found, we compute the solutions \$(x_k,y_k)\$ with \$k\le max(3,(P+1)/2)\$, using the recurrence relations:
$$x_{k+1}=x_1x_k+ny_1y_k\\
y_{k+1}=x_1y_k+y_1x_k
$$
For each \$x_k\$, we test whether \$x_k\$ is odd and both \$(x_k-1)/2\$ and \$(x_k+1)/2\$ are \$P\$-smooth. If so, we store them in the object \$r\$.
( h = (x, y) =>
  k-- &&
  h(
    X * x + n * Y * y,
    X * y + Y * x,
    x &
    s(x = ~-x / 2) &
    s(x + 1) ?
      r[x] = x + 1
    :
      0
  )
)(X = x, Y = y, k = P < 5 ? 3 : -~P / 2)

1: Because it does not test the primality of the divisors, the function \$s\$ will actually be truthy for some non-square free numbers, even when it's called with \$i=1\$. The idea is to filter out most of them so that not too many useless Pell equations are solved.

Hi Arnauld! I just couldn't wrap my head around these two: x = ~-x / 2 and -~P / 2.Are these some kind of rounding...

@rv7 ~x is a bitwise NOT, which computes -(x+1). Therefore, ~-x is -(-x+1) = x-1 and -~x is -(-(x+1)) = x+1. Like all bitwise operations in JS, only the 32-bit integer part is taken into account. So the they can indeed be used for rounding. But both $x$ and $P$ already are integers here.

Jelly, 16 14 bytes
4*ÆfṀ<ɗƇ‘rƝLÐṂ

Try it online!
Checks for pairs up to \$4^k\$ which is inefficient for larger \$k\$ but should ensure none are missed.
Thanks to @JonathanAllan for saving 1 byte!
Explanation
4*ÆfṀ<ɗƇ‘rƝLÐṂ  | Monadic link, input k

4*              | 4**k, call this n
      ɗƇ        | For each number from 1..n filter those where:
  Æf            |   - Prime factors
    Ṁ           |   - Maximum
     <  ‘       |   - Less than k+1
         rƝ     | Inclusive range between neighbouring values
           LÐṂ  | Keep only those of minimum length (i.e. adjacent values)

Are you sure that $4^k$ will always be large enough? In my solution, I used $k!^2$ but JonathanAllan was not sure that it would always be large enough. If  $4^k$ does always work, I would be curious to hear an explanation.

@ComradeSparklePony I looked at the first 20 terms of A117581 in OEIS and tried various functions of k. Using $4^k$ is big enough for small k, and seems to rapidly exceed the value of A117581 as k increases. However, I don’t have a deductive proof.

Thanks for the quick response. I was thinking similarly, but more broadly: "factorial gets pretty high quickly, it's probably big enough." (turns out it wasn't unless I squared it). Congrats on the shorter and more efficient golf, you have my upvote.

Note (from https://oeis.org/A002072) "a(n) < 10^n/n except for n=4. (Conjectured, from experimental data.) - M. F. Hasler, Jan 16 2015". I think we have to stick with the weak bound of Lehmer in https://projecteuclid.org/download/pdf_1/euclid.ijm/1256067456 (theorem 7) unless we can prove otherwise.

...there's an open question over on Mathematics SE asking exactly this too!

f’$ż‘$ can be golfed to rƝLÐṂ

@JonathanAllan It’s worth noting that my current method uses $4^k$, and since k is always >= 2n where k is the n’th prime, this will be a weaker bound than Hasler’s. Thanks for the golf!

@PeterTaylor that’s for the number of pairs, not the maximum number. The problem is knowing a bound on the maximum number of pairs doesn’t let you stop searching

05AB1E, 8 bytes
°Lü‚ʒfà@

Try it online!
Explanation:
°            # 10 ** the input
 Lü‚         # list of pairs up to that number
    ʒ        # filtered by...
     fà      # the greatest prime factor (of either element of the pair)...
       @     # is <= the input

Haskell, 118 107 bytes
-11 bytes thanks to nimi
q 1=[1]
q n=(:)<*>q.div n$[x|x<-[2..n],mod n x==0]!!0
f k|let r=all(<=k).q=[(n,n+1)|n<-[1..4^k],r n,r(n+1)]

Try it online!

q n calculates a list of all prime factors of n
f k generates a list of \$k\$-smooth pairs for a given k by filtering a list of all pairs

You can loop through [2..n] within p and inline it into q. Try it online!

Jelly, 123 bytes
¹©Æ½Ø.;µU×_ƭ/;²®_$÷2ị$}ʋ¥⁸;+®Æ½W¤:/$$µƬṪ€F¹;Ḋ$LḂ$?ṭ@ṫ-ṚZæ.ʋ¥ƒØ.,U¤-ịWµ1ịżU×®W¤Ɗ$æ.0ị$ṭµ³’H»3¤¡
ÆRŒPP€ḟ2ḤÇ€ẎḢ€+€Ø-HÆfṀ€<ẠʋƇ‘

Try it online!
This is a relatively efficient but long Jelly answer that uses the continued fractions method to solve the fundamental solution for the Pell equations for \$2×\$ each k-smooth square-free number, finds \$\max(3, \frac{k+1}{2})\$ solutions for each and then checks whether \$\frac{x-1}{2}, \frac{x+1}{2}\$ are smooth for each solution. This is Lehmer’s method, as described in the question’s Wikipedia link.
A full program that takes a single argument, \$k\$ and returns a list of lists of pairs. The code above doesn’t sort the final output, but the TIO link does.

Jelly, 24 bytes
³!²R‘Ė
ÇÆFḢ€€€’<³FȦ$€Tị¢

Try it online!
This takes a long time for 7, but it computes much faster if you remove the squaring of the factorial: Try it online!
Explanation:
³!²R‘Ė                Generates a list like [[1,2],[2,3],...]
³!²                  Take the square of the factorial of the input
   R                 Range 1 through through the above number.
    ‘Ė               Decrement and enumerate, yielding desired list

ÇÆFḢ€€€’<³FȦ$€Tị¢
Ç                    Get the list of pairs
 ÆF                  Get the prime factors of each number
   Ḣ€€€              Get the base of each
       ’<³           Is each base less than or equal to the input?
          FȦ$€       Check that all bases of a pair fit the above.
              T      Get a list of the truthy indexes
               ị¢    Index into the original list of pairs
                     Implicit output

-3 bytes thanks to @JonathanAllen

I don't read Jelly, can you give an explanation on how this works?

I don't think this works - isn't (8,9) a 3-smooth pair since $8=2^3$ and $9=3^2$?

I'm not sure it is though. What makes you think that will hold?

@JonathanAllan Naive optimism and the fact for all examples I've seen (admittedly not many), the largest pair is less than k! (except for 3, which has a small factorial because it is a small number).

More upper bounds: A117581

https://projecteuclid.org/download/pdf_1/euclid.ijm/1256067456 has a proof of a weak upper bound on the product of the largest pair, but I believe yours is tighter - e.g. at [2,3,5,7,...,41] theirs would bound $(v,w)$ to have $v\times w<10^{10^{9925}}$ while your bound is equivalent to one of $(41!^2-1)\times(41!^2)$ which is roughly $10^{199}$ (yes the value is below this, but will it always be?)

@Arnauld that does not help, since they certainly fit within the bound used here.

³!²R‘Ė would save 2, and ÆfQ€€ would save 1.

@EmbodimentofIgnorance Added explanation.

@JonathanAllan I may be misunderstanding this, in the paper it says that there is an upper bound of the number of pairs of $3^{2t+1}$, whereas in my program there is an upper bound of $t!^2$ which will be larger for any given $t$, right? I haven't yet taken a course that deals with math at this level, so please correct me if I got anything wrong.

The upper bound you're using is on the maximum number used in a pair, not on the number of pairs (you can't implement an upper bound on the number of pairs in this way as you wont know when to stop looking!) See theorem 7 for an upper bound on the product of the largest pair.

...if the factorial were enough in all cases >2 then ³‘!R‘Ė would be faster.

Wolfram Language (Mathematica), 241 bytes
uses Pell equations
(s=#;v@a_:=Max[#&@@@#&/@FactorInteger@a]<=s;Select[{#-1,#+1}/2&/@(t={};k=y=1;While[k<=Max[3,(s+1)/2],If[IntegerQ[x=Sqrt[1+2y^2#]],t~AppendTo~x;k++];y++];t),v@#&]&/@Join[{1},Select[Range[3,Times@@Prime@Range@PrimePi@s],SquareFreeQ@#&&v@#&]])&

Try it online!

Python 3 + sympy, 116 bytes
import sympy
def f(k):x=[i for i in range(2,4**k)if max(sympy.factorint(i))<=k];return[(y,y+1)for y in x if y+1in x]

Try it online!
Python 3 + sympy, 111 bytes
from sympy import*
def f(k):
 b=1
 for i in range(2,4**k):
  x=max(factorint(i))<=k
  if x&b:print(i-1,i)
  b=x

Try it online!
Two variations on my Jelly answer but in Python 3. They both define a function which accepts an argument k. The first returns a list of tuples of the pairs that meet the criteria. The second prints them to stdout.

Pyth, 15 bytes
f!>#QsPMTCtBS^4

Try it online!
Uses Nick Kennedy's observation that no output number will be larger than 4^k.

05AB1E, 16 bytes
°LʒfàI>‹}Xšü‚ʒ¥`

Try it online (extremely inefficient, so times out for \$n\gt3\$..). Here a slightly faster alternative, although still pretty slow..
Explanation:
°                # Take 10 to the power of the (implicit) input
 L               # Create a list in the range [1, 10^input]
  ʒ              # Filter this list by:
   fà            #  Get the maximum prime factor
     I>‹         #  And check if it's smaller than or equal to the input
        }Xš      # After the filter: prepend 1 again
           ü‚    # Create pairs
             ʒ   # And filter these pairs by:
              ¥` #  Where the forward difference / delta is 1

Stax, 14 bytes
Θ",²aÇu,á‼⌐çLB

Run and debug it
This is not the shortest possible program, but it begins producing output as soon as matching pairs are found.  It does terminate eventually, but output is produced as it's found.

Ruby, 89+8 = 97 bytes
Uses the -rprime flag. For each number \$i\$ from 1 to \$4^n\$, map it to [i, i+1] if both are \$n\$-smooth, otherwise map it to false, then prune all false from the list.
->n{g=->x{x.prime_division.all?{|b,_|b<=n}};(1..4**n).map{|i|g[i]&&g[i+1]&&[i,i+1]}-[!1]}

Try it online!


text:
Generate ladder of integers using the least number of unique characters (in C++)
I am new to the sport of code golf. I am trying to generate a ladder of integers using the least number of unique characters in C++.
Let's say we are given an integer 4.
We will generate the following ladder:
1
1 2
1 2 3
1 2 3 4
In short, my program will read a positive integer from stdin and print this ladder to the output. I am trying to do so with the least number of unique characters possible.
My program is as follows:
#include<iostream>

int i;
int ii;
int iii;
int iiii;

main() {
    std::cin >> i;
    for(ii++; ii <= i; ii++) {
        int iii = iiii;
        for(iii++; iii <= ii; iii++) {
            std::cout << iii << " ";
        }
        std::cout << std::endl;
    }
}

Here's the checker that I used to check the number of unique characters in my program:
#include <cstdio>
#include <cstring>
using namespace std;
int check[300],diffcnt=0,cnt=0,t;
char c;
double score;
int main(){

    memset(check,0,sizeof(check));
    FILE *in=fopen("ans.cpp","r");
    while(fscanf(in,"%c",&c)!=EOF){
        cnt++;
        if(!check[c]){
            check[c]=1;
            if(c=='\r'||c=='\n') continue;
            diffcnt++;
        }
    }
    if(diffcnt<25) printf("100\n");
    else if(diffcnt<30){
        printf("%.3lf\n",20.0*100.0/cnt+20.0*(29-diffcnt));
    }
    else{
        score=20.0;
        for(int x=95;x<cnt;x++) score*=0.9;
        printf("%.3lf\n",score);
    }
    printf("Unique Characters: %d\n", diffcnt);
    printf("Total Characters: %d\n", cnt);
    return 0;
}

Preferably I wish to use less than 25 unique characters to complete this program (excluding newline characters but including whitespace). Currently, my program uses 27. I am not sure how to optimize it further.
Could someone please advise me on how to optimize it further (in terms of the number of unique characters used)? Please note that only C++ can be used.

It is certainly novel to ask for [tag:tips] regarding any other scoring criteria than [tag:code-golf], but afaict, it is on-topic, since the [tag:tips] pages says to make it a better answer to a programming challenge that is on-topic.

This would have a wider interest if extended to any language

@LuisMendo I don't really think that is true in this case, since many languages completely trivialise this scoring scheme. If this user wants help learning to "unique golf" it only really makes sense in a subset of languages, so I think this is much better as a tip than as a generic challenge. That said the base problem could probably be a challenge if someone wants to post it.

So how many characters would this be in Unary?  Yeah, that'd be super-exploitable.

I think you can use digraphs <% and %> instead of curly braces, and I think I missed some.

I definitely missed some. # is %:, so you can get rid of three characters and introduce one ( { => <%, } => %>, # => %:) and get to 25. If you combine this with the answer below, I think you can get 24.

@someone +1 Oh my god. Where did you learn these tricks? :)

@LanceHAOH Trigraphs are extremely common in [underhanded] questions, and digraphs show up as well when reading about trigraphs.

@someone: fortunately trigraphs have been removed as of ISO C++17.  But only trigraphs, not digraphs or operator keywords like not instead of !.   So if you're unique-golfing in the most recent C++ version, you get to ignore trigraphs, but not digraphs. :/  Current g++ already ignores trigraphs by default even without -std=gnu++17; you have to use -trigraphs to enable them, or -std=c++11 or something for strict conformance to a standard that does include them. But yes, gcc -std=c++17 does do %> as }

I believe I managed to remove the = character from your code, although it now is significantly slower
#include<iostream>

int i;
int ii;
int iii;
int iiii;

int main() {
    std::cin >> i;
    i++;
    for(ii++; ii < i;) {
    for(;iii>iiii;iii++);
    for(;iii<iiii;iii++);
    ii++;
        for(iii++; iii < ii; iii++) {
            std::cout << iii << " ";
        }
        std::cout << std::endl;
    }
}

Its not pretty, but by abusing integer overflow we can get back to 0 without using =
Also we had to change the guards a little. Unfortunately because of the include I couldn't get rid of all new line characters (although its close) so that may be the next avenue for investigation.
Edit: Run out of time for now, but if you include and use strstream and various other libraries, I think you may be able to remove the " character too, again using integers to arrive at the correct character for space and passing it into the strstream

You could #include<std> and eliminate all the :s.  Not great coding practice, but that's beside the point.

@DarrelHoffman I can't get that to work, don't you have to do using namespace std; which would use an additional p for the : so a net 0

Hmm.  Maybe, my C++ is a tad rusty.  Also that adds a g, so net loss I guess.  If this were code gold, we could reduce the byte count by renaming ii, iii, and iiii to other single letter names (pick any other already-used letters), but that's not what this challenge is about, so I guess not.  I'm wondering if there'd be any gains to using getc and putc instead of cin/cout, would have to try it.

My bad. I just read through the checker again. Seems that newline character is ignored. So there is actually no need to bother about removing newlines. But combined with your strategy and the solution by @someone in the comments, I managed to get it to 24 characters. I made the program even faster by using short instead of int. So I got an additional 'h' character. But this let me use the char datatype without additional cost. So I got rid of the " character as well by using character code.

@LanceHAOH: note that signed integer overflow is undefined behaviour in C++, for all signed types including signed char. If you compile with optimization enabled, this code might break with modern compilers, unless you use gcc -fwrapv to make signed overflow well-defined as 2's complement wrap-around. clang supports -fwrapv, too.  (unsigned integer types including unsigned char have well-defined behaviour (wrap-around) in ISO C++). It depends on the ABI whether char is signed char or unsigned char, so char can be ok.

Also, fun fact: atomic<int> is defined as 2's complement with wrap-around.  (But of course is very slow vs. a non-shared int, like maybe 20 cycles per atomic increment on modern x86 with no other threads touching it, vs. 1 cycle for an int that optimizes into a register.  Or for int with -fwrapv a compiler  might see what a loop is doing and just zero it without looping.)  The optional type int32_t is defined to be 2's complement if it exists at all, but isn't wrap-around safe.  It's usually just a typedef for int on implementations that have it.

Anyway, int and char are both fine for golfing with optimization disabled, but just in case you or anyone else are curious about C++ language rules outside of any particular implementation, this is worth pointing out.

@LanceHAOH and @Expired: If you assume ASCII/UTF-8, space is a char with value 32.  If you can create that in a char c variable somehow, you can cout << stuff << c.  If you can create a 0, you could just fully unroll 32 c++; statements to avoid using an = or any digits.  Or maybe char cc(c+c); to double a value into a new variable (left shift by adding to itself), using C++ parenthesis initializer syntax.  So after 2x c++ or something, create new var names to get 4, 8, 16, 32 = ' '

@ExpiredData: turned some of my comments into an answer, 23 bytes with digraphs.

I finally got 24 unique characters by combining the answers of  @ExpiredData and @someone. Also, using the short data type instead of int helped to speed up my program because it takes a shorter time to overflow a short data type.
My code is as follows.
%:include<iostream>

short i;
short ii;
short iii;
short iiii;
char iiiii;

main() <%
    std::cin >> i;
    iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;
    iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;
    iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;
    iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;iiiii++;
    i++;
    for(ii++; ii < i; ii++) <%
        for(;iii;iii++);
        for(iii++; iii < ii; iii++)
            std::cout << iii << iiiii;
        std::cout << iii << std::endl;
    %>
%>

@KevinCruijssen he uses it in char iiiii;, the last of the variable initializations.

@KevinCruijssen That is true. But that allows me to remove the " character because I can use character code to represent the space character. So the net difference in unique characters used = 0.

23 unique characters using Digraphs.  (25 without).  No UB.
Use C++11 braced initializer syntax to list-initialize an integer to zero with int var{}; avoiding = and 0.  (Or in your case, avoiding global iiii).  This gives you a source of zeros other than global variables (which are statically initialized to zero, unlike locals).
Current compilers accept this syntax by default, without having to enable any special options.
(The integer wraparound trick is fun, and ok for golfing with optimization disabled, but signed overflow is undefined behaviour in ISO C++.  Enabling optimization will turn those wraparound loops into infinite loops, unless you compile with gcc/clang -fwrapv to give signed integer overflow well-defined behaviour: 2's complement wraparound.
Fun fact: ISO C++ std::atomic<int> has well-defined 2's complement wrap-around!  int32_t is required to be 2's complement if defined at all, but the overflow behaviour is undefined so it can still be a typedef for int or long on any machine where one of those types is 32 bits, no padding, and 2's complement.)

Not useful for this specific case:
You can also initialize a new variable as a copy of an existing one, with either braces or (with a non-empty initializer), parens for direct initialization.
int a(b) or int a{b} are equivalent to int a = b;
But int b(); declares a function instead of a variable initialized to zero.
Also, you can get a zero with int() or char(), i.e. zero-initialization of an anonymous object.

We can replace your <= compares with < compares by a simple logic transformation: do the loop-counter increment right after the compare, instead of at the bottom of the loop.  IMO this is simpler than the alternatives people have proposed, like using ++ in the first part of a for() to make a 0 into a 1.
    // comments aren't intended as part of the final golfed version
    int n;
    std::cin >> n;      // end condition

    for(int r{}; r < n;) {      // r = rows from 0 .. n-1
        ++r;
        for(int i{}; i < r;) {
            ++i;
            std::cout << i << ' ';
        }
        std::cout << std::endl;
    }

We could golf that down to for(int r{}; r++ < n;) but IMO that's less easy for humans to read.  We're not optimizing for total byte count.

If we were already using h, we could save the ' or " for a space.
Assuming an ASCII or UTF-8 environment, space is a char with value 32.  We can create that in a variable easily enough, then cout << c;
    char c{};
    c++; c++;            // c=2
    char cc(c+c+c+c);    // cc=8
    char s(cc+cc+cc+cc); // s=32 = ' ' = space in ASCII/UTF-8

And other values can obviously be created from a sequence of ++ and doubling, based on the bits of their binary representation.  Effectively shifting a 0 (nothing) or 1 (++) into the LSB before doubling into a new variable.

This version uses h instead of ' or ".
It's much faster than either of the existing versions (not relying on a long loop), and is free of Undefined Behaviour.  It compiles with no warnings with g++ -O3 -Wall -Wextra -Wpedantic and with clang++.  -std=c++11 is optional.  It is legal and portable ISO C++11 :)
It also doesn't rely on global variables.  And I made it more human-readable with variable names that have a meaning.
Unique-byte count: 25, excluding the comments which I stripped with g++ -E.  And excluding space and newline like your counter.  I used sed 's/\(.\)/\1\n/g' ladder-nocomments.cpp | sort | uniq -ic from this askubuntu to count occurrences of each character, and piped that into wc to count how many unique characters I had.
#include<iostream>

int main() {
    char c{};
    c++; c++;            // c=2
    char cc(c+c+c+c);    // cc=8
    char s(cc+cc+cc+cc); // s=32 = ' ' = space in ASCII/UTF-8

    int n;
    std::cin >> n;      // end condition

    for(int r{}; r < n;) {      // r = rows counting from 0
        ++r;
        for(int i{}; i < r;) {
            ++i;
            std::cout << i << s;
        }
        std::cout << std::endl;
    }
}

The only 2 f characters are from for.  We could use while loops instead if we had a use for w.
We could possibly rewrite the loops into an assembly-language style of i < r || goto some_label; to write a conditional jump at the bottom of the loop, or whatever.  (But using or instead of ||).  Nope, that doesn't work.  goto is a statement like if and can't be a sub-component of an expression like it can in Perl.  Otherwise we could have used it to remove the ( and ) characters.
We could trade f for g with if(stuff) goto label; instead of for, and both loops always run at least 1 iteration so we'd only need one loop-branch at the bottom, like a normal asm do{}while loop structure.  Assuming the user inputs an integer > 0...

Digraphs and Trigraphs
Fortunately, trigraphs have been removed as of ISO C++17 so we don't have to use ??> instead of } if we're unique-golfing for the most recent C++ revision.
But only trigraphs specifically: ISO C++17 still has digraphs like :> for ] and %> for }.  So at the cost of using %, we can avoid both  { and }, and use %: for # for a net saving of 2 fewer unique characters.
And C++ has operator keywords like not for the ! operator, or bitor for the | operator.  With xor_eq for ^=, you could zero a variable with i xor_eq i, but it has multiple characters you weren't using.
Current g++ already ignores trigraphs by default even without -std=gnu++17; you have to use -trigraphs to enable them, or -std=c++11 or something for strict conformance to an ISO standard that does include them.
23 unique bytes:
%:include<iostream>

int main() <%
    int n;
    std::cin >> n;

    for(int r<% %>; r < n;) <%
        ++r;
        for(int i<%%>; i < r;) <%
            ++i;
            std::cout << i << ' ';
        %>
        std::cout << std::endl;
    %>
%>

Try it online!
The final version uses a ' single-quote instead of h or " for the space separator.  I didn't want to digraph the char c{} stuff so I deleted it.  Printing a char is more efficient than printing a string, so I used that.
Histogram:
$ sed 's/\(.\)/\1\n/g' ladder-nocomments.cpp | sort | uniq -ic  | tee /dev/tty | wc -l
     15         // newline
     95         // space
     11 %
      2 '
      3 (
      3 )
      4 +
      9 :
     10 ;
     14 <
      8 >
      2 a
      4 c
      6 d
      3 e
      2 f
     12 i
      2 l
      2 m
     11 n
      5 o
      7 r
      5 s
     11 t
      3 u
25   // total lines, including space and newline

The space separator (still unsolved)
In a now-deleted answer, Johan Du Toit proposed using an alternate separator, specifically std::ends.  That's a NUL character, char(0), and prints as zero-width on most terminals.  So the output would look like 1234, not 1 2 3 4.  Or worse, separated by garbage on anything that didn't silently collapse '\0'.
If you can use an arbitrary separator, when the digit 0 is easy to create with cout << some_zeroed_var.  But nobody wants 10203040, that's even worse than no separator.
I was trying to think of a way to create a std::string holding a " " without using char or a string literal.  Maybe appending something to it?  Maybe with a digraph for [] to set the first byte to a value of 32, after creating one with length 1 via one of the constructors?
Johan also suggested the std::ios fill() member function which returns the current fill character.  The default for a stream is set by std::basic_ios::init(), and is ' '.
std::cout << i << std::cout.fill(); replaces << ' '; but uses . instead of '.
With -, we can take a pointer to cout and use ->fill() to call the member function:
std::cout << (bitand std::cout)->fill().  Or not, we weren't using b either so we might as well have used & instead of its lexical equivalent, bitand.
Calling a member function without . or ->
Put it inside a class, and define operator char() { fill(); }
// not digraphed
struct ss : std::ostream {  // default = private inheritance
//      ss() { init(); }  // ostream's constructor calls this for us
        operator char() { return fill(); }
}

Then ss s{} before the loop, and std::cout << i << s; inside the loop.  Great, it compiles and works properly, but we had to use p and h for operator char(), for a net loss of 1.
 At least we avoided b to make member functions public by using struct instead of class. (And we could override the inheritance with protected in case that ever helps).

@JohanduToit: good idea with cout.fill() from std::ios, but we weren't previously using .  Maybe we can call it somehow by taking a pointer and using ->fill() to a member function?  Does anything return a pointer to cout or any other stream?

Oops, << (bitand std::cout)->fill() compiles, but uses -.  (Despite the token name, bitand is just a lexical equivalent to &, not specifically the bitwise-and operator.  It also works as the address-of operator.)  Hmm, is there some template or lambda stuff that can get a pointer to a member function that we can () without using . or ->?

The only other thing that I found is that std::ios::left is defined as 32, in gcc, but I could not really figure out a way to take advantage of that. I think I’m going to let this one go and get some actual work done :-)

@JohanduToit: Creating an int 32 isn't a problem, my answer already shows how to do that with ++ starting from an int c{}; zero.  But yeah, I'm not going down the rabbit hole of looking into lambdas, templates, or std::function. Or the std::string idea.  But we're not using g to we can't actually declare a std::string without losing; my idea for using goto instead of for didn't pan out.  decltype(something) could give us a char type, but costs us a y.

You can use auto instead of char for the opeator:struct ss : std::ostream { operator auto () { return fill(); } }; but it doesn't help much.

@JohanduToit: oh crazy, I didn't know you could do operator auto.  That brings is back to break even, swapping ' for p.  I keep wondering about CPP macros, but the predefined ones are all upper-case and I assume this problem is case-sensitive.

Use #import instead of #include with the overloaded operator...

Ignore that, late night brain fart...

@JohanduToit: We could avoid l if we construct a char with value 10 instead of using std::endl for newline. (We know how to do that using h for char).  So the GCC extension import has possibilities...

Cool - I have decided to undelete my post. Please feel free to edit it if you want to.

How to not do it...

@rv7: Uh, thank you?  I wrote it all the text from scratch, summarizing my own thoughts.  I don't have the patience to organize my thoughts into an actual book, though :/  The 23-unique-byte code is there in the last section, with a TIO link.  Maybe you missed it.

C++ (gcc) x86_64 Linux only, 9295 8900 8712 6812 5590 5218 bytes, 18 unique characters
int m[]={11111111111111111+1111111111111111+1111111111111+1111111111111+111111111+111111111+11111111+11111111+11111111+111111+11+11+11+11+11+11+11+1+1,11111111111+11111111111+11111111111+1111111111+111111111+111111111+111111111+111111+1111+1111+111+111+111+111+11+11+11+11+11+11+11+11+11+1+1+1,111111111111111111+11111111111111+11111111111+111111111+11111111+11111111+111111+111111+111111+111111+1111+111+111+111+111+111,111111111111111+111111111111111+111111111111111+111111111111111+11111111111111+111111111111+111111111+11111111+11111111+11111+1111+1111+111+111+11+11+1+1+1+1,11111111111111111+1111111111111111+1111111111111111+1111111111111111+111111111+111111111+11111111+111111+11111+11111+11111+1111+1111+1111+11+11+11+11+11+11+11,1111111111111111+111111111111111+111111111111+11111111111+1111111111+1111111111+11111111+111111+111111+11111+11+11+11+1+1+1+1+1+1+1+1,11111111111111111+1111111111111111+11111111111+11111111111+11111111+11111111+11111111+1111+1111+11+11+11+11+11+11+11+11+11+1+1+1,111111111111+11111111111+1111111111+1111111111+1111111111+1111111111+1111111111+1111111111+11111111+11111+11111+11111+11111+11111+11111+1+1,111111111111111+11111111111111+11111111111+11111111111+1111111111+1111111+1111111+11111+111+111+111+111+111+111+111+111+11+11+1+1+1+1+1+1,11111111111+1111111111+111111111+11111111+11111111+1111111+1111111+1111111+1111111+1111111+1111111+1111111+111111+11+1+1+1+1+1+1+1,111111111111111111+1111111111111111+1111111111111111+111111111111111+111111111+11111111+11111+11111+11111+11111+11111+11111+111+111+111+111+111+111+11+11+1+1+1,11==1,1111111111+11111111+11111111+11111111+1111111+1111111+1111111+1111111+1111111+1111+1111+1111+1111+1111+1111+1111+1111+1111+111+111+111+11+11+11+1+1+1,1111111111111+111111111111+11111111111+1111111111+111111111+111111111+11111111+111111+111111+111111+11111+1111+111+111+1+1,111111111111+111111111111+11111111111+11111111111+11111111111+11111111111+111111111+111111111+11111111+111111+1111+1111+111+111+111,111111111111+11111111111+1111111111+1111111111+111111111+1111111+111+111+1+1+1+1,11111111111111111+1111111111111111+1111111111111111+1111111111+1111111111+111111111+1111111+1111111+1111111+1111111+1111111+1111+1111+1111+111+111+11+1+1+1+1+1,111111111111111+1111111111111+1111111111111+11111111111+1111111111+11111111+11111111+1111+1111+1111+111+111+111+111+11+11,111111111+111111111+11111111+11111111+11111111+1111111+1111111+111111+11111+1111+1111+1111+1111+111+111+11+11+11+11+11+1+1+1+1+1+1+1+1,11111111111111+111111111111+111111111111+11111111111+111111111+111111+111111+111111+1111+1111+1111+1+1+1+1+1+1+1+1,111111111111111111+1111111111111+1111111111111+111111111111+111111111+111111111+111111111+11111111+1111111+111111+111+11+11+11+11+1+1+1,11111111111111111+111111111111111+1111111111+111111111+111111111+11111111+1111+1111+1111+111+111+111+11+11+11+11+11+11+11+11+11+11,111111111111111+1111111111111+1111111111+111111111+11111111+1111111+1111111+111111+11111+11111+11111+1111+111+111+111+111+11+11+11+1+1+1+1+1,1111111111111111+111111111111111+111111111111111+11111111+11111111+1111111+1111111+1111111+1111+1111+1111+1111+1111+111+11+11+11+1+1+1+1+1+1+1+1+1+1,111111111111111+1111111111111+111111111111+111111111111+111111111111+11111111111+1111111111+1111111111+111111111+111111+111111+111111+111111+1111+11+1+1,111111111111111+11111111111111+111111111111+111111111111+1111111111+1111111111+111111111+11111111+1111+1111+1111+111+111+111+111+111+11+11+11+11+11+11+11+11+1+1+1+1,11111111111111111+1111111111111111+11111111111+11111111+1111111+1111111+111111+11111+11111+1111+1111+111+111+111+111+111+111+111+111+11+11+1+1+1+1+1+1+1+1,11111111111111111+11111111111111+1111111111+1111111+111111+11111+11111+11111+1111+111+111+111+111+111+111+11+11+11+11+11+11+11+11+11,11111111111111111+1111111111111+1111111111111+1111111111111+1111111111+1111111+11111+11111+11111+1111+111+111+111+1+1+1+1+1+1+1,1111111111111+1111111111+11111111+11111111+11111111+11111+1111+111+111+11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1+1,1111111111111111+11111111111+11111111111+11111111111+111111111+111111111+111111111+11111+11111+11111+11111+11111+11111+11111+11111+11111+111+111+11,11111111111111+1111111111+1111111+1111111+1111111+1111111+1111111+1111111+1111111+111111+111111+11111+1111+1111+111+111+111+111+111+111+1+1+1+1+1+1,111111111111111+1111111111111+111111111+111111111+111111111+111111111+11111111+11111111+11111111+11111111+1111111+111111+11111+11111+11111+1111+111+111+111+11+11+11+11+11,1111111111+111111111+1111111+1111111+111111+111111+11111+11111+11111+11111+11111+11111+1111+1111+1111+11+11+11+11+11+11+11+11+11+1+1+1,11111111111111111+11111111111111111+1111111111111111+1111111111111111+1111111111111+11111111111+111111111+111111+111111+111111+1+1+1+1+1+1+1,1111111111+111111111+111111111+11111111+1111111+1111111+1111111+111111+11111+11111+11111+11111+11111+111+111+111+11+11+11+1,111111111111111111+11111111111111111+111111111111111+111111111111111+111111111111111+11111111111+11111111111+11111111+11111+11111+11111+11111+11111+11+11+11+1+1+1,111111111111+11111111111+1111111111+111111111+111111111+111111+111111+111111+111111+11111+11111+11+11+11+11+11+1,111111111+11111+11111+111+11+1+1+1+1+1+1+1+1+1};main(){((int(*)())m)();}

Try it online!
This uses the character set  ()*+,1;=[]aimnt{} and is based on ideas from this CGCC answer. A machine language program is expressed as an array of 32 bit ints, each of which is represented as a sum of 1+11+111.... It turns out that it may be more efficient to encode x as y such that y%(1<<32)==x. The encoded machine language program is the following
0x0000000000000000:  55                         push    rbp
0x0000000000000001:  31 ED                      xor     ebp, ebp
0x0000000000000003:  53                         push    rbx
0x0000000000000004:  48 83 EC 18                sub     rsp, 0x18
0x0000000000000008:  48 8D 74 24 0C             lea     rsi, [rsp + 0xc]
0x000000000000000d:  31 C0                      xor     eax, eax
0x000000000000000f:  31 FF                      xor     edi, edi
0x0000000000000011:  6A 01                      push    1
0x0000000000000013:  5A                         pop     rdx
0x0000000000000014:  0F 05                      syscall
0x0000000000000016:  89 C3                      mov     ebx, eax
0x0000000000000018:  85 C0                      test    eax, eax
0x000000000000001a:  74 0C                      je      0x28
0x000000000000001c:  6B ED 0A                   imul    ebp, ebp, 0xa
0x000000000000001f:  03 6C 24 0C                add     ebp, dword ptr [rsp + 0xc]
0x0000000000000023:  83 ED 30                   sub     ebp, 0x30
0x0000000000000026:  EB E0                      jmp     8
0x0000000000000028:  C7 44 24 0C 00 00 00 00    mov     dword ptr [rsp + 0xc], 0
0x0000000000000030:  FF C3                      inc     ebx
0x0000000000000032:  8B 44 24 0C                mov     eax, dword ptr [rsp + 0xc]
0x0000000000000036:  8D 78 01                   lea     edi, [rax + 1]
0x0000000000000039:  89 7C 24 0C                mov     dword ptr [rsp + 0xc], edi
0x000000000000003d:  E8 27 00 00 00             call    0x69
0x0000000000000042:  6A 20                      push    0x20
0x0000000000000044:  48 89 E6                   mov     rsi, rsp
0x0000000000000047:  52                         push    rdx
0x0000000000000048:  58                         pop     rax
0x0000000000000049:  50                         push    rax
0x000000000000004a:  5F                         pop     rdi
0x000000000000004b:  0F 05                      syscall
0x000000000000004d:  5E                         pop     rsi
0x000000000000004e:  39 5C 24 0C                cmp     dword ptr [rsp + 0xc], ebx
0x0000000000000052:  7C DE                      jl      0x32
0x0000000000000054:  6A 0A                      push    0xa
0x0000000000000056:  48 89 E6                   mov     rsi, rsp
0x0000000000000059:  52                         push    rdx
0x000000000000005a:  58                         pop     rax
0x000000000000005b:  0F 05                      syscall
0x000000000000005d:  5E                         pop     rsi
0x000000000000005e:  39 DD                      cmp     ebp, ebx
0x0000000000000060:  7F C6                      jg      0x28
0x0000000000000062:  48 83 C4 18                add     rsp, 0x18
0x0000000000000066:  5B                         pop     rbx
0x0000000000000067:  5D                         pop     rbp
0x0000000000000068:  C3                         ret
0x0000000000000069:  85 FF                      test    edi, edi
0x000000000000006b:  74 2C                      je      0x99
0x000000000000006d:  89 F8                      mov     eax, edi
0x000000000000006f:  6A 0A                      push    0xa
0x0000000000000071:  59                         pop     rcx
0x0000000000000072:  48 83 EC 18                sub     rsp, 0x18
0x0000000000000076:  99                         cdq
0x0000000000000077:  F7 F9                      idiv    ecx
0x0000000000000079:  89 C7                      mov     edi, eax
0x000000000000007b:  8D 42 30                   lea     eax, [rdx + 0x30]
0x000000000000007e:  89 44 24 0C                mov     dword ptr [rsp + 0xc], eax
0x0000000000000082:  E8 E2 FF FF FF             call    0x69
0x0000000000000087:  48 8D 74 24 0C             lea     rsi, [rsp + 0xc]
0x000000000000008c:  6A 01                      push    1
0x000000000000008e:  58                         pop     rax
0x000000000000008f:  50                         push    rax
0x0000000000000090:  5F                         pop     rdi
0x0000000000000091:  50                         push    rax
0x0000000000000092:  5A                         pop     rdx
0x0000000000000093:  0F 05                      syscall
0x0000000000000095:  48 83 C4 18                add     rsp, 0x18
0x0000000000000099:  C3                         ret

...which is based on the following C code.
void print(int x){
  if( x ) {
    int y=x%10+'0';
    print(x/10);
    write(1,&y,1);
  }
}
void f() {
  int i=0,j=0,k;
  for( ;read(0,&k,1);i=i*10+k-'0' );
  do {
    for( j++,k=0; print( ++k ), write(1," ",1), k<j; );
    write(1,"\n",1);
  } while(j<i );
}

Edit: Now accepts input from stdin instead of argv[1]. Thanks to @ASCII-only and @PeterCordes for their suggestions!
Edit4: Slightly Significantly improved encoding.

-w flag pls :P (also you can rename ii to a)

You need gcc -zexecstack for this, right?  Because int m[] is not const.  (And recent toolchains put .rodata in a non-executable page anyway so even const int m[] doesn't work on e.g. my Arch Linux system with gcc 8.2.1 20181127 and ld (GNU Binutils) 2.31.1.)  Anyway, you forgot to mention that in your answer, but it's in your TIO link.

BTW, the OP's unique-count scoring algorithm doesn't count space and newline, so you don't have to make the whole thing terrible to read, just the array :P

You can save machine-code bytes by copying the 1 with push %rax / pop %rdi instead of another push-immediate.  Or more simply, for values that aren't 64-bit, i.e. non-pointers, 2-byte mov %eax, %edi.  Also, Linux syscall doesn't destroy its input registers, only rax with the return value and RCX+R11 with saved RIP and RFLAGS as part of how the syscall instruction works. So you can leave rdi and rdx set to 1 across calls, and use different regs. Also, RBX is call-preserved, so it's not really save to clobber main's RBX. It happens to work because CRT start code doesn't care.

21 unique characters + 1 unremovable newline
%:include<iostream>
int(n)(int(i))<%
    if(--i)if(n(i))<%%>
    if(i)if(std::cout<<i<<std::addressof(std::cout)->fill())<%%>
%>
int(l)(int(i))<%
    if(n(-(--i)))<%%>
%>
int(m)(int(i))<%
    if(--i)if(m(i))<%%>
    if(i)if(l(-i))<%%>
    if(i)if(std::cout<<std::endl)<%%>
%>
int(c)(int(i))<%
    if(m(-(--i)))<%%>
%>
int(main)(int(i))<%
    if(std::cin>>i)<%%>
    if(c(-i))<%%>
%>

Whitespaces aren't required except for the first newline. Compiled in g++ 7.3.0.
Used characters: %:include<ostram>()f-.
Improvements to other answers:

Removed semicolons by changing for loops to if and recursion.
Got the space character by std::addressof(std::cout)->fill(), aka std::cout.fill().

std::addressof,nice!

21 20 unique characters excluding whitespaces
All whitespaces could be changed into newlines.
%:include<iostream>
%:include<list>
int n;
const int co<%%>;
const int ci<%not co%>;
const int cmu<%-ci-ci-ci-ci%>;
const char ctd<%-cmu-cmu-cmu-cmu-cmu-cmu-cmu-cmu%>;
const int cia<%-ctd-ctd-ctd-ctd-ctd-cmu%>;
const int ciu<%cia- -ci- -ci%>;

struct<%struct<%struct<%struct<%struct<%struct<%struct<%
int c<:ctd-ci:>;
%>d<:ctd:>;int c<:ctd-ci:>;%>d<:ctd:>;int c<:ctd-ci:>;
%>d<:ctd:>;int c<:ctd-ci:>;%>d<:ctd:>;int c<:ctd-ci:>;
%>d<:ctd:>;int c<:ctd-ci:>;%>d<:-cmu:>;int c<:-ci-cmu:>;
%>e<:co:><:ctd:><:ctd:><:ctd:><:ctd:><:ctd:><:ctd:>;

int i<:co:>;
auto ia<%e%>;
auto iu<%e%>;
int l<%std::cin>>n and co%>;

struct s<%
    int c<%std::cout<<i<:ciu:>- --i<:cia:><<ctd and n%>;
%>;
struct o<%
    int c<%--ia and n%>;
%>;
struct t<%
    std::list<s>c<%- --l%>;
    std::list<o>r<%-l%>;
    int m<%std::cout<<std::endl and n%>;
%>;
std::list<t>a<%n%>;
int main;

Exits with segfault. Used characters: %:include<ostram>;-h.
It works in this specific compiler version on a 64 bit Linux:
g++-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010

With the parameter:
-std=c++17

Even then, I'm not sure it would always work. It may also depends on a lot of other things. cia and ciu are the memory offsets divided by 4 between ia iu and i. (int is 32 bit in this version.) You may have to change the numbers to match the actual offset. The addresses would be much more predictable if they are all contained in a struct. Unfortunately non-static auto isn't allowed in a struct.
e is a 0-elements array of an element type with a size of (232-1) ×232 bytes. If the corresponding pointer type of e is decremented, the higher half of the pointer would be decremented by (232-1), which is equivalent to incrementing by one. This could reset the decremented counter without using the equality sign.
A more reasonable version that should work more reliably, but uses one more character =:
%:include<iostream>
%:include<list>
int n;
int ci<%not n%>;
int cmu<%-ci-ci-ci-ci%>;
char ctd<%-cmu-cmu-cmu-cmu-cmu-cmu-cmu-cmu%>;
int i;
int l<%std::cin>>n and n-n%>;

struct s<%
    int c<%std::cout<<- --i<<ctd and n%>;
%>;
struct t<%
    std::list<s>c<%- --l%>;
    int r<%i=n-n%>;
    int m<%std::cout<<std::endl and n%>;
%>;
std::list<t>a<%n%>;
int main;

Even this doesn't work in the latest version of g++ because it doesn't seem to allow defining main in an arbitrary type anymore.
These two programs don't use parentheses. But then semicolons don't seem to be avoidable.

22 Unique characters excluding whitespaces. Separates the numbers with a NUL character which displays correctly on Windows.
%:include<iostream>
int main(int n)<%
    std::cin>>n;
    for(int r<%%>;r++<n;)<%
        for(int i<%%>;i<r;)
            std::cout<<++i<<std::ends;
        std::cout<<std::endl;
    %>
%>

Try it online
Histogram:
[%] 0x25 = 9
[:] 0x3A = 11
[)] 0x29 = 3
[i] 0x69 = 11
[n] 0x6E = 12
[c] 0x63 = 4
[l] 0x6C = 2
[u] 0x75 = 3
[d] 0x64 = 8
[e] 0x65 = 4
[<] 0x3C = 13
[o] 0x6F = 5
[s] 0x73 = 7
[t] 0x74 = 12
[r] 0x72 = 6
[a] 0x61 = 2
[m] 0x6D = 2
[>] 0x3E = 7
[(] 0x28 = 3
[;] 0x3B = 7
[f] 0x66 = 2
[+] 0x2B = 4
Unique Characters: 22
Total Characters: 189

std::ends is a NUL character (char(0)), not a space (char(32) in ASCII / UTF-8).  https://en.cppreference.com/w/cpp/io/manip/ends.  I tried it on my Linux desktop just to make sure, and the output looks like 1234, not 1 2 3 4.  It looks the same way on your TIO output!

@PeterCordes, the OP does not specify how the numbers should be separated ;-)

Do you really think they would have wasted a character on " for " " if they could have used iiii to separate with '0' for 10203040?  I guess you can make a case that there is a separator still in the binary output of the program, but pointing out this change and describing it in English is important for your answer, because this is not a drop-in replacement!  I'd be happy to remove my downvote if you expand your answer to explain and justify that.

@PeterCordes, Point taken.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Ambassadors and Translators
Two ambassadors at a UN conference want to speak to each other, but unfortunately each one only speaks one language- and they're not the same language. Fortunately, they have access to several translators, who each understand and speak a few languages. Your task is to determine the shortest chain of translators (since you want as little to be lost in translation as possible) that allows the two ambassadors to speak with each other.
Coding
Input: two languages as 2-letter lowercase strings (each ambassador's language) and a list of lists of languages (one list per available translator)
You may alternatively take in integers instead of 2-letter codes.
Output: A sequence of translators either by index or value that is any one of the shortest chains of translators that allows the two ambassadors to communicate. If there is no valid chain of translators, the behavior is undefined. (You may crash, output any arbitrary value, or indicate an error)
A valid chain of translators is one where the first translator speaks one ambassador's language, the second and subsequent translators share at least one language with the previous translator, and the last translator speaks the other ambassador's language.
Examples
Using zero-based indexing:
es, en, [
    [es, en]
] ==> [0]

en, en, [] ==> []

en, jp, [
    [en, zh, ko, de],
    [jp, ko]
] ==> [0, 1]

es, ru, [
    [gu, en, py],
    [po, py, ru],
    [po, es]
] ==> [2, 1]

fr, gu, [
    [it, fr, de, es, po, jp],
    [en, ru, zh, ko],
    [jp, th, en],
    [th, gu]
] ==> [0, 2, 3]

fr, ru, [
    [fr, en],
    [en, ko, jp],
    [en, ru]
] ==> [0, 2]

de, jp, [
    [en, fr],
    [ko, jp, zh],
    [fr, po],
    [es, ko, zh],
    [de, en, th],
    [en, es],
    [de, fr]
] ==> [4, 5, 3, 1]

Rules and Assumptions

Standard IO rules (use any convenient I/O format) and banned loopholes apply.
You may assume that speaking and understanding languages is perfectly symmetric and that all possible translations between languages are equally efficient.
There is no concept of "close enough" languages. It is not good enough to use Portuguese on one end where Spanish is required, for instance.
If there are multiple shortest translator chains, any one of them will do.
If the ambassadors happen to speak the same language, the translator list should be empty
Which of the ambassadors is the first one doesn't matter; the translator list can be forward or reverse.
Ambassadors only speak one language for the sake of this challenge
Translators speak at least two languages
The 2-letter language codes do not need to correspond with real languages
You may assume there is a valid sequence of translators
If outputting the sequence by value, include the full set of available languages, not just the relevant ones.

Happy Golfing!

Why the I/O restriction to two-character strings, wouldn't integers do just as well?

can the list of list of translators be in csv form like: en,fr,sp;en,gr;gr,fr

@Quinn standard IO rules say yes.

Can the ambassadors be included in the output at the beginning and end?

@NickKennedy I'm gonna say no on that one.

^ To expand on my above comment, the reason why is to maintain consistency whether you return "by index" or "by value"

Minor point, but one of your rules contradicts the ‘not the same language’ bit of the intro.

Jelly, 19 17 bytes
ŒPŒ!€Ẏj@€fƝẠ$ƇḢḊṖ

Try it online!
A dyadic link taking the list of translators as the left argument and list of ambassadors (each double-wrapped in a list) as the right argument. Returns a list of translators, each of which is a list of the languages they speak.
Thanks to @KevinCruijssen for saving 2 bytes!
Explanation
ŒPŒ!€Ẏj@€fƝẠ$ƇḢḊṖ | A dyadic link taking a list of translators as left argument and a list of ambassadors (double-wrapped in lists) as right argument

ŒP                | Power set of translators
  Œ!€             | Permutations of each
     Ẏ            | Tighten, i.e. create a single list of all permutations of any length
      j@€         | Join the ambassadors with each set of translators
            $Ƈ    | Filter those where:
           Ạ      |   all
         fƝ       |   the neighbouring pairs have at least one in common
              Ḣ   | Take the first
               Ḋ  | Drop the first ambassador from the start
                Ṗ | Drop the second ambassador from the end

You can save 2 bytes by removing the sort by length LÞ, since the powerset + permurations already results in a list sorted by length.

@KevinCruijssen thanks, good point!

Python 2, 138 126 120 117 113 bytes
F=lambda a,b,T,*U:a!=b and min([[t]+F(l,b,T,t,*U)for t in T if(t in U)<(a in t)for l in t-{a}]+[2*T],key=len)or[]

Try it online!
3 bytes thx to ArBo
Returns a minimal length list of the translators as sets of languages, i.e. 'by value', from T that allow a to talk to b.

if t not in U and a in t can be changed to if(a in t)>U.count(t) to save 4 bytes.

@mypetition - I had a similar thought and squeezed out another 2.

117 by using *args notation

@ArBo: Nice; thx for 3 bytes.

05AB1E, 18 17 bytes
æ€œ€`ʒ²š³ªüå€àP}н

Inspired by @NickKennedy's Jelly answer, so make sure to upvote him!
Outputs the lists themselves instead of their indices.
Try it online or verify all test cases.
Explanation:
æ                # Get the powerset of the (implicit) input-list of translators
                 #  i.e. [["ef","gh","bc"],["bc","ab"],["ef","cd","de"]]
                 #   → [[],[["ef","gh","bc"]],[["bc","ab"]],[["ef","gh","bc"],["bc","ab"]],[["ef","cd","de"]],[["ef","gh","bc"],["ef","cd","de"]],[["bc","ab"],["ef","cd","de"]],[["ef","gh","bc"],["bc","ab"],["ef","cd","de"]]]
 €œ              # Get the permutations of each
                 #  → [[[]],[[["ef","gh","bc"]]],[[["bc","ab"]]],[[["ef","gh","bc"],["bc","ab"]],[["bc","ab"],["ef","gh","bc"]]],[[["ef","cd","de"]]],[[["ef","gh","bc"],["ef","cd","de"]],[["ef","cd","de"],["ef","gh","bc"]]],[[["bc","ab"],["ef","cd","de"]],[["ef","cd","de"],["bc","ab"]]],[[["ef","gh","bc"],["bc","ab"],["ef","cd","de"]],[["ef","gh","bc"],["ef","cd","de"],["bc","ab"]],[["bc","ab"],["ef","gh","bc"],["ef","cd","de"]],[["bc","ab"],["ef","cd","de"],["ef","gh","bc"]],[["ef","cd","de"],["ef","gh","bc"],["bc","ab"]],[["ef","cd","de"],["bc","ab"],["ef","gh","bc"]]]]
   €`            # Flatten each one level down (4D list becomes 3D list)
                 #  → [[],[["ef","gh","bc"]],[["bc","ab"]],[["bc","ab"],["ef","gh","bc"]],[["ef","gh","bc"],["bc","ab"]],[["ef","cd","de"]],[["ef","cd","de"],["ef","gh","bc"]],[["ef","gh","bc"],["ef","cd","de"]],[["ef","cd","de"],["bc","ab"]],[["bc","ab"],["ef","cd","de"]],[["ef","cd","de"],["bc","ab"],["ef","gh","bc"]],[["ef","cd","de"],["ef","gh","bc"],["bc","ab"]],[["bc","ab"],["ef","cd","de"],["ef","gh","bc"]],[["bc","ab"],["ef","gh","bc"],["ef","cd","de"]],[["ef","gh","bc"],["ef","cd","de"],["bc","ab"]],[["ef","gh","bc"],["bc","ab"],["ef","cd","de"]]]
     ʒ           # Filter this 3D list by:
      ²š         #  Prepend the second input ambassador
                 #   i.e. [["bc","ab"],["ef","gh","bc"]] and "ab"
                 #    → ["ab",["bc","ab"],["ef","gh","bc"]]
        ³ª       #  Append the third input ambassador
                 #   i.e. ["ab",["bc","ab"],["ef","gh","bc"]] and "ef"
                 #    → ["ab",["bc","ab"],["ef","gh","bc"],"ef"]
          ü      #  For each adjacent pair of translator-lists:
           å     #   Check for each item in the second list, if it's in the first list
                 #    i.e. ["bc","ab"] and ["ef","gh","bc"] → [0,0,1]
            €à   #   Then check if any are truthy by leaving the maximum
                 #    → 1
              P  #  And then take the product to check if it's truthy for all pairs
                 #   i.e. ["ab",["bc","ab"],["ef","gh","bc"],"ef"] → [1,1,1] → 1
     }н          # After the filter: only leave the first list of translator-lists
                 #  i.e. [[["bc","ab"],["ef","gh","bc"]],[["bc","ab"],["ef","gh","bc"],["ef","cd","de"]]]
                 #   → [["bc","ab"],["ef","gh","bc"]]
                 # (which is output implicitly as result)

JavaScript (ES6),  123  121 bytes
Expects integers instead of 2-letter codes.
(a,b,l)=>((B=g=(m,s,i)=>m>>b&1?B<i||(o=s,B=i):l.map(a=>a.map(M=c=>M|=1<<c)|M&m&&m^(M|=m)&&g(M,[...s,a],-~i)))(1<<a,[]),o)

Try it online!

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Golf my Ada arrays
Background
Ada is a programming language that is not exactly known for its terseness.
However, its array literal syntax can in theory allow for fairly terse array
specifications. Here is a simple EBNF description of the array literal
syntax (passable to bottlecaps.de:
array ::= positional_array | named_array
positional_array ::= expression ',' expression (',' expression)*
                   | expression (',' expression)* ',' 'others' '=>' expression
named_array ::= component_association (',' component_association)*
component_association ::= discrete_choice_list '=>' expression
discrete_choice_list ::= discrete_choice ('|' discrete_choice)*
discrete_choice ::= expression ('..' expression)? | 'others'

We will limit ourselves to 1-dimensional arrays of integers for simplicity. This
means that we will use only integers for the expression values. Perhaps in
a future challenge we could try something more advanced (like declaring
variables and multidimensional arrays). You do not have to golf the integer
literals.
Here are some examples of Ada array literals and a python-esque equivalent representation for clarity:
(1, 2, 3) = [1, 2, 3]
(1, others => 2) = [1, 2, 2, ..., 2]
(others => 1) = [1, 1, ..., 1]
(1 => 1, 2 => 3) = [1, 3]
(1|2 => 1, 3 => 2) = [1, 1, 2]
(1 => 1, 3 => 2, others => 3) = [1, 3, 2, 3, 3, ..., 3]

Challenge
The goal of this challenge is to output the shortest byte-count Ada array
literal for a given input array. Note that Ada arrays can start from whatever
index is desired, so you can pick what you wish the starting index to be as long
as each value is sequential. In this example I choose to start at 1, which is
idiomatic for Ada, however you can choose to start at any other integer.
Input
Your input will consist of a list of integers, in whatever form is convenient.
Output
Your output will be a string of text representing the shortest valid Ada array literal that represents the list of input integers. You may use any starting index you wish on this array, but your choice (whatever it is) must be specified in your answer (the starting index may also be dynamic).
The integers are to represented as signed decimal numbers, as in the examples. This challenge does not cover golfing of integer values.
Examples
Here are some examples:
Simple: [1, 2, 3] -> (1,2,3)
Range: [1, 1, 1, 1, 1, 1, 1,] -> (1..7=>1)
Others: [1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1] -> (6=>2,others=>1)
Multiple Ranges: [1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1] -> (6..10|16..20=>2,others=>1)
Tiny Ranges: [1,1,2,2,1,1,1,1,1] -> (3|4=>2,others=>1)
Far Range: [[1]*5, [2]*100, [3]*5] -> (1..5=>1,6..105=>2,others=>3)
Alternation: [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2] -> (1|3|5|7|9|11|13|15|17=>1,others=>2)
Big Number: [1234567890,1,1234567890] -> (2=>1,1|3=>1234567890)
Big-ish Number: [1234567,1,1234567] -> (1234567,1,1234567)
Solo: [-1] -> (1=>-1)
Huge Input: [[0],[1]*1000000000] -> (0,others=>1)
Positional Others: [1, 2, 3, 3, 3, 3, 3, 3] -> (1,2,others=>3)
Range and Choice, no Others: [1,1,1,12,12,3,3,3,3,3,3,3,3,3,3,4] -> (1..3=>1,4|5=>12,6..15=>3,16=>4)

Minimum Requirements

Support at least 100 numbers and inputs of at least 256 numbers in length.
Produce the correct result for all such inputs

Includes putting 'others' at the end
Includes putting an index for single item arrays

Terminate (preferably on TIO) for each of the above inputs in under a minute.

Shortest solution in bytes wins!
Reference Implementation
Try it online!
This implementation uses the input as its array, with each character being
a number. Capital letters are special constants for large values. The program
argument is the 'start index' to use.
The "code" section in the TIO link is a correct solution to the problem, while the "header" and "footer" implement the test structure.

Does the "Far Range" case exist simply to indicate that we may take input in that format if we choose or to highlight that we have to be able to handle that input format as well as normal arrays? Also, shouldn't the last test case just output (-1)?

The "Far Range" case is merely written that way to save space, the actual input would be a flat array consisting of 110 integers, but the output is correct. Its purpose is to demonstrate cases where the 'others' keyword should go on a shorter range that has a longer representation. (106..110=>3,others=>2 would be longer) The last case needs to have an index, as the grammar doesn't allow single element positional arrays (positional_array ::= expression ',' expression (',' expression)*)

In theory, could (and should) a list of 100,000,000 $1$'s be encoded as (1=>1,others=>1) since it's shorter than (1..100000000=>1)?

@Arnauld very nice catch. I made a mistake in my grammar because its awkwardly hidden in the Ada specification. It should actually just be (others=>1) since others can be all alone (it counts as a discrete choice). I will update the question accordingly!

Could you please confirm that (1|3=>1234567,2=>1) is another valid output for [1234567,1,1234567]?

Are we allowed to use Ada as our language of choice?

Suggested test case: [1,1,1,12,12,3,3,3,3,3,3,3,3,3,3,4] (resulting in (1..3=>1,4|5=>12,6..15=>3,16=>4)); an output containing both .. and | at the same time.

@Arnauld Oops, I copied the wrong one.. But yes, I indeed meant that [1,2,3,3,3,3,3,3] now fails in the reference implementation (results in (1,2,3,3,3,3,3,3) instead of the shortest (1,2,others=>3))

@Arnauld and @Kevin Cruijssen you are correct, [1,2,3,3,3,3,3,3] should indeed be (1,2,others=>3) I will add both test cases and update my reference implementation shortly.

JavaScript (ES6),  307  304 bytes
Saved 2 bytes thanks to @KevinCruijssen
This is embarrassingly long ...
a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>j-k|!m[6]?o[k]+'=>'+k:O,O='others=>'+j).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+[,O]].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!

305 bytes (-2) by creating a variable for the duplicated 'others=>'.

@KevinCruijssen Thanks! (NB: In your version, t is used before it's defined; the reason why it doesn't crash is that the first 2 test cases don't use it at all; that can be easily fixed at no cost, though.)

Ah ok. I didn't really ungolf your answer to see what was used where. I simply noticed you had 'others' two times and tried to create a variable for it without changing the output. ;) Thanks for explaining it though, and nice golf of the comma by using [,O]. :)

05AB1E, 136 134 132 bytes
"',ý'(ì')«ˆ"©.V"θ…ˆ†=>ìª®.V"Uγ¨D€gPi˜IX.V}\ÙεQƶ0KDāαγ€g£}D2Fε¾iεнyg≠iyθyg<i'|ë„..}ý}}ë˜}'|ý„=>«Iyнн<è«}Ð®.VgFDN._ć'>¡X.V}\¼}¯éIgi¦}н

EDIT: Fixed for all test cases now.
Try it online or verify all test cases (except for the 'Huge Input' one, since it's too big).
Explanation:
"',ý'(ì')«ˆ"       # Push this string (function 1), which does:
 ',ý              '#  Join a list by ","
    '(ì           '#  Prepend a "("
       ')«        '#  Append a ")"
          ˆ        #  Pop and add it to the global array
            ©      # Store this string in the register (without popping)
             .V    # And execute it as 05AB1E code on the (implicit) input-list
"θ…ˆ†=>ìª®.V"      # Push this string (function 2), which does:
 θ                 #  Pop and push the last element of the list
  …ˆ†=>ì           #  Prepend dictionary string "others=>"
        ª          #  Append that to the list which is at the top of the stack
         ®.V       #  And execute function 1 from the register
             U     # Pop and store this string in variable `X`
γ                  # Get the chunks of equal elements in the (implicit) input-list
 ¨                 # Remove the last chunk
  D                # Duplicate the list of remaining chunks
   €g              # Get the length of each
     Pi     }      # If all chunk-lengths are 1:
       ˜           #  Flatten the list of remaining chunks
        I          #  Push the input-list
         X.V       #  Execute function 2 from variable `X`
             \     # Discard the top of the stack (in case we didn't enter the if-statement)
Ù                  # Uniquify the (implicit) input-list
 ε                 # Map each unique value `y` to:
  Q                #  Check for each value in the (implicit) input-list if it's equal to `y`
                   #  (1 if truthy; 0 if falsey)
   ƶ               #  Multiply each by its 1-based index
    0K             #  Remove all 0s
      D            #  Duplicate it
       ā           #  Push a list [1, length] without popping the list itself
        α          #  Get the absolute difference at the same indices
         γ         #  Split it into chunks of the same values
          €g       #  Get the length of each
            £      #  And split the duplicated indices-list into those parts
                   # (this map basically groups 1-based indices per value.
                   #  i.e. input [1,1,2,1,1,2,2,1,1] becomes [[[1,2],[4,5],[8,9]],[[3],[6,7]]])
 }D                # After the map: duplicate the mapped 3D list
   2F              # Loop 2 times:
     ε             #  Map the 3D list of indices to:
      ¾i           #   If the counter_variable is 1:
        ε          #    Map each list `y` in the 2D inner list to:
         н         #     Leave the first value
         yg≠i      #     And if there is more than one index:
             yθ    #      Push the last value as well
             yg<i  #      If there are exactly two indices:
              '|  '#       Push string "|"
             ë     #      Else (there are more than two indices)
              „..  #       Push string ".."
             }ý    #      And join the first and last value by this string
        }}         #    Close the if-statement and map
      ë            #   Else:
       ˜           #    Flatten the 2D list
      }'|ý        '#   After the if-else: join by "|"
          „=>«     #   Append "=>"
       yнн         #   Get the very first index of this 2D list
          <        #   Decrease it by 1 to make it 0-based
      I    è       #   And index it into the input-list to get its value again
            «      #   Which is also appended after the "=>"
     }Ð            #  After the map: triplicate the result
       ®.V         #  Execute function 1 from the register
       g           #  Get the amount of items in the triplicated list
        F          #  Loop that many times:
         D         #   Duplicate the list
          N._      #   Rotate it the index amount of times
          ć        #   Extract the head; pop and push remainder and head
           '>¡    '#   Split this head by ">"
              X.V  #   And then function 2 is executed again from variable `X`
        }\         #  After the loop: discard the list that is still on the stack
          ¼        #  And increase the counter_variable by 1
   }¯              # After looping twice: push the global array
     é             # Sort it by length
      Igi }        # If the input only contained a single item:
         ¦         #  Remove the very first item
           н       # And then only leave the first item
                   # (which is output implicitly as result)

See this 05AB1E tip of mine (section How to compress strings not part of the dictionary?) to understand why …ˆ†=> is "others=>".


text:
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\$
Details

You may use 0 or 1 based indexing, whatever suits you best.
You can return the \$n\$-th prime given the index \$n\$ or the first \$n\$ primes in increasing order, or alternatively you can return an infinite list/generator that produces the primes in increasing order.

Test cases
The first few terms are following:
(#1-13)   7, 13, 19, 37, 61, 109, 127, 193, 271, 331, 397, 433, 547,
(#14-24) 631, 769, 919, 1201, 1453, 1657, 1801, 1951, 2029, 2269, 2437,
(#25-34) 2791, 3169, 3469, 3571, 3889, 4219, 4447, 4801, 5167, 5419,
(#35-43) 6211, 7057, 7351, 8269, 9241, 10093, 10267, 11719, 12097,
(#44-52) 12289, 13267, 13669, 13873, 16651, 18253, 19441, 19927, 20173

More terms can be found on OEIS: They are split up in two sequences, depending on wheter \$x = 1+y \$ or \$x = 2+y\$: A002407 and A002648

Can we return the first n primes not sorted?

@J42161217 No, the primes should be in increasing order.

JavaScript (V8), 54 bytes
A full program that prints cuban primes forever.
for(x=0;;){for(k=N=~(3/4*++x*x);N%++k;);~k||print(-N)}

Try it online!
NB: Unless you have infinite paper in your printer, do not attempt to run this in your browser console, where print() may have a different meaning.

JavaScript (ES6),  63 61 60  59 bytes
Returns the \$n\$-th cuban prime, 1-indexed.
f=(n,x)=>(p=k=>N%++k?p(k):n-=!~k)(N=~(3/4*x*x))?f(n,-~x):-N

Try it online!
How?
This is based on the fact that cuban primes are primes of the form:
$$p_n=\left\lfloor\frac{3n^2}{4}\right\rfloor+1,\;n\ge3$$
The above formula can be written as:
$$p_n=\begin{cases}
\dfrac{3n^2+1}{4}\;\text{ if }n\text{ is odd}\\
\dfrac{3n^2+4}{4}\;\text{ if }n\text{ is even}
\end{cases}
$$
or for any \$y>0\$:
$$p_{2y+1}=\dfrac{3(2y+1)^2+1}{4}=3y^2+3y+1$$
$$p_{2y+2}=\dfrac{3(2y+2)^2+4}{4}=3y^2+6y+4$$
which is \$\dfrac{x^3-y^3}{x-y}\$ for \$x=y+1\$ and \$x=y+2\$ respectively.

05AB1E, 16 12 9 bytes
Generates an infinite list.
Saved 4 bytes with Kevin Cruijssen's port of Arnaulds formula.
Saved another 3 bytes thanks to Grimy
∞n3*4÷>ʒp

Try it online!
Explanation
∞          # on the list of infinite positive integers
 n3*4÷>    # calculate (3*N^2)//4+1 for each
       ʒp  # and filter to only keep primes

You've made a typo in your explanation: "put a copy of N^2+3 on the stack" should be 3*N^2. Also, why the ) instead of ¯? Because it's easier to type? And for some reason I have the feeling the NnN‚3*¬sO‚ can be 1 byte shorter, but I'm not seeing it. A slight equal-byte alternative is Nn3*DN3*+‚. But I'm probably just seeing things that aren't there.. ;) Nice answer, so +1 from me.

Porting the formula in @Arnauld's answer is 12 bytes: [Nn3*4÷>Dpiˆ (PS: Your approach with Arnauld's formula is also 12 bytes, but way slower: )[Nn3*4÷>ªʒp.)

@KevinCruijssen: Yeah I tend to use ) partly because I can write it on my keyboard and I also keep forgetting I can use ¯. Thanks for the explanation correction and the golf :)

I actually tried to port my answer to 05AB1E, but failed miserably. :D

Generating an infinite list isn't required, the question allows you to simply return the n-th cuban prime (-2 bytes).

Actually, generating an infinite list is more convenient: 9 bytes with ∞n3*4÷>ʒp

@Grimy: Thanks! I really should have thought to use ∞ with the simplified formula.

@Grimy: generating an infinite list isn’t just not required, it violates the requirement to take n as input and output the nth item.

@WGroleau, you might want to throw another eye over the specs ;)

OK, I'm not used to specs that contradict themselves.   :-)

@WGroleau I assume you've never developed software professionally then. I'm more concerned when I get specs that don't contradict themselves.

Retired from that after nearly forty years.  Yeah, some of the three-hundred-page specs (that should have been fifty pages) did indeed have contradictions.  Those I wrote were less padded and more carefully proofread before release.

R, 75 73 bytes
n=scan()
while(F<n)F=F+any(!(((T<-T+1)*1:4-1)/3)^.5%%1)*all(T%%(3:T-1))
T

Try it online!
-2 bytes by noticing that I can remove brackets if I use * instead of & (different precedence).
Outputs the nth Cuban prime (1-indexed).
It uses the fact (given in OEIS) that Cuban primes are of the form \$p=1+3n^2\$ or \$4p=1+3n^2\$ for some \$n\$, i.e. \$n=\sqrt{\frac{a\cdot p-1}{3}}\$ is an integer for \$a=1\$ or \$a=4\$.
The trick is that no prime can be of the form \$2p=1+3n^2\$ or \$3p=1+3n^2\$ (*), so we can save 2 bytes by checking the formula for \$a\in\{1, 2, 3, 4\}\$ (1:4) instead of \$a\in\{1, 4\}\$ (c(1,4)).
Slightly ungolfed version of the code:
# F and T are implicitly initialized at 0 and 1
# F is number of Cuban primes found so far
# T is number currently being tested for being a Cuban prime
n = scan()                       # input
while(F<n){
  T = T+1                        # increment T
  F = F +                        # increment F if
    (!all(((T*1:4-1)/3)^.5 %% 1) # there is an integer of the form sqrt(((T*a)-1)/3)
     & all(T%%(3:T-1)))          # and T is prime (not divisible by any number between 2 and T-1)
  }
T                                # output T

(*) No prime can be of the form \$3p=1+3n^2\$, else \$1=3(p-n^2)\$ would be divisible by \$3\$.
No prime other than \$p=2\$ (which isn't a Cuban prime) can of the form \$2p=1+3n^2\$: \$n\$ would need to be odd, i.e. \$n=2k+1\$. Expanding gives \$2p=4+12k(k+1)\$, hence \$p=2+6k(k+1)\$ and \$p\$ would be even.

what about avoiding a loop by using an upper bound on the nth Cuban prime?

@Xi'an I thought about that, but couldn't come up with such a bound. Do you have one?

Wolfram Language (Mathematica), 66 65 56 bytes
(f=1+⌊3#/4#⌋&;For[n=i=0,i<#,PrimeQ@f@++n&&i++];f@n)&

Try it online!

J42161217 -1 by using ⌊ ⌋ instead of Floor[ ]
attinat

-1 by using ⌊3#/4#⌋ instead of ⌊3#^2/4⌋
-8 for For[n=i=0,i<#,PrimeQ@f@++n&&i++] instead of n=2;i=#;While[i>0,i-=Boole@PrimeQ@f@++n]

65 bytes. Welcome to ppcg. Nice first answer! +1

Thanks! (Long time lurker.) I couldn't quite parse your existing answer so I wrote my own and it came out a little shorter. I might do a Python one too.

56 bytes

@attinat I thought Arnauld's formula only worked for n>2 so I didn't start with 0 - although as in your example it works for all n (because it starts 1 1 4 7 13 ... so the primes are 7 13 ...)

Java 8, 94 88 86 84 bytes
v->{for(int i=3,n,x;;System.out.print(x<1?++n+" ":""))for(x=n=i*i++*3/4;~n%x--<0;);}

-6 bytes by using the Java prime-checker of @SaraJ, so make sure to upvote her!
-2 bytes thanks to @OlivierGrégoire. Since the first number we check is 7, we can drop the trailing %n from Sara's prime-checker, which is to terminate the loop for n=1.
-2 bytes thanks to @OlivierGrégoire by porting @Arnauld's answer.
Outputs space-delimited indefinitely.
Try it online.
Explanation (of the old 86 bytes version): TODO: Update explanation
Uses the formula of @Arnauld's JavaScript answer: \$p_n=\left\lfloor\frac{3n^2}{4}\right\rfloor+1,\;n\ge3\$.
v->{                     // Method with empty unused parameter and no return-type
  for(int i=3,           //  Loop-integer, starting at 3
          n,x            //  Temp integers
      ;                  //  Loop indefinitely:
      ;                  //    After every iteration:
       System.out.print( //     Print:
        n==x?            //      If `n` equals `x`, which means `n` is a prime:
         n+" "           //       Print `n` with a space delimiter
        :                //      Else:
         ""))            //       Print nothing
    for(n=i*i++*3/4+1,   //   Set `n` to `(3*i^2)//4+1
                         //   (and increase `i` by 1 afterwards with `i++`)
        x=1;             //   Set `x` to 1
        n%++x            //   Loop as long as `n` modulo `x+1`
                         //   (after we've first increased `x` by 1 with `++x`)
             >0;);}      //   is not 0 yet
                         //   (if `n` is equal to `x`, it means it's a prime)

I don't really think it's feasible, but another way of finding the cuban primes uses this formula: v->{for(int n=7,i=3,p,x,d,r=0;;i+=++r%2*3,n+=i,System.out.print(x>1?x+" ":""))for(x=n,d=1;++d<n;x=x%d<1?0:n);}, maybe someone can use this to golf? I couldn't.

@OlivierGrégoire You can golf yours a bit more by removing the unused ,p and changing i+=++r%2*3,n+=i to n+=i+=++r%2*3, but then I'll still end up at 106 bytes. Using Java 11's String#repeat with prime-regex is 105 bytes: v->{for(int n=7,i=3,r=0;;n+=i+=++r%2*3)if(!"x".repeat(n).matches(".?|(..+?)\\1+"))System.out.println(n);}.

Yeah, I guessed it wasn't much golfable despite my (now obvious) mistakes. Thanks for giving it a ride ;)

@OlivierGrégoire Maybe also good to know for you, but there is apparently a shorter prime-check loop in Java. See my edit and SaraJ's prime-check answer.

I might be wrong, but the last %n isn't required, is it?

@OlivierGrégoire Ah, in this case it's indeed not necessary, since we start at n=7. With a general prime check the trailing %n is still required for n=1 though, since 1%x for x>=2 will always result in 1. So without the trailing %n the loop won't terminate for n=1.

84 bytes, trying to use some of @Arnauld's techniques.

Wolfram Language (Mathematica), 83 bytes
(t=1;While[Length[l=Select[Join@@Array[{(v=3#^2+1)+3#,v}&,t++],PrimeQ]]<#];Sort@l)&

Try it online!

Jelly, 12 bytes
²×3:4‘
ÇẒ$#Ç

Try it online!
Based on @Arnauld’s method. Takes n on stdin and returns that many Cuban primes.

Wolfram Language (Mathematica), 83 bytes
This solution will output the n-th Cuban prime with the added benefits of being fast and remembering all previous results in the symbol f.
(d:=1+3y(c=1+y)+3b c;e:=If[PrimeQ@d,n++;f@n=d];For[n=y=b=0,n<#,e;b=1-b;e,y++];f@#)&

Try it online!

Python 3, 110 108 102 bytes
Similar method to my Mathematica answer (i.e. isPrime(1+⌊¾n²⌋) else n++)
 using this golfed prime checker and returning an anonymous infinite generator
from itertools import*
(x for x in map(lambda n:1+3*n**2//4,count(2)) if all(x%j for j in range(2,x)))

Try it online!

mypetlion -2 because arguably anonymous generators are more allowed than named ones
-6 by starting count at 2 +1 so that the and x>1 in the prime checker I borrowed is unnecessary -7

The answer going into a variable is usually not considered a valid form of "output". Could you rework your answer so that the result is either output to stdout or returned by a function?

since anonymous functions are allowed, and the challenge explicitly allows an infinite generator, I've removed g=. I had only included it in the first place because it allowed a quick visual on TIO with print(next(g) for i in range(52)).

Japt, 14 13 bytes
Adapted from Arnauld's formula. 1-indexed.
@µXj}f@Ò(X²*¾

Try it
1 byte saved thanks to EmbodimentOfIgnorance.

13 bytes? Not tested thoroughly though.

Thanks, @EmbodimentofIgnorance. I'd tried that but it didn't work; turns out I'd forgotten the (.

Racket, 124 bytes
(require math)(define(f n[i 3])(let([t(+(exact-floor(* 3/4 i i))1)][k(+ 1 i)])(if(prime? t)(if(= 0 n)t(f(- n 1)k))(f n k))))

Try it online!
Returns the n-th cuban prime, 0-indexed.
Uses the formula of @Arnauld's JavaScript answer

Whitespace, 180 bytes
[S S S T    S N
_Push_2][S N
S _Duplicate][N
S S N
_Create_Label_OUTER_LOOP][S N
N
_Discard_top_stack][S S S T N
_Push_1][T  S S S _Add][S N
S _Duplicate][S N
S _Duplicate][T S S N
_Multiply][S S S T  T   N
_Push_3][T  S S N
_Multiply][S S S T  S S N
_Push_4][T  S T S _Integer_divide][S S S T  N
_Push_1][T  S S S _Add][S S S T N
_Push_1][S N
S _Duplicate_1][N
S S S N
_Create_Label_INNER_LOOP][S N
N
_Discard_top_stack][S S S T N
_Push_1][T  S S S _Add][S N
S _Duplicate][S N
S _Duplicate][S T   S S T   T   N
_Copy_0-based_3rd][T    S S T   _Subtract][N
T   S T N
_Jump_to_Label_PRINT_if_0][S T  S S T   S N
_Copy_0-based_2nd][S N
T   _Swap_top_two][T    S T T   _Modulo][S N
S _Duplicate][N
T   S S S N
_Jump_to_Label_FALSE_if_0][N
S N
S N
_Jump_to_Label_INNER_LOOP][N
S S T   N
_Create_Label_PRINT][T  N
S T _Print_as_integer][S S S T  S T S N
_Push_10_(newline)][T   N
S S _Print_as_character][S N
S _Duplicate][N
S S S S N
_Create_Label_FALSE][S N
N
_Discard_top_stack][S N
N
_Discard_top_stack][N
S N
N
_Jump_to_Label_OUTER_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Outputs newline-delimited indefinitely.
Try it online (with raw spaces, tabs, and new-lines only).
Explanation in pseudo-code:
Port of my Java 8 answer, which also uses the formula from @Arnauld's JavaScript answer: \$p_n=\left\lfloor\frac{3n^2}{4}\right\rfloor+1,\;n\ge3\$.
Integer i = 2
Start OUTER_LOOP:
  i = i + 1
  Integer n = i*i*3//4+1
  Integer x = 1
  Start INNER_LOOP:
    x = x + 1
    If(x == n):
      Call function PRINT
    If(n % x == 0):
      Go to next iteration of OUTER_LOOP
    Go to next iteration of INNER_LOOP

function PRINT:
  Print integer n
  Print character '\n'
  Go to next iteration of OUTER_LOOP

Python 3, 83 bytes
prints the cuban primes forever.
P=k=1
while 1:P*=k*k;x=k;k+=1;P%k>0==((x/3)**.5%1)*((x/3+.25)**.5%1-.5)and print(k)

Try it online!
Based on this prime generator. For every prime it checks whether an integer y exists that fulfills the equation for either \$x = 1+y\$ or \$x=2+y\$.
$$ p=\frac{(1+y)^3-y^3}{(1+y)-y} = 1 + 3y +3y^2 \Leftrightarrow y = -\frac{1}{2}\pm\sqrt{\frac{1}{4}+\frac{p-1}{3}}$$
$$ p=\frac{(2+y)^3-y^3}{(1+y)-y} = 4 + 6y +3y^2 \Leftrightarrow y = -1 \pm\sqrt{\frac{p-1}{3}}$$
As we only care whether \$y\$ has an integer solution, we can ignore the \$\pm\$ and \$-1\$.

Perl 6, 33 31 bytes
-2 bytes thanks to Grimy
{grep &is-prime,1+|¾*$++²xx*}

Try it online!
Anonymous code block that returns a lazy infinite list of Cuban primes. This uses Arnauld's formula to generate possible cuban primes, then &is-prime to filter them.
Explanation:
{                           }  # Anonymous code block
 grep &is-prime,               # Filter the primes from
                         xx*   # The infinite list
                   ¾*          # Of three quarters
                     $++²      # Of an increasing number squared
                1+|            # Add one by ORing with 1

1+0+| can be just 1+|

Pari/GP, 51 bytes
Using Arnauld's formula.
n->a=0;for(i=1,n,until(isprime(p=3*a^2\4+1),a++));p

Try it online!

APL(NARS), 98 chars, 196 bytes
r←h w;y;c;v
r←c←y←0⋄→4
→3×⍳∼0πv←1+3×y×1+y+←1⋄r←v⋄→0×⍳w≤c+←1
→2×⍳∼0πv+←3×y+1⋄c+←1⋄r←v
→2×⍳w>c

indented :
r←h w;y;c;v
r←c←y←0⋄→4
    →3×⍳∼0πv←1+3×y×1+y+←1⋄r←v⋄→0×⍳w≤c+←1
    →2×⍳∼0πv+←3×y+1⋄c+←1⋄r←v
    →2×⍳w>c

test:
  h ¨1..20
7 13 19 37 61 109 127 193 271 331 397 433 547 631 769 919 1201 1453 1657 1801
  h 1000
25789873
  h 10000
4765143511

it is based on: if y in N, one possible Cuban Prime is
S1=1+3y(y+1)

the the next possible Cuban Prime will be
S2=3(y+1)+S1

authors: Xi'an ні війні