text:
All ASCII characters with a given bit count
(Title with thanks to @ChasBrown)
Sandbox
The Background
This challenge is inspired by a question that I recently posted on Puzzling Stack Exchange. Please feel free to follow the link if you are interested in the original question. If not then I won't bore you with the details here.
The Facts
Every printable standard ASCII character has a decimal value between 32 and 126 inclusive. These can be converted to their corresponding binary numbers in the range 100000 to 1111110 inclusive. When you sum the bits of these binary numbers you will always end up with an integer between 1 and 6 inclusive.
The Challenge
Given an integer between 1 and 6 inclusive as input, write a program or function which will output in any acceptable format all of the printable standard ASCII characters where the sum of the bits of their binary value is equal to the input integer.
The Examples/Test Cases
1 -> ' @'
2 -> '!"$(0ABDHP`'
3 -> '#%&)*,1248CEFIJLQRTXabdhp'
4 -> ''+-.3569:<GKMNSUVYZ\cefijlqrtx'
5 -> '/7;=>OW[]^gkmnsuvyz|'
6 -> '?_ow{}~'

An ungolfed Python reference implementation is available here (TIO).
The Rules

Assume the input will always be an integer (or string representation of an integer) between 1 and 6 inclusive.
You may write a program to display the results or a function to return them.
Output may be in any reasonable format but must be consistent for all inputs. If you choose to output a quoted string then the same type of quotes must be used for all inputs.
Standard loopholes prohibited as usual.
This is code golf so shortest code in each language wins.

Are we allowed to return/print a list of the decimal ascii values or do we need to have them in the form of characters (eg. 63 vs ?)?

Must be the actual characters.

"the same type of quotes must be used for all inputs" Python, for example, uses single quotes (') for the string representation of a string by default, but uses double quotes (") if the string contain a single quote and no double quotes. Not that this specific case will matter much, as you're probably better off returning the actual string instead of its representation, and you can still use single quotes in such a string for input anyway, but I feel it's worth mentioning here.

@EriktheOutgolfer Agreed. That is why I thought it might be interesting just to throw that in as an extra rule :-)

Thanks  @RIKER. The point of the format of the test cases was to show different acceptable formats of output however I'll leave your edits in place.

Seeing as there are only 6 possible inputs, you may as well include them all as test cases.

@ElPedro I hope you don't mind, I just added the remaining two cases just to complete the list.

@flawr No problem but you may want to escape the sigle quote in test case 4 ;-)

@ElPedro I wasn't sure what to do as it is probably a good idea to have some quotes, as there is a space in the first example, but the usual quotes both appear in the output:) Edit: maybe use french guillemets (« »)? :D

x86-16 machine code, IBM PC DOS, 29 25 bytes
Machine code:
00000000: be81 00ad b330 b108 d0c8 12dd e2fa 3adc  .....0........:.
00000010: 7502 cd29 fec0 79ec c3                   u..)..y..

Listing:
BE 0081     MOV  SI, 081H   ; SI = memory address of command line string
AD          LODSW           ; AL = start ASCII value (is 20H from space on cmd line)
                            ; AH = target number of bits (in ASCII)
        CHR_LOOP:
B3 30       MOV  BL, '0'    ; BL = counter of bits, reset to ASCII zero
B1 08       MOV  CL, 8      ; loop through 8 bits of AL
        BIT_LOOP:
D0 C8       ROL  AL, 1      ; rotate LSB of AL into CF
12 DD       ADC  BL, CH     ; add CF to BL (CH is always 0)
E2 FA       LOOP BIT_LOOP   ; loop to next bit
3A DC       CMP  BL, AH     ; is current char the target number of bits?
75 02       JNE  NO_DISP    ; if not, do not display
CD 10       INT  29H        ; display ASCII char in AL (current char in loop)
        NO_DISP:
FE C0       INC  AL         ; increment char to next ASCII value
79 EC       JNS  CHR_LOOP   ; if char <= 127, keep looping
C3          RET             ; return to DOS

Standalone PC DOS executable program, input number from command line.  Output is displayed to console window.

For a moment I thought it said "Download and test AT ABCT.COM", as if you had registered a domain just for this answer.

CP-1610 assembly (Intellivision), 20 DECLEs1 = 25 bytes
Takes \$N\$ in R0 and a pointer to the output buffer in R4. Writes all matching characters in the buffer and marks the end of the results with NUL.
                ROMW    10              ; use 10-bit ROM width
                ORG     $4800           ; map this program at $4800

                ;; ------------------------------------------------------------- ;;
                ;;  test code                                                    ;;
                ;; ------------------------------------------------------------- ;;
4800            EIS                     ; enable interrupts

4801            MVII    #$103,    R4    ; set the output buffer at $103 (8-bit RAM)
4803            MVII    #2,       R0    ; test with N = 2
4805            CALL    getChars        ; invoke our routine

4808            MVII    #$103,    R4    ; R4 = pointer into the output buffer
480A            MVII    #$215,    R5    ; R5 = backtab pointer

480C  draw      MVI@    R4,       R0    ; read R0 from the buffer
480D            SLL     R0,       2     ; R0 *= 8
480E            SLL     R0
480F            BEQ     done            ; stop if it's zero

4811            ADDI    #7-256,   R0    ; draw it in white
4815            MVO@    R0,       R5

4816            B       draw            ; go on with the next entry

4818  done      DECR    R7              ; loop forever

                ;; ------------------------------------------------------------- ;;
                ;;  routine                                                      ;;
                ;; ------------------------------------------------------------- ;;
      getChars  PROC

4819            MVII    #32,      R1    ; start with R1 = 32

481B  @loop     MOVR    R1,       R3    ; copy R1 to R3
481C            CLRR    R2              ; clear R2
481D            SETC                    ; start with the carry set

481E  @count    ADCR    R2              ; add the carry to R2
481F            SARC    R3              ; shift R3 to the right (the least
                                        ; significant bit is put in the carry)
4820            BNEQ    @count          ; loop if R3 is not zero

4822            CMPR    R2,       R0    ; if R2 is equal to R0 ...
4823            BNEQ    @next

4825            MVO@    R1,       R4    ; ... write R1 to the output buffer

4826  @next     INCR    R1              ; advance to the next character
4827            CMPI    #127,     R1    ; and loop until 127 is reached
4829            BLT     @loop

482B            MVO@    R3,       R4    ; write NUL to mark the end of the output

482C            JR      R5              ; return

                ENDP

Output for N=2
NB: The opening parenthesis looks a lot like an opening square bracket in the Intellivision font. Both characters are distinct, though.

screenshot from jzIntv

1. A CP-1610 opcode is encoded with a 10-bit value, known as a 'DECLE'. This routine is 20 DECLEs long, starting at $4819 and ending at $482C (included).

+1 just for being (a) a solution for the Intellivision, and (b) the first Intellivision code I've ever seen.

@Eight-BitGuru Coding on the Intellivision is pretty fun. And today's homebrew games are written in 16-bit ROM, which unlocks the full power (ahem...) of the CPU. :)

Impressive! Had no idea the Intellivision had a frame buffer and a built in character set. So much more advanced than the Atari 2600 for sure. Very nicely done!

@gwaugh The GROM (for Graphics ROM) contains all printable ASCII characters and a few common graphical shapes. Fun fact: it also contains some executable code that did not fit in the main ROM.

Definitely more advanced than the 2600, but if memory serves, Mattel didn’t reveal any of the advanced stuff hiding out in ROM, so third-party devs were either limited to straight machine code or had to suss out the fancy stuff on their own. Might be apocryphal.

Python 2, 62 bytes
lambda n:[chr(i)for i in range(32,127)if bin(i).count('1')==n]

Try it online!

sum(map(int,bin(i)[2:]))==n can become bin(i).count('1')==n to save 7 bytes.

Perl 6, 41 34 bytes
{chrs grep *.base(2)%9==$_,^95+32}

Try it online!
Anonymous code block that takes a number and returns a string of valid characters.
Explanation:
{                                }  # Anonymous code block taking a number
      grep                ,^95+32   # Filter from the range 32 to 126
           *.base(2)                # Where the binary of the digit
                    %9                # When parsed as a decimal modulo 9
                      ==$_            # Is equal to the input
 chrs                               # And convert the list of numbers to a string

It can be proven that for any number \$n\$ in base \$b\$, \$n \equiv \text{digitsum}(n) \pmod{b-1}\$ (clue: remember that \$b \pmod{b-1}=1\$).
We can use this to get the digitsum of our binary number by parsing it as a decimal number and moduloing by 9, which is valid because the range of numbers we are using is guaranteed to have less than 9 bits. This is helped along by Perl 6's automatic casting of the binary string to a decimal number when used in a numeric context.

05AB1E, 8 bytes
žQʒÇbSOQ

Try it online!
Explanation
žQ        # push the printable ascii characters
  ʒ       # filter, keep elements whose
   Ç      # character code
    b     # converted to binary
     SO   # has a digit sum
       Q  # equal to the input

JavaScript (Node.js), 60 bytes
Using Jo King's modulo trick
n=>(g=x=>x>>7?'':Buffer(x.toString(2)%9-n?0:[x])+g(x+1))(32)

Try it online!

JavaScript (Node.js),  70  69 bytes
n=>(g=x=>x>>7?'':Buffer((h=x=>x&&x%2+h(x>>1))(x)-n?0:[x])+g(x+1))(32)

Try it online!
Commented
n => (              // n = input
  g = x =>          // g = recursive function, taking a byte x
    x >> 7 ?        //   if x = 128:
      ''            //     stop recursion and return an empty string
    :               //   else:
      Buffer(       //     create a Buffer:
        (h = x =>   //       h = recursive function taking a byte x
          x &&      //         stop if x = 0
          x % 2 +   //         otherwise, add the least significant bit
          h(x >> 1) //         and do a recursive call with floor(x / 2)
        )(x)        //       initial call to h
        - n ?       //       if the result is not equal to n:
          0         //         create an empty Buffer (coerced to an empty string)
        :           //       else:
          [x]       //         create a Buffer consisting of the character x
      ) +           //     end of Buffer()
      g(x + 1)      //     append the result of a recursive call to g with x + 1
)(32)               // initial call to g with x = 32

60 bytes using Jo's modulo trick.

@Shaggy Oh. That's a nice one.

Jelly, 8 bytes
ØṖOB§=ʋƇ

Try it online!
ØṖ       printable ascii character list
  OB     to binary
    §    popcount
     =   equal to input?
      ʋƇ filter (implicitly output)

Brachylog, 7 bytes
∈Ṭ&ạhḃ+

Try it online!
A predicate which functions as a generator, takes input through its output variable, and produces each character through its input variable. Because Brachylog.
           The input variable (which is an element of the output)
∈          is an element of
 Ṭ         the string containing every printable ASCII character
  &        and the input
   ạh      converted to a codepoint
     ḃ     converted to a list of binary digits
      +    sums to
           the output variable (which is the input).

Japt, 9 bytes
;EÆ¶Xc¤è1

Try it or test all inputs
;EÆ¶Xc¤è1     :Implicit input of integer U
;E            :Printable ASCII
  Æ           :Filter each X
   ¶          :Test U for equality with
    Xc        :  Character code of X
      ¤       :  To binary string
       è1     :  Count the 1s

Excel (2016 or later), 76 bytes
=CONCAT(IF(LEN(SUBSTITUTE(DEC2BIN(ROW(32:126)),0,))=A1,CHAR(ROW(32:126)),""))

Takes input from A1, outputs in whatever cell you put this formula. This is an array formula, so you need to press Ctrl+Shift+Enter to input it. The "2016 or later" is because it needs the CONCAT function (the deprecated CONCATENATE won't take an array as argument).

I like this. I'm a Lotus Notes and 123 guy so this works for me :-)

R, 77 68 bytes
Approach using for loop
-9 bytes thanks to Giuseppe

n=scan();for(i in 32:126)if(sum(intToBits(i)>0)==n)cat(intToUtf8(i))

Try it online!
Previously:
R, 78 69 66 bytes
-12 bytes thanks to Giuseppe

a=32:126;cat(intToUtf8(a[colSums(sapply(a,intToBits)>0)==scan()]))

Turns the numbers 32 to 126 into a matrix of bits then sums across the rows to find which match the input number.
Try it online!

Use intToBits(x)>0 rather than as.single

Nice, I tried |0 and got an error and just assumed the logic operators wouldn't work.

66 bytes for the "previous" approach using sapply rather than matrix

C (standard library), 74 67 bytes
i;j;k;f(n){for(i=31;i<126;k||puts(&i))for(k=n,j=++i;j;j/=2)k-=j&1;}

Using only standard library functions. Thanks go to @gastropner for improvement from 74 to 67 bytes.
Try it online!

67 bytes

@gastropner that is an amazing improvement! Thank you!

I think you need to start at index 31 in order to pick up space in the f(1) case (because the ++i skips it).

@LambdaBeta You're absolutely right, thank you!

Java 8, 131 71 bytes
-60 bytes thanks to everyone in the comments
Returns a java.util.stream.IntStream of codepoints
n->java.util.stream.IntStream.range(32,127).filter(i->n.bitCount(i)==n)

Try it online!
Using HashSet, 135 bytes. Returns a Set<Object>:
n->new java.util.HashSet(){{for(int i=31;i++<126;add(Long.toBinaryString(i).chars().map(c->c-48).sum()==n?(char)i+"":""),remove(""));}}

Try it online!

128 bytes

Static access from non-static context reeeeeee. Thanks.

Long.toBinaryString(i) can be Long.toString(i,2);

Small tip: without streams is usually shorter ;)

To continue on my first comment: if you take the input as a Integer instead of int, Long.toBinaryString(i) can actually be n.toString(i,2) to save some more bytes.

@KevinCruijssen that's what my first comment does

@ExpiredData Ah, you're right. Since Benjamin responded to you I thought he had already edited your changes into his answer, but apparently not.. In that case just n.toString(i,2) stands as suggested golf. :) Oh, and the +"" can be removed as well I now notice.

92 bytes, but still using your stream approach.

@KevinCruijssen Just get rid of the final map: 71 bytes. Java deals with integers as characters since version 5...

@OlivierGrégoire Oh, now it's not much longer than my 67 bytes answer without stream. (Your TIO in your comment fails however because you forgot to modify the lambda signature.)

@KevinCruijssen You're right. Here's the fixed version: (still) 71 bytes. And yes, I saw your version which I upvoted less than 10 minutes ago ;)

Thanks for filling my inbox guys. I did not know bitcount existed, nice.

Dyalog APL Extended, 24 22 bytes
⎕ucs a⌿⍨⎕=+⌿2⊤a←32…126

Try it online!
-2 bytes thanks to ngn
Alternative 22 bytes in regular Dyalog APL by ngn:
⎕ucs 32+⍸⎕=32↓+/↑,⍳7⍴2

Try it online!

(expr)∘= -> ⎕=expr

without extended: ⎕ucs 32+⍸⎕=32↓+/↑,⍳7⍴2 (⎕io←0)

J, 31 27 23 bytes
((=1#.#:)u:@#])32+i.@95

-2 thanks to south
Attempt This Online!
J, 31 27 bytes
-4 bytes thanks to Galen
[:u:32+[:I.]=1#.32#:@+i.@95

Try it online!
Original Answer
a.#~&(95{.32}.])]=1#.2#:@i.@^8:

Try it online!

2#:@i.@^8: produces the binary numbers 0 through 255 (2 ^ 8 is 256)
1#. sums each one
]= produces a binary mask showing where the sum equals the original input
a.#~ mask uses that binary mask to filter J's full ascii alphabet a.
&(95{.32}.]) but before doing so take only elements 32...126 from both the alphabet and the mask

[:u:32+[:I.]=1#.32#:@+i.@95 for 27 bytes

Thanks Galen.  TIL you could do i.@95

25 bytes

@south Thanks.  I shaved an additional 2 off using your idea.

C# (Visual C# Interactive Compiler), 86 bytes
n=>Enumerable.Range(32,95).Where(x=>"0123456".Sum(g=>x>>g-48&1)==n).Select(x=>(char)x)

Thanks to @ExpiredData for giving me the idea to use Sum()! When I get back to my PC, I will replace the string "0123456" with unprintables, saving three bytes.
Try it online!

Sum and - instead of Count and ==

@ExpiredData Thanks for the idea to use Sum()!

Java 10, 98 97 94 70 67 bytes
n->{for(var c='';c-->31;)if(n.bitCount(c)==n)System.out.print(c);}

-24 bytes thanks to NahuelFouilleul.
Try it online.
Explanation:
Contains an unprintable character with unicode value 127.
n->{                         // Method with Integer parameter and no return-type
  for(var c='';c-->31;)     //  Loop character `c` in the range ['~', ' '] / (127,31):
    if(n.bitCount(c)         //   If the amount of 1-bits in the two's complement binary
                             //   representation of the current characters
                    ==n)     //   equals the input:
      System.out.print(c);}  //    Print the current character

-24bytes using Long.bitCount

@NahuelFouilleul Ah, I always forget about that builtin in Java! Thanks a lot. And 3 more bytes can be saved by using n.bitCount. :)

Yeah, Java beats JavaScript once more! I love those character challenges :P

Factor, 52 bytes
[ 32 126 [a,b] [ bit-count = ] with filter >string ]

Try it online!

32 126 [a,b] Create a range of printable ascii values
[ bit-count = ] with filter Select values with the bit count indicated by the input
>string Convert the result from a sequence of code points to a printable string

Python 2, 69 bytes
lambda n:[chr(i)for i in range(32,127)if sum(map(int,bin(i)[2:]))==n]

Try it online!

That's exactly what I got when I golfed my ref implementation. +1

Gaia, 10 bytes
₵R⟪¤cbΣ=⟫⁇

Try it online!
		| implicit input, n
₵R		| push printable ascii
  ⟪	⟫⁇	| filter the list where:
   ¤cbΣ		| the sum of the code point in binary
       =	| is equal to n

Ruby, 48 bytes
->n{(' '..?~).select{|x|x.ord.digits(2).sum==n}}

Try it online!

Perl 5 -a,  50 43 bytes
@NahuelFouilleul saves 7 bytes
map{$_=chr;unpack('B*')%9-"@F"||say}32..126

Try it online!

could save one byte using "@F" instead of $F[0]

48 bytes

43 bytes using %9 trick by @JoKing

K (ngn/k), 20 bytes
Solution:
`c$32+&(+/2\32+!95)=

Try it online!
Explanation:
Evaluated right-to-left:
`c$32+&(+/2\32+!95)= / the solution
                   = / equals?
       (          )  / do this together
               !95   / range 0..94
            32+      / add 32, so range 32..126
          2\         / break into base-2
        +/           / sum up
      &              / indices where true
   32+               / add 32
`c$                  / cast to character

\c$32+&32_(+/!7#2)=or`c$(31<)#&(+/!7#2)=` brings it to 19.

6502 assembly (NES), 22 bytes
Machine code:
a0 1f a6 60 c8 98 30 fb ca 0a b0 fc d0 fb e8 d0 f1 8c 07 20 f0 ec

Assembly:
    ldy #$1f ; Y holds the current character code
NextCharacter:
    ldx $60 ; load parameter into X
    iny
    tya
    bmi (NextCharacter + 1) ; exit at char 128, #$60 is the return opcode

CountBits:
    dex
Continue:
    asl
    bcs CountBits
    bne Continue

CompareBitCount:
    inx ; fixes off-by-one error and sets Z flag if bit count matches
    bne NextCharacter
    sty $2007
    beq NextCharacter ; always branches

Full program. Tested with FCEUX 2.2.3, should work on any standard NES emulator.
Inspired by Ryan Russell's answer. Input given at CPU address $60. Outputs to the console's Picture Processing Unit memory.

Hello and welcome to PPCG. Is there any way to verify your solution apart from building a cartridge, i.e. an (online) emulator or specification?

@JonathanFrech I've added a full program that can be assembled and run locally. As I understand, the NES environment is not really standardized for codegolf.

VBA, 146 bytes
Sub Main()
n=3
For i=32 To 127
b=CStr(Application.WorksheetFunction.Dec2Bin(i))
If Len(b)-Len(Replace(b,"1",""))=n Then MsgBox Chr(i)
Next
End Sub

I wonder if somehow it could be done using Excel alone, I am not a excel formula pro....

=IF(LEN(DEC2BIN(32))-LEN(SUBSTITUTE(DEC2BIN(32),"1",""))=A1,CHAR(32),"") Checks against the value in cell A1 and displays the character if the binary sum matches. It needs to be repeated 95 times, one for each ASCII value that we need to check, so it comes out at around 7100 bytes - not very golfy but at least it can be done!

@ElPedro - thanks to the Let() command, this can actually be compacted into a really satisfying Excel answer at 86 bytes

You can get this down to 91 bytes if you convert this to an immediate window function, use [...] evaluation, take input from A1 and output to the VBE debug window - x=[Dec2Bin(ROW(1:126))]:For i=32To 126:?IIf(Len(Replace(x(i,1),0,""))=[A1],Chr(i),"");:Next - Check out Tips for Golfing in VBA for more info

Nibbles, 5 bytes
|_~`^+`@ 2

That's 10 nibbles each encoded as half a byte in the binary form.
Translation:
|          filter
 _         printables (since stdin is empty)
 ~         not
  `^       xor
    +      sum
     `@2   to base 2
        $  filter var (implicit)
    @      first input arg (implicit)

It uses not of the xor to set itself up for implicit args (instead of == which wouldn't be able to use any)
Usage:
nibbles <filename>.nbl <input number>

Nibbles isn't on TIO yet...

Python 3.10, 58 bytes
lambda n:(chr(i)for i in range(32,127)if i.bit_count()==n)

Attempt This Online!
It's kind of like Lynn's answer.
Just it uses the .bit_count introduced in Python3.10, so its shorter
More info about .bit_count here: https://docs.python.org/3/library/stdtypes.html

I really like the idea of going through old questions and finding where new functions can shave a few bytes off! +1 from me.

Kotlin, 60 bytes
{n->(32..127).filter{n==it.countOneBits()}.map{it.toChar()}}

Note:
For the moment Kotlin's STDOUT in ATO is always empty.
And TIO doesn't support countOneBits().
More information about how to count bytes for a Kotlin answer:
https://codegolf.stackexchange.com/a/202985/112099
Attempt This Online!

you can use this ATO link just dropping the fun main

MATL, 10 bytes
6Y2tB!si=)

Try it online!
Explanation
6Y2        % All ASCII Chars
   t       % dup
    B      % convert each to binary
     !     % transpose
      s    % sum
       i=  % equal to the input?
         ) % Keep truthy elements

Wolfram Language (Mathematica), 70 bytes
FromCharacterCode/@Select[32~Range~126,s=#;Tr@IntegerDigits[#,2]==s&]&

Try it online!

PowerShell, 83 bytes
param($n)[char[]](32..126|?{([convert]::ToString($_,2)|% t*y|group)[1].count-eq$n})

Try it online!
Takes input $n, constructs a range from 32 to 126 and pulls out those numbers where |?{}: the number, converted ToString in base 2; converted toCharArray; grouped into 0s and 1s; taking the [1] index of that grouping; taking the .count thereof, and checking that it's -equal to our input $number. Those numbers are then cast as a char-array and left on the pipeline. Output is implicit, with newlines between elements.

Charcoal, 10 bytes
Φγ⁼Σ↨℅ι²Ｉθ

Try it online! Link is to verbose version of code. Explanation:
 γ          Predefined ASCII characters
Φ           Filtered by
      ι     Current character's
     ℅      ASCII code
    ↨       Converted to base
       ²    Literal 2
   Σ        Summed
  ⁼         Equals
         θ  First input
        Ｉ   Cast to integer
            Implicitly printed

PHP, 72 bytes
for($x=31;$x++<126;)echo$argn==count_chars(decbin($x),1)[49]?chr($x):'';

Try it online!

count_chars(decbin($x),1)[49] can just be decbin($x)%9

Red, 92 bytes
func[n][repeat k 95[if n = length? replace/all enbase/base c: form #"^_"+ k 2"0"""[prin c]]]

Try it online!

C(MSVC) 50 bytes
i;f(n){for(i=31;i++<127;n-__popcnt(i)||puts(&i));}

C(gcc), 60 bytes
i;f(n){for(i=31;i++<127;n-__builtin_popcount(i)||puts(&i));}

Try it online

Can you not use || instead of ?n:?

You can remove one byte by combining the increment with the check: i;f(n){for(i=32;i++<127;n-__builtin_popcount(i)||puts(&i));}

Octave with Communications Package, 32 bytes
@(n)t(sum(de2bi(t=' ':'~')')==n)

Try it online!

Factor, 94 bytes
: f ( n -- n s ) 94 [0,b] [ 32 + 2 >base [ 49 = ] count over = ] filter [ 32 + ] map >string ;

Try it online!

That is an impressive amount of necessary whitespace

@Unrelated String yes, it is :)

Haskell, 77 bytes
import Data.Char
b 0=0
b k=mod k 2+b(div k 2)
f n=[chr k|k<-[32..126],b k==n]

Try it online!

C (GCC) - 134 Bytes
#include <stdio.h>
#include <stdlib.h>
int main(int _,char**v){for(char c=32;c<127;c++)__builtin_popcount(c)-atoi(v[1])||putchar(c);}

Compile with gcc chars.c -o chars, and run the resulting program with the number of bits as the command-line argument.
Compiles with no warnings.
This program utilizes the __builtin_popcount builtin that is present in GCC, which resolves to a POPCNT instruction on most x86 hardware built in the last dozen or so years.

Scala, 88 87 bytes
(y:Int)=>32 to 126 map{x=>BigInt(x).bitCount->x}filter(_._1==y)map(_._2.toChar)mkString

I'm not that familiar with Scala, but are static calls possible like in Java? And if yes, can bytes be saved by changing (y:Int)=> to (y:Integer)=> and Integer.bitCount(x) to y.bitCount(x)?

@KevinCruijssen Can't use Integer but I can cast the value to BigInt and use bitCount on that. Thanks!

Z80Golf, 25 bytes
00000000: cd03 806f 0e20 517d 45cb 3a9b 10fb de30 ...o. Q}E.:....0
00000010: 2002 79ff 0ce2 0600 76                   .y.....v

Try it online!
  call $8003    ; A = getchar(), e.g. '5'
  ld l, a       ; L = A
  ld c, ' '     ; C = ' '
next:           ; do {
  ld d, c       ;   D = C
  ld a, l       ;   A = L, e.g. '5'
  ld b, l       ;   B = L (way more than enough)
more:           ;   while (--B ≠ 0) {
  srl d         ;       shift D right, bit 0 goes into Carry
  sbc a, e      ;       A -= 0 + Carry
  djnz more     ;   }
done:
  sbc a, '0'    ;   A -= '0' + Carry
  jr nz, omit   ;   if A == 0:
  ld a, c       ;       putchar(C)
  rst $38
omit:
  inc c         ;   C++
  jp po, next   ; } until overflow, i.e. stop when C becomes 0x80 = -128
  halt

Haskell, 61 bytes
f n=[toEnum k|k<-[32..126],sum[k`div`2^i`mod`2|i<-[0..6]]==n]

Try it online!
The type of f is f :: (Enum t) => Int -> [t]. That's more general than necessary, and it means  you need to e.g. putStrLn the result for Haskell to infer that you want a [Char] result.
I don't know what the rules say about that, but replacing toEnum k with ['\0'..]!!k is a workaround costing 3 bytes.

Forth (gforth), 81 bytes
: f 127 32 do 0 i begin 2 /mod >r + r> ?dup 0= until over = if i emit then loop ;

Try it online!
Code Explanation
: f           \ start a new word definition
  127 32      \ set up loop parameters
  do          \ loop from 32 to 126
    0 i       \ set up values for counting bits
    begin     \ start an indefinite loop
      2 /mod  \ divide by 2 and get quotient and remainder
      >r + r> \ add the remainder to the counter
      ?dup 0= \ check if quotient equals zero
    until     \ end the loop if it is
    over =    \ check if the result equals the input number
    if        \ if it is
      i emit  \ output the char for the current ascii value
    then      \ end the if
  loop        \ end the counted loop
;             \ end word definition

Perl 5 - 42+1
This is a modification of @Xcali solution, saving one character.  Perl's unpack has a built-in bit counting mechanism, no need for the mod-9 trick.
#!perl -a
map{$_=chr;unpack('%B*')-"@F"||say}32..126

Nice, you can save another byte reordering the body of the map too: https://tio.run/##K0gtyjH9/z83saBaJd42OaPIWsnBTUm3NK8gMTlbXdVJSz2/SKE4sbLW2EhPz9DI7P9/43/5BSWZ@XnF/3V9TfUMDA3@6yYCAA

MS Excel, 76 bytes
An anonymous worksheet function that takes input from cell A1 and outputs to the calling cell.
=Let(a,Row(32:126),Concat(If(Len(Substitute(Dec2Bin(a),0,))=A1,Char(a),"")))

Try it Online
Explanation
=Let(...)                      ' begin variable definition block
   a,Row(32:126),              ' assign array `[32...126]` to variable `a`
         Dec2Bin(a)            ' convert `a` to binary
       Substitute(~,0,)        ' for each binary element, remove all `0`s, leaving only `1`s
     If(Len(~)=A1,Char(a),"")  ' iff number of `1`s equals input, print that char
   Concat(~)                   ' concat array and output

Seriously cool. I had no idea you could do that. I'm not an Excel  expert. My idea Was just posted as a bit of fun. Respect and +1

Stax, 7 bytes
æqäí¼.ö

Run and debug it

Fig, \$10\log_{256}(96)\approx\$ 8.231 bytes
Fcp'=#xSbC

Try it online!
Explained (old)
VR32 127Co0*v=Mv'Sb
VR32 127            # Put the range [32, 127) into the register
              Mv'   # to each item in that range:
                 Sb # get the sum of the on bits in the binary representation of the number
         o0*v=      # multiply the register by whether each item in the bit count list equals the input and remove 0s. This acts as a makeshift filter that can use global input.
        C           # convert the remaining items to their ascii character equivalent

MathGolf, 12 bytes
♣⌡╒T≥gæâΣk=$

Try it online.
Explanation:
♣             # Push 128
 ⌡            # Subtract 2: 126
  ╒           # Pop and push a list in the range [1,126]
   T≥         # Remove the first 31 items: range [32,126]
     g        # Filter this list of integers by,
      æ       # using 4 characters as inner code-block:
       â      #  Convert the integer to a binary-list
        Σ     #  Sum the bits together
         k    #  Push the input-integer
          =   #  Check if it's equal to the sum
           $  # Convert the remaining integers to characters with this codepoint
              # (after which the entire stack is output implicitly as result)

Vyxal, 8 bytes
kP'Cb∑?=

Try it Online!
Explained
kP'Cb∑?=
kP       # printable ACSI characters with no spaces in between them
  '      # lambda filter
   C     # char
    b    # binary
     ∑   # summate
      ?  # input
       = # equal?

I am clueless about how this works. Would you care to add a short explaination?

@ElPedro How bout now? I edited it to include the explanation - hope u understand :3

Thunno 2, 9 bytes
kcæCh2BS=

Attempt This Online!
Explanation
kcæCh2BS=  # Implicit input
kc         # Printable ASCII characters
  æ        # Filtered by:
   Ch      #  Their ordinal
     2B    #  Converted to binary
       S=  #  Has a sum equal to the input
           # Implicit output

C++ (gcc), 124 113 bytes
-11 bytes thanks to @ceilingcat
#import<string>
auto a(int n){std::string f;for(int i=30,j,k;++i<127;f+=i*!j,j=n)for(k=i;k;k/=2)j-=k&1;return f;}

Try it online!
Iterates through the printable character codes, finds those that match the number of 1 bits desired, returns the string containing those characters concatenated.

Out of curiosity, why does i start at 30 instead of 31? It's currently looping in the range (30,127), but shouldn't this be (31,127)?

You don't have to add the #include statements to your code length, TIO 97 bytes

@KevinCruijssen: this relies on j being zero-initialized; the j=n condition is only run after the first loop, so since j is 0 the first time around, the first loop does nothing. Hence the first value that is actually checked is 32.

@JohanduToit why don't I have to add the #import statement? Aren't imports considered part of the code (since they are necessary for it to function)?

@NeilA. sorry, you are correct. You can still save one byte by using a 'for' loop instead of the 'while'.

JavaScript (Client && NodeJs), 222 bytes
Try it online
x=>[...Array(127).keys()].slice(32).reduce((a,d)=>(a.push({y:[...d.toString(2)].map(x=>+x),z:String.fromCharCode(d)}),a),[]).map(i => (i.y.reduce((a,b)=>(a.y+=+b,a),{y:0,z:i.z}))).reduce((a,b)=>(b.y==x?a.push(b.z):0,a),[])

T-SQL, 153 bytes
Query returns 1 row for each character.
DECLARE @ INT=6

SELECT char(number)FROM
spt_values,(values(1),(2),(4),(8),(16),(32),(64))x(x)WHERE
type='P'and number/32in(1,2,3)GROUP BY number
HAVING sum(number/x%2)=@

Try it online
186 bytes
Putting all characters in same row:
DECLARE @ INT=6

SELECT string_agg(char(h),'')FROM(SELECT
iif(sum(number/x%2)=@,number,-1)h
FROM spt_values,(values(1),(2),(4),(8),(16),(32),(64))x(x)WHERE
type='P'and number/32in(1,2,3)GROUP BY number)c

Try it online

Attache, 25 bytes
${{x=1~Bin[Ord@_]}\ascii}

Try it online!
Alternatives
26 bytes: ${{x=1~(Bin@Ord@_)}\ascii}
26 bytes: ${{x=Sum@Bin@Ord@_}\ascii}
28 bytes: ${Char!{x=Sum@Bin@_}\32:126}
28 bytes: ascii&${{y=Sum@Bin@Ord@_}\x}
34 bytes: ascii&{Mask[_2=Sum@Bin=>Ords@_,_]}
35 bytes: ascii&{Mask[_2=1&`~@Bin=>Ords@_,_]}
Explanation
${{x=1~Bin[Ord@_]}\ascii}
${                      }   lambda with named parameter `x` (for scoping)
  {              }\ascii    select all ascii characters...
     1~                       where the number of 1s
       Bin[Ord@_]             in the character's binary representation
   x=                         equals the parameter

6502 Assembly (NES), 29 bytes
Outputs as tiles to the screen.
Machine code: (xx represents branch displacement bytes which I would probably get wrong assembling by hand)
A2 1F
E8
30 xx
86 01
A9 00
06 01
F0 xx
69 00
10 xx
69 00
C5 00
D0 xx
8E 07 20
D0 xx
60

Assembly:
; Output buffer address in $2006 PPU_ADDR. bits in address 0.
    ldx #31 ; initialize first printable character
@loop:
    inx
    bmi @done ; stop at 128 (127 won't match on input 1-6)
    stx 1 ; initialize address 1 with character
    lda #0
@bits:
    asl 1 ; load a bit into carry
    beq @next
    adc #0 ; add the carry to a
    bpl @bits ; branch always
@next:
    adc #0
    cmp 0
    bne @loop
    stx $2007
    bne @loop
@done:
    rts

Clean, 65 bytes
import StdEnv
$n=[c\\c<-[32..127]|sum[(c>>p)rem 2\\p<-[0..6]]==n]

Try it online!
Defines $ :: Int -> [Int] giving a list of codepoints.

Rust - 112 bytes
fn a(i:u32)->String{std::str::from_utf8(&(0..128u8).filter(|x|x.count_ones()==i).collect::<Vec<u8>>()).unwrap()}

Going for worst reasonable answer. Rust does not allow simple conversions from ints to chars to strings.

JavaScript, 92 bytes
f=(b,c=32)=>c<127?(c.toString(2).match(/1/g).length-b?String.fromCharCode(c):"")+f(b,c+1):""

I like Number.prototype.toString(n).
f=(b,c=32)=>                                                                                //function declaration, starting at character code 32.
            c<127?                                                                           //check for out of range
                  (c.toString(2)                                                             //if the number in binary has
                                .match(/1/g).length                                          //number of 1 bits
                                                   -b?                                       //equal to b
                                                      String.fromCharCode(c):"")             //then add the character
                                                                                +f(b,c+1)    //next character

  :"" //base case for out of range(127)

dc, 52 bytes
sn31[dP]sP[1+dd[2~rd0<B]dsBx[+z3<S]dsSxln=PC6>M]dsMx

Try it online!
sn to store our target bit count from top-of-stack into register n. 31 starts us off at our first ASCII value (the main macro increments it immediately). [dP]sP is a printing macro, we call this when the bit count is equal to the target. Into our main macro, M... 1+dd increments top-of-stack and duplicates it twice. [2~rd0<B]dsBx uses integer division by two w/ remainder to break a decimal value down into binary bits on the stack. [+z3<S]dsSx sums stack items until we're back to three values on the stack - our summation and two copies of our ASCII value. ln=P compares the summation with n, our target bit count, and runs the printing macro P if they're equal. C6>M keeps running M through ASCII value 126.
One thing to note that I sometimes forget about when golfing in dc is that there's no harm in burying macros B and S inside of M since they're always going to run at least once per run of M. This saves a byte in each case - dsBx instead of sB outside of macro M and then lBx inside.

Have never heard of dc before but it looks cool. +1 for the good explanation.

@ElPedro, it's a fun language to mess around with. Somewhat golfy in that commands are all a single character, but then you get into issues like conditionals only being able to run macros. So if you want to print if something ==0, you can't 0=p but rather must make a macro that prints [p]sp and then call that. Stack movement is also very limited. A lot of little things working against you that makes it a fun challenge.

Clam, 11 bytes
p#:\bcqQ'a-

Prints an array of characters
Explanation
            - Implicit Q = first input
p           - Print...
        'a- - ASCII characters (dictionary access)
 #          - Where...
   \        - The sum of...
    b       - The binary bits of...
     cq     - The charcode of the character
  :         - Equals...
       Q    - Q

Julia 1.0, 43 bytes
y->filter(x->count_ones(Int(x))==y,' ':'~')

Try it online!

Arturo, 52 bytes
$->x[to[:char]select 32..127=>[x=∑digits.base:2&]]

Try it!
Outputs a list of characters, which seems to be allowed.


text:
Check if a string is entirely made of the same substring
This is taken from this question (with permission ofcourse). I'll quote:

Create a function which takes a string, and it should return true or
  false based on whether the input consists of only a repeated character
  sequence. The length of given string is always greater than 1 and the
  character sequence must have at least one repetition.

Some examples:
'aa' //true
'aaa' //true
'abcabcabc' //true
'aba' //false
'ababa' //false
'weqweqweqweqweqw' // false

Specifically, the check for a string strictly composed of repeating substrings (Update) can output any true or false representation, but no error output please. Strictly alphhanumeric strings. Otherwise standard code golf rules. This is Code Golf, so shortest answer in bytes for each language wins.

Hm, I was going to close this challenge as a dupe of that one, but I noticed that the other one scores on character count. So maybe we should close the other one (it also has an accepted answer) as a dupe of this one instead.

Let us continue this discussion in chat.

Brachylog, 4 3 bytes
ġ=Ṁ

Try it online!
Explanation
ġ=Ṁ    Implicit input, say "abcabc"
ġ      Split into chunks of equal lengths (except maybe the last one): ["abc","abc"]
 =     Apply the constraint that all of the chunks are equal,
  Ṁ    and that there are multiple of them.

The program prints true. if the constraints can be satisfied, and false. if not.

I was just struggling through trying to get something like ~j↙ or =Ṁc working before I noticed you posted this an hour ago

Oh, yeah, this could be one byte shorter: ġ=Ṁ

(Ṁ is a variable constrained to be a list of two or more elements)

(better TIO link now that I've realized why writeln is broken [I forgot to handle default subscript when I updated it for compatibility with declarative write])

I guess I'll just edit?

If I messed anything up feel free to roll it back

@UnrelatedString Great, thanks! I didn't think to check the variables wiki page.

Ṁ was added pretty recently, so if you hadn't checked it in the past week or two (or been in the chat room, where it was announced) you'd have no idea it's there. It's certainly not the most intuitive place to look unless you're already in the habit of using Ċ wherever you'd think to use l₂.

A lot of great answers, and the LUA answer has a special place in my heart. Arnauld's answer is particularly sweet since the original question that I based this on (not the dupe) is actually tagged Javascript. Mainly selecting this one just because it does appear to be the overall shortest for all languages and, as this is my first question, I get a badge.

JavaScript (ES6), 22 bytes
Returns a Boolean value.
s=>/^(.*)\1+$/.test(s)

Try it online!

Without a regular expression,  33  29 bytes
Returns either null (falsy) or an object (truthy).
s=>(s+s).slice(1,-1).match(s)

Try it online!
NB: Technically, \$s\$ is converted to a regular expression for match(), so the above title is a lie.

grep, 19
grep -qxE '(.+)\1+'

Test
while read; do
  <<<"$REPLY" grep -qxE '(.+)\1+' && t="true" || t="false"
  echo "$REPLY: $t"
done < infile

Output:
aa: true
aaa: true
abcabcabc: true
aba: false
ababa: false
weqweqweqweqweqw: false

Japt, 6 bytes
²é ¤øU

Saved one byte thanks to @Shaggy
Try it online!
        Implicit input, stored in variable 'U'
²       U+U, "abcabc" -> "abcabcabcabc"
 é      Rotate 1 char to the right "abcabcabcabc" -> "cabcabcabcab"
   ¤    Remove first two chars, "cabcabcabcab" -> "bcabcabcab"
    øU  Check if U is in the above

Nice one :) You can replace the p<space> with ² to save a byte.

Java, 25 24 bytes
-1 byte thanks to Olivier Grégoire!
Boring regex answer
s->s.matches("(.+)\\1+")

Try it online!
It's just 1 byte longer than the python answer aaaaa I'm tied now :)

You can remove the final $ as the matches method is an exact match, not a substring match by default.

I forgot matches adds its own $ to the regex. Thanks!

Excel, 26 bytes
=FIND(A1,A1&A1,2)<=LEN(A1)

Inputs from A1, outputs to whatever cell you put this formula.

You could save 4 bytes if you defined a single-letter range name (e.g. A) and set that as your input.

@i_saw_drones - I think that is disallowed by standard I/O rules: here's a link to the meta answer that would apply to that method; it's currently at -36 votes.

Apologies I hadn't seen that post, although thinking about it, isn't A1 also a "variable" since it contains the input value? :)

I would feel that way if I were doing anything special with the fact that it's A1 specifically, like if I relied somehow on its ROW(_) being 1. As is, though, it's just the most natural way of providing an Excel function with an arbitrary input.

R, 28 bytes
grepl("(.+)\\1+$",scan(,''))

Try it online!
Simple Regex version. R is (sometimes) very similar to Python, so this is similar to TFeld's Python 2 regex answer, albeit shorter!
Question (if anyone knows the answer)
I am still confused why this works, as the substring can be any length and will always work, and still works when I add a letter to the front of a valid string, like "cABABABABAB". If I personally read the regex, I see (.+), which captures any group of any length. And then \\1+$ which repeats the captured group any number of times until the end.
So why doesn't it capture just "AB" and find that it is repeated until the end of the string, especially since there is no restriction specified as to where the substring can start?

Interesting, this seems to be a bug in R's regex engine. Adding the option perl=TRUE makes it match cABABAB, as you'd expect. Running grep -E '(.*)\1+$' in bash also matches cABABAB, even though grep -E uses ERE, the same regex flavor R is supposed to support.

My guess is that this is an incorrectly applied optimization. Changing .+ at the start of a pattern to ^.+ is an important optimization, but if the .+ is inside capturing parens it stops being valid.

Retina 0.8.2, 9 bytes
^(.+)\1+$

Try it online! Link includes test cases.

Jelly,  5  4 bytes
I see now that the optimal way is to follow xnor's method!
Ḋ;Ṗw

A monadic Link that accepts a list of characters and outputs an integer - the  shortest possible length of a repeating slice or zero if none exists. Note that zero is falsey while non-zero numbers are truthy in Jelly.
Try it online!
How?
Ḋ;Ṗw - Link: list of characters, S   e.g. "abcabcabc"   or "abababa"
Ḋ    - dequeue S                           "bcabcabc"       "bababa"
  Ṗ  - pop from S                         "abcabcab"       "ababab"
 ;   - concatenate                "bcabcabcabcabcab"       "bababaababab"
   w - first index of sublist     3  ^---here!             0  (not found)

Python 2, 24 bytes
lambda s:s in(s*2)[1:-1]

Try it online!
Shamelessly stolen from xnor's answer to the original question.

More intuitive version:
Python 2, 59 55 53 bytes
lambda s:s in[len(s)/i*s[:i]for i in range(1,len(s))]

Try it online!

Boring regex version:
Python 2, 44 bytes
lambda s:re.match(r'(.+)\1+$',s)>0
import re

Try it online!

Perl 5 -p, 14 bytes
$_=/^(.*)\1+$/

Try it online!

J, 26 25 15 14 bytes
Using xnor method
+./@E.}:@}.@,~

Try it online!
original (two different approaches)
J, 25 bytes
1<1#.(#%#\)=<\+/@E.&:>"{]

Try it online!
J, 26 bytes
1<1#.-@#\([:(-:##{.)<\)"{]

Try it online!

Pyke, 4 bytes
+tO{

Try it here!
+    -    input+input
 t   -   ^[1:]
  O  -  ^[:-1]
   { - input in ^

Wolfram Language (Mathematica), 24 23 bytes
StringMatchQ[x__..~~x_]

Try it online!
StringMatchQ[           (*a function that checks if its input (string) matches:*)
             x__..      (*a sequence of one or more characters, repeated one or more times*)
                  ~~x_] (*and one more time*)

GNU Bash, 28 bytes
[[ ${1:1}${1::-1} == *$1* ]]

Save the above script into a file, and run bash file.sh "string to test".
Exit code 0 is truthy and non-zero is falsy. (as all Unix shells would interpret)

PowerShell, 23 24 bytes
+1 byte to fully match rules
"$args"-match"^(.+)\1+$"

Try it online!
Pretty boring. Based on the other Regex answers. Luckily PowerShell doesn't use \ as an escape character!

it returns true for aabcabc

@mazzy just fixed!

05AB1E, 5 bytes
xnor's method from the previous question appears to be optimal in 05AB1E as well.
«¦¨så

Try it online!
or as a Test Suite
Explanation
«       # append input to input
 ¦¨     # remove the first and last character of the resulting string
   så   # check if the input is in this string

Of course.. I was about to make a 05AB1E answer when I saw none were there. Colleague asked me some questions and talked about his vacation. I look back at the screen: one new answer. Tada, beat again XD

@KevinCruijssen: That's typical. Has happened to me a bunch of times as well ;)

C# (Visual C# Interactive Compiler), 70 bytes
xnor's shameless adaptation (46 bytes)
s=>(s+s).Substring(1,s.Length*2-2).Contains(s)

My non Regex Solution:
s=>s.Select((x,y)=>y).Count(z=>s.Replace(s.Substring(0,z+1),"")=="")>1

Explanation:
Replace every possible substring that starts at index 0 with an empty string. If the result is an empty string, the string is entirely made of that substring. Since this includes evaluating the entire string with itself, the amount of expected results must be greater than 1.
Example: abcabc
Possible substrings starting at index 0:
'a', 'ab', 'abc', 'abca', 'abcab', 'abcabc'

If we replace them with empty strings
Substring          Result

'a'         =>     'bcbc'
'ab'        =>     'cc'
'abc'       =>     ''
'abca'      =>     'bc'
'abcab'     =>     'c'
'abcabc'    =>     ''

Since there is a substring other than 'abcabc' that returns an empty string, the string is entirely made of another substring ('abc')
Try it online!

Python 3, 62 60 56 54 bytes
-4 bytes thanx to ArBo
lambda s:s in(len(s)//l*s[:l]for l in range(1,len(s)))

Iterate over all possible prefixes in the string.
Try to build the string out of the prefix.
Return whether this succeeds with any prefix at all.

Try it online!

Nice answer! The f= can be dropped; anonymous functions are generally allowed. Also, by switching to Python 2 and checking membership of a list instead of the any construct, you can get to 55 bytes

Nice catch with the list membership, thanx!
I won't switch to Python 2, as this is like switching the language, which is obviously not the point here ;)
Also, is there a convenient way to test an anonymous function in TIO, keeping the byte-count?

@movatica In the header, put f = \ (\ is the line continuation character in python)

Annoyingly, \ is also an escape character. Here, without code formatting, is what you should put in the header: f = \

Ruby -n, 16 13 bytes
-3 bytes thanks to south
For completeness, more or less the same as the other regex answers. Prints 0 for truthy, nil for falsey.
p~/^(.+)\1+$/

Attempt This Online!

13 bytes p~/^(.+)\1+$/. ~ is equivalent to rxp =~ $_.

@south Oops! Good catch.

Japt, 10 bytes
Returns a positive number if truthy and 0 if falsey. If you want a bool output just add -¡ flag
å+ k@rXÃÊÉ

å+ k@rXÃÊÉ      Full program. Implicit input U.
                    e.g: U = "abcabcabc"
å+              Take all prefixes
                         U = ["a","ab","abc","abca","abcab","abcabc","abcabca","abcabcab","abcabcabc"]
   k@           Filter U by:
     rXÃ        Values that return false (empty string)
                when replacing each prefix in U
                e.g: ["bcbcbc","ccc","","bcabc","cabc","abc","bc","c",""]
                                take ↑                             and ↑
                     U = ["abc","abcabcabc"]
         ÊÉ     Get U length and subtract 1. Then return the result

Try it online!

Husk, 6 bytes
Ṡ€ȯhtD

Try it online!
I feel like this is one byte more than optimal, but I couldn't find an arrangement that made the explicit composition ȯ unnecessary.
Explanation
Ṡ€      Find the argument in the result of applying the following function to the argument
  ȯhtD  Duplicate the argument, then remove the first and last elements.

€htD¹ avoids the ȯ.

That's fantastic! I had thought about λ€htD¹ but I didn't realize that lambdas would be added implicitly

Mathematica 11.x, 74 bytes
{}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&

where, throughout, # represents the input string, and
StringCases[#,<pattern>]

finds substrings of the input string matching the pattern
StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")

This pattern requires matches, x, must start at the start of the string and must satisfy the condition that (1) the match is not the whole input string and (2) if we replace occurrences of the match in the input string with the empty string we obtain the empty string.  Finally, comparing the list of matches to the empty list,
{}!=

is True if the list of matches is nonempty and False if the list of matches is empty.
Test cases:
{}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aa"]
(*  True  *)
{}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aaa"]
(*  True  *)
{}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["abcabc"]
(*  True  *)

and
{}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["aba"]
(*  False  *)
{}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["ababa"]
(*  False  *)
{}!=StringCases[#,StartOfString~~x__/;(x!=#&&StringReplace[#,x->""]=="")]&["weqweqweqweqweqw"]
(*  False  *)

Python 3, 84 bytes
import textwrap
lambda s:any(len(set(textwrap.wrap(s,l)))<2 for l in range(1,len(s)))

Uses textwrap.wrap (thanks to this answer) to split the string into pieces of length n to test each possible length of repeating substring. The split pieces are then compared to each other by adding them to a set. If all of the pieces are equal, and the set is of length 1, then the string must be a repeating string. I used <2 instead of ==1 because it saves a byte, and the length of the input string was guaranteed to be greater than zero.
If there is no n for which repeating substrings of length n make up the entire string, then return false for the whole function.

C++ (gcc), 36 bytes
#define f(x)(x+x).find(x,1)<x.size()

Try it online!
Another port of xnor's solution. Uses a macro to expand the argument into the expression. The argument is assumed to be of type std::string.

Clean, 73 bytes
Doesn't use regex.
import StdEnv,Data.List
$s=or[isPrefixOf s(cycle t)\\t<-tl(tails s)|t>[]]

Try it online!
Defines $ :: [Char] -> Bool.
Checks if the given string is a prefix of the repetition of any sub-string taken from the end.

Zsh, 19 bytes
Outputs via error code:
[[ $1$1 = ?*$1*? ]]

Try it online!
However, the challenge did specify "output on stdout":
Zsh, 22 bytes
Outputs an empty string if true, and a non-empty string for false:
<<<${${:-$1$1}/?*$1*?}

If the output must be fixed:
Zsh, 25 bytes
Outputs 0 for true, 1 for false
[[ $1$1 = ?*$1*? ]]
<<<$?

Try it online!

The heart of these solutions is ?*$1*?, which is a glob which matches the string in question surrounded by at least one character on each side: * is a string of any length, and ? is a single character.  This is an alternate version of xnor's solution, but using globs to match extra characters rather than removing leading and trailing characters.

Vyxal r, 5 4 bytes
dḢṪc

-1 byte by porting xnor's answer from the other question
Try it online!
Concatenates the string to itself, removes the first and last characters, then checks if the input string is in that.

K (ngn/k), 11 bytes
&/1_=':#'=:

Try it online!
Thanks to PyGamer0 for the "check if all the values of a list are equal" code snippet!
Return 1 for true and 0 for false
Explanations:
&/1_=':#'=:  Main function. Takes implicit input with : on the right-most
         =   Group the characters into a dictionary
       #'    Get the length in the values of each of the keys
             (The values are the occurence positions of the characters in the string)
      :      Apply everything on the left to the right
    ='       Check if the values of the values in the dictionary are equal
  1_         Weed out the first one (as we know it will always be false)
&/           Get the minimum value

T-SQL, 47 bytes
Using @Xnor's method:
DECLARE @ varchar(max)='ababab'

PRINT sign(charindex(@,left(@+@,len(@)*2-1),2))

Keeping old answer as it contains some nice golfing(67 bytes):
DECLARE @y varchar(max)='abababa'

,@ INT=0WHILE
replace(@y,left(@y,@),'')>''SET
@+=1PRINT @/len(@y)^1

Explanation: This script is repeatingly trying to replace the input '@y' with the first '@' characters of the input '@y' with nothing, while increasing '@'.

if you replace 'ab' in 'ababab' with nothing you have an empty string

Eventually the result will be empty. If this happens when the loop variable is equal to the length of the varchar, the criteria is false/0 because '@'=len(@y) (there was no repeating varchar).
iif(@=len(@y),0,1)

can be golfed into this
@/len(@y)^1

because the length of '@y' can not be 0 and '@' will never exceed the length @y.
Try it online

QlikView Variable, 27 bytes
This should be defined as a variable, which then allows you to pass parameters, e.g. $1 as your input value.
It returns 0 or -1 (equivalent to QlikView's TRUE() function).
=substringcount($1&$1,$1)>2

Swift, 196 bytes
func r(s:String)->Bool{guard let k=s.dropFirst().firstIndex(where:{$0==s.first}) else{return false};let v=s[...k].dropLast();var w=v;while s.hasPrefix(w) && s.count>=(w+v).count{w+=v};return s==w}

Try it online!

I don't use Swift, but I'm sure that extra whitespace can be removed

193 bytes using @benjamin's suggestion.

@ArtemisFowl or even 123 bytes

Icon, 46 bytes
procedure f(s);return find(s,(s||s)[2:-1]);end

Try it online!
Another port of xnor's solution.

K (oK), 29 bytes
{0<+/(1=#?:)'(0N,'1_!#x)#\:x}

Try it online!

Red, 72 bytes
func[s][repeat i length? s[parse s[copy t i skip some t end(return 1)]]]

Try it online!
Returns 1 for True

sed, 48
Using the more efficient algorithm described in this answer:
s=abcabc
<<<"$s" sed -nE 's/.*/&\n&&/; /^([^\n]+)\n..*\1.*.$/!q5' \
  && echo true \
  || echo false

TI-BASIC, 14 bytes
length(Ans)>inString(Ans+Ans,Ans,2

Input is a string in Ans.
Output is true (1) or false (0) as requested by the challenge.
Examples:
"HELLO
HELLO
prgmCDGF17
               0
"AB
AB
prgmCDGF17
               0
"ABAB
ABAB
prgmCDGF17
               1

Explanation:
length(Ans)>inString(Ans+Ans,Ans,2   ;full program

            inString(                ;get the index of
                             Ans,    ; the input in
                     Ans+Ans,        ; the input concatenated with itself
                                 2   ; starting at the second character
                                     ; (returns index of concatenated piece
                                     ;  if not found elsewhere)
length(Ans)                          ;and then get the length of the input
           >                         ;is the length greater than the index?
                                     ; result is left in "Ans"
                                     ; 1 if true, 0 if false
                                     ;implicit print of "Ans"

Note:  TI-BASIC is a tokenized language.  Character count does not equal byte count.

C (gcc), 37 bytes
#define f(x)strcmp(strstr(1+x x,x),x)

Try it online!
Yet another port of xnor's solution.
Using C macros to create the concatenated string, where the macro assumes the argument is a string literal.

Perl 6, 14 bytes
{?/^(.+)$0+$/}

Try it online!

Swift 4.2/Xcode 10.2, 123 84 bytes
(1...s.count-1).contains{s==String(repeating:String(s.prefix($0)),count:s.count/$0)}

Try it online!

SmileBASIC 3, 72 bytes
Prints 1 for true and 0 for false.
LINPUT L$W=LEN(L$)FOR I=1TO W/2IF LEFT$(L$,I)*(W/I)==L$THEN?1STOP
NEXT?0

Explained
LINPUT L$       'read line of input
W=LEN(L$)       'store length of input
FOR I=1 TO W/2  'loop over all prefixes
 'if this prefix repeated to length of input equals input, print 1 and stop
 IF LEFT$(L$,I)*(W/I)==L$ THEN ?1 STOP
NEXT
?0              'print 0 because check failed

Perl 6, 14 bytes
*~~/^(.+)$0+$/

Or for the same amount
{m/^(.+)$0+$/}

Much the same as other answers with a simple regex.  First one uses Whatever block and a smart matcher to run the regex, and the second does a match on the block input with the implied value.  Both return Match objects which are truthy on success, and Nil which is falsey on fairly.
Try it online!

Lua, 50 bytes
Another port of xnor's solution:
s=io.read()t=s..s print(s.find(t.sub(t,2,#t-1),s))

Prints indexes if true, 'nil' otherwise.
Try it online!

source: Stack Exchange

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

sort: votes


text:
Kill The Dragon!
John, a knight wants to kill a dragon to escape the castle! The dragon has A heads and B tails.
He knows, that:

if you cut off one tail, two new tails grow
if you cut off two tails, one new head grows
if you cut off one head, one new tail grows
if you cut off two heads, nothing grows

To defeat the dragon, John needs to cut off all his heads and all his tails. Help the knight to do this by making no more than 1000 strikes.
Input
The input contains two integers A and B (1 ≤ A, B ≤ 100).
Output
Print the sequence of strikes in the order in which they should be performed by encoding them with the following combinations of letters: T (one tail), TT (two tails), H (one head), HH (two heads) in the most optimal order.
Example
3 1

T
TT
HH
HH

The winning condition is the least number of bytes!
UPDATE: Bounty on offer for answers with Python

Must the output be the most optimal order, or list an order? This might make it easier to produce a solution by converting all heads to tails (or vice versa) before engaging in a predictable sequence.

@Draco18s it has to be the most optimal order

@Draco18s will also offer bounty to winning python answer

What is your criteria for "most optimal order"? Least total limbs cut or least steps in the sequence?

@Zylviij least steps

Do we have to use T, TT, H, HH or can we use other values (such as 0 1 2 3)?

@TFeld T, TT, H and HH have to be used as an output. You can represent it using that but at the end the output has to be in that format.

Please add test cases.

This is basically pathfinding from $(a, b)$ to $(0, 0)$ on a $\mathbb{N}^2$ grid, where the valid moves are ${(0,1),(1,-2),(-1,1),(-2,0)}$ (with a minor caveat: you can't make the first move at $b=1$).

Visually, these are the steps you can make ("more tails" is $\uparrow$, "more heads" is $\rightarrow$, you're trying to go $\swarrow$): $$ \begin{bmatrix}\cdot&\cdot&\cdot&\cdot&\cdot\\cdot&\text{H}&\text{T}&\cdot&\cdot\\text{HH}&\cdot&\text{you}&\cdot&\cdot\\cdot&\cdot&\cdot&\cdot&\cdot\\cdot&\cdot&\cdot&\text{TT}&\cdot\end{bmatrix} $$

I see this problem appears as brain teaser on other sites such as this one, and it seems to be originally from a book of brainteasers. Do you have the author's permission to post it?

@xnor I came up with it

JavaScript (ES6),  136  134 bytes
Takes input as (heads)(tails). Naive brute force search.
h=>F=(t,x=0)=>(g=(h,t,p=[],i=-6)=>h|t?h<0|t<0||p[x]?0:['HH','H','T','TT'].some(m=>g(h+i+4,i++%5%4-~t,[...p,m]))&&P:P=p)(h,t)||F(t,x+1)

Try it online!

I think this works for 104 bytes, but I'm not totally sure if it's guaranteed to find an optimal solution.

@user This is indeed not optimal for, say, (4,1) which can be done in 4 moves.

Oh, that's too bad.

Python 2, 122 121 117 bytes
def f(a,b):x=a+b/2;b+=1;return b%2*x%2and['H']+a%2*['TT']+f(a-~a%2,b-a%2*2)or~b%2*['HT'[x%2]]+b/2*['TT']+-~x/2*['HH']

Try it online!

Python 2, 121 bytes
Outputs to stderr, tries all possible sequences until the first one succeeds.
r=[([],)+input()]
for s,h,t in r:h==t==0>exit(s);r+=[(s+['HT'[i/9]*(2-i%2)],h+i/4-2,t+i%4-2)for i in 11,12,7,2 if h>-1<t]

Try it online!
I don't think the if h>-1<t part is necessary, without it it would be 111 bytes.

Could you do it so the input is separated by a space not a comma?

Without h>-1<t, I think the algorithm will always find a solution with the correct length. It may however result in negative heads or tails (e.g. 2,1 -> ['TT', 'H', 'HH']) and would therefore be invalid.

Jelly, 71 bytes
⁴HḞ
“TT¶”ẋ¢
³ḂḤ⁴+
“H¶TT¶“H¶H¶TT¶“T¶TT¶“”¢ị
Ø+ŻUŻ3£ị+1£+³H
“HH¶”ẋ¢
2£4£¢

Try it online!
I'm quite new to Jelly, so this is not optimal, but here's my explanation:
                         (1st link)
⁴                        starting number of tails
 H                       halved
  Ḟ                      and floored

                         (2nd link)
“TT¶”                    take the string "TT\n"
     ẋ¢                  and repeat it (last link) amount of times

                         (3rd link)
³                        starting number of heads
 Ḃ                       mod 2
  Ḥ                      doubled
    +                    plus
   ⁴                     starting number of tails

                         (4th link)
“H¶TT¶“H¶H¶TT¶“T¶TT¶“”   array of actions
                      ¢  based on the last link
                       ị get the (n % len(array))th element

                         (5th link)
Ø+                       [1, -1]
  Ż                      prepend 0 ([0, 1, -1])
   U                     reverse the array ([-1, 1, 0])
    Ż                    prepend 0 ([0, -1, 1, 0])
       ị                 index
     3£                  of the 3rd link
        +                plus
         1£              1st link
             +           plus
           ³H            half the number of heads

                         (6th link)
“HH¶”                    take the string "HH\n"
     ẋ¢                  repeat it (last link) amount of times

                         (Main link)
2£                       2nd link
  4£                     4th link
    ¢                    last link

Batch, 201 bytes
@set/aa=%1,b=%2,c=(b+a+a)%%4
@if %1%c%==12 echo TT&set/ab-=a=c=2
@if %c%==3 echo T&set/ab+=1,c=0
@set/ab+=c,a+=b/2-c,c+=c
@for %%v in (%c%.H %b%.TT %a%.HH)do @for /l %%i in (2,2,%%~nv)do @echo%%~xv

Works by directly calculating the number of H, TT and HH strikes required. This handles all cases except where \$2a+b\equiv3\pmod4\$ (which requires an initial T) and the case \$a=1,b=4k\$ (which requires an initial TT). Edit: Fixed second special case for \$k>1\$.

Java 8, 194 167 164 163 140 135 bytes
(h,t)->{for(;t>-h;)System.out.println(t+h%2<1&&h>(h-=2)?"HH":h<1&t%4<3|t%4==h%2*2&&h<++h&t>(t-=2)?"TT":t++%4!=3-h%2*2&&h>--h?"H":"T");}

-51 bytes thanks to @ceilingcat.
Try it online.
Explanation:
I first tried all possible cases by hand:
Heads     Tails        Steps

1 (odd)   5 (%4==1)    1,5 → T(1,6) TT(2,4) TT(3,2) TT(4,0) HH(2,0) HH(0,0)
1 (odd)   6 (%4==2)    1,6 → see above after first step

2 (even)  6 (%4==2)    2,6 → H(1,7) H(0,8) TT(1,6) TT(2,4) TT(3,2) TT(4,0) HH(2,0) HH(0,0)
1 (odd)   7 (%4==3)    1,7 → see above after first step

3 (odd)   8 (%4==0)    3,8 → H(2,9) H(1,10) TT(2,8) TT(3,6) TT(4,4) TT(5,2) TT(6,0) HH(4,0) HH(2,0) HH(0,0)
2 (even)  9 (%4==1)    2,9 → see above after first step

2 (even)  7 (%4==3)    2,7 → T(2,8) TT(3,6) TT(4,4) TT(5,2) TT(6,0) HH(4,0) HH(2,0) HH(0,0)
2 (even)  8 (%4==0)    2,8 → see above after first step

0 (zero)  6 (%4==2)    0,6 → TT(1,4) H(0,5) TT(1,3) H(0,4) TT(1,2) TT(2,0) HH(0,0)
0 (zero)  5 (%4==1)    0,5 → see above after second step
0 (zero)  4 (%4==0)    0,4 → see above after fourth step

0 (zero)  7 (%4==3)    0,7 → T(0,8) TT(1,6) TT(2,4) TT(3,2) TT(4,0) HH(2,0) HH(0,0)

5 (odd)   0 (zero)     5,0 → H(4,1) H(3,2) TT(4,0) HH(2,0) HH(0,)
4 (even)  0 (zero)     4,0 → see above after third step

After that I knew the first moves for every possibility. Which I displayed here in table form:
      | 0   %4==0    %4==1    %4==2    %4==3  < Tails
------|-------------------------------------
0     | -   TT       TT       TT       T
%2==0 | HH  TT       H        H        T
%2==1 | H   H        T        TT       H
  ^
Heads

As for my code:
(h,t)->{                // Method with two integer parameters and String return-type
  for(;t>-h;)           //  Loop until both the amount of heads and tails are 0:
    System.out.println( //   Print with trailing newline:
      t+h%2<1&&         //    If there are 0 tails and an even amount of heads:
        h>(h-=2)?       //     Decrease the amount of heads by 2
        "HH"            //     And print "HH"
      :h<1&t%4<3        //    Else if there are 0 heads and tails modulo 4 is 0, 1, or 2
       |t%4==h%2*2&&    //    Or there is an even amount of heads and tails modulo 4 is 0
                        //    Or there is an odd amount of heads and tails modulo 4 is 2:
        h<++h&          //     Increase the amount of heads by 1
        t>(t-=2)?       //     Decrease the amount of tails by 2
        "TT"            //     And print "TT"
      :t++%4!=3-h%2*2&& //    Else-if there are an odd amount of heads and tails modulo-4 is NOT 1
                        //    Or there are an even amount of heads and tails modulo-4 is NOT 3:
                        //    (and increase `t` by 1 with `t++` right after this check)
        h>--h?          //     Decrease the amount of heads by 1
        "H"             //     And print "H"
      :                 //    Else:
        "T");}          //     Print "T"

Wolfram Language (Mathematica), 104 91 77 bytes
-14 bytes thanks to @att
Table@@@Join[{H,b=1-#~Mod~2},{T,q=Mod[2-#2-b,4]},{TT,n=(#2+q)/2},HH|(#+n)/2]&

Try it online!
A 74 byte version, but can't be run in TIO, as it fakes Put. Put is the only valid operator with a higher precedence than Set, so it can be used in place of List in each pair, save a byte over each.
Table@@@Join[H>>b=1-#~Mod~2,T>>q=Mod[2-#2-b,4],TT>>n=(#2+q)/2,HH|(#+n)/2]&

H takes (1,0) to (0,1), not (2,0). You can also use infix on the left side of Set.

77 bytes

APL (Dyalog Unicode), 91 79 bytes
Saved 1 byte thanks to @ovs
{⍺=-⍵:⍬⋄⍵>1:'TT ',(⍺+1)∇⍵-2⋄3=⍺+⍵:'H ',(⍺-1)∇⍵+1⋄1=⍺⌈⍵:'T ',⍺∇⍵+1⋄'HH ',⍵∇⍨⍺-2}

Try it online!
Here is my "research." The x-axis is heads, y-axis is tails. Each cell contains the minimum number of moves to get to (0, 0), and the optimal move(s) you can make from there.

There are multiple ways you can divide it up, but I am going to hold t>=2 to be one section (TT); (2, 1) and (3, 0) to be another (H); (1, 0), (0, 1), and (1, 1) to be another (T), and the rest to be HH.
The first case is if the dragon has no heads or tails (h==-t), in which case we return the empty set (⍬).
As you can see, the optimal move if the dragon has 2 or more tails is a double tail-chop, and that is our second case. We prepend 'TT ' to the result of calling the function again with one more head and two less tails. ∇ refers to the current function, ⍺ is heads, and ⍵ is tails.
The third case is the single head chop. The only two times when the only option available is H is at (3,0) and (2,1). Our condition here is that h+t is 3 (this condition is also met with (1,2) and (0,3), but those were covered in the second case).
The third case is the single tail chop. Only one square requires it - (1, 1), so we check if the maximum of h and t is 1.
The last case doesn't need any condition checking, so we can go ahead and decapitate the dragon twice.

0=⍺+⍵ => ⍺=-⍵ for -1 byte

How can the optimal move for 1 head, 0 tails be a tail chop? (Although I can't talk; my script outputs two head chops and a double tail chop...)

Never mind, those rows don't make sense, as you're guaranteed at least one head and one tail.

@Neil I didn't notice that! I should probably update it, even if it's a case that will never be reached.

05AB1E, 75 71 bytes
[UVXY+_#XÈY_*i„HHYXÍëY4%©X_i3‹ëXÈi_ë2Q}}i„TTYÍX>ë®XÈi3Q}i'TY>Xë'HY>X<]»

Port of my Java answer. Can definitely be golfed, though (probably by using a different approach all-together more suitable to 05AB1E..)
Try it online or verify some more test cases.
Explanation:
[                  # Start an infinite loop:
 U                 #  Pop and save the top of the stack (or the first (implicit) input
                   #  in the first iteration) in variable `X` (the heads)
 V                 #  Pop and save the top of the stack (or the second (implicit) input
                   #  in the first iteration) in variable `Y` (the tails)
 XY+_              #  If the amount of heads and tails are both 0:
     #             #   Stop the infinite loop
 XÈ   i            #  If there is an even amount of heads
   Y_*             #  and there are 0 tails:
       „HH         #   Push "HH" to the stack
       Y           #   Leave `Y` the same
       XÍ          #   Decrease `X` by 2
 ë                 #  Else:
  Y4%              #   Push tails modulo-4 to the stack
     ©             #   (and add it to the register without popping as well)
      X_i          #   If there are 0 heads:
         3‹        #    Check if tails modulo-4 is 0, 1, or 2
      ëXÈi         #   Else-if there are an even amount of heads (but not 0)
          _        #    Check if tails modulo-4 is 0
      ë            #   Else (there are an odd amount of heads)
       2Q          #    Check if tails modulo-4 is 2
           }}i     #   And if it is truthy:
              „TT  #    Push "TT" to the stack
              YÍ   #    Decrease `Y` by 2
              X>   #    Increase `X` by 1
 ë                 #   Else:
  ®                #    Push tails modulo-4 to the stack again (from the register)
   XÈi             #    If there are an even amount of heads:
      3Q           #     Check if tails modulo-4 is 3
        }i         #    If this is truthy or tails modulo-4 is 1:
          'T      '#     Push "T" to the stack
          Y>       #     Increase `Y` by 1
          X        #     Leave `X` the same
 ë                 #    Else:
  'H              '#     Push "H" to the stack
  Y>               #     Increase `Y` by 1
  X<               #     Decrease `X` by 1
]                  # After all if-else statements and the loop:
 »                 # Join everything on the stack by newlines
                   # (which is output implicitly as result)

Scala, 154 147 bytes
a=>b=>{var(h,t,s)=(a,b,"")
while(-t<h)s+=(if(t>1){h+=1;t-=2
"TT "}else if(3==h+t){h-=1;t+=1
"H "}else if(2>h.max(t)){t+=1
"T "}else{h-=2
"HH "})
s}

Try it online!
Uses a completely different approach, but it's still longer than Java. :(
See my APL answer for an explanation.
Previous solution, 182 bytes
h=>t=>{var m=Map(0->0->"")
while(!m.keySet(h->t)){for{g->s->p<-m
i->u->q<-Map(g+2->s->"HH",(g+1,s-1)->"H",(g,s-1)->"T",(g-1,s+2)->"TT")--m.keySet
if-1<i*u}m+=i->u->s"$q $p"}
m(h->t)}

Try it online!
Uses the pathfinding approach Lynn suggested in the comments.

Python 3, 107 bytes
def f(a,b):return'TT '+f(a+1,b-2)if b>2else'HH '+f(a-2,b)if a>2else'H '+f(1,b+1)if a>1else'T TT HH'[2*b-2:]

Try it online!
The only way to reduce the tails is TT. You can safely do this as long as b > 2.
You can also safely reduce heads by HH as long as a > 2. I do this after reducing the tails, so it does not mix with TT operations.
When no more than 2 heads and tails are left, there are two cases:

a = 2: Cut off a head (H) then call recursively (with a = 1 now).
a = 1: Manually coded using a constant string.

Java (JDK), 110 bytes
String f(int a,int b){return b>2?"TT "+f(a+1,b-2):a>2?"HH "+f(a-2,b):a>1?"H "+f(1,b+1):b>1?"TT HH":"T TT HH";}

Try it online!

Perl 5, 102 bytes
sub f($a,$b){$b>2?"TT ".f($a+1,$b-2):$a>2?"HH ".f($a-2,$b):$a>1?"H ".f(1,$b+1):$b>1?"TT HH":"T TT HH"}

Try it online!
6 Chars less due to hint by Dom Hastings.

Nice! You can save 6 bytes with the flag -Mfeature+signatures (which changes the 'language' from Perl to Perl + -Mfeature+signatures instead of adding bytes) and using function signatures: Try it online!

@Dom Hastings: Thank you for your hint!

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


text:
Which big number is bigger?
Input
Integers a1, a2, a3, b1, b2, b3 each in the range 1 to 20.
Output
True if a1^(a2^a3) > b1^(b2^b3) and False otherwise.

^ is exponentiation in this question.
Rules
This is code-golf. Your code must terminate correctly within 10 seconds for any valid input on a standard desktop PC.
You can output anything Truthy for True and anything Falsey for False.
You can assume any input order you like as long as its specified in the answer and always the same.
For this question your code should always be correct. That is it should not fail because of floating point inaccuracies.  Due to the limited range of the input this should not be too hard to achieve.
Test cases
3^(4^5) > 5^(4^3)
1^(2^3) < 3^(2^1)
3^(6^5) < 5^(20^3)
20^(20^20) > 20^(20^19)
20^(20^20) == 20^(20^20)
2^2^20 > 2^20^2
2^3^12 == 8^3^11
1^20^20 == 1^1^1
1^1^1 == 1^20^20

Comments are not for extended discussion; this conversation has been moved to chat.

Perl 6, 31 29 bytes
-2 bytes thanks to Grimy
*.log10* * ***>*.log10* * ***

Try it online!
Believe it or not, this is not an esolang, even if it is composed of mostly asterisks. This uses Arnauld's formula, with log10 instead of ln.

I believe this fails for 2^3^12 == 8^3^11.

@ØrjanJohansen This should be fixed now. let me know if it fails for anything else

-2 by removing the unneeded spaces

@Grimy Thanks! I could have sworn I tried that...

R, 39 bytes
function(x,y,z)rank(log2(x)*(y^z))[1]<2

Try it online!
Returns FALSE when a > b and TRUE if b < a

This is wrong for f(2,2,20,2,20,2)

Fixed, using your suggestion to @Arnauld answer ;)

I believe this fails for 2^3^12 == 8^3^11.

Fails for both 1^20^20 == 1^1^1 and 1^1^1 == 1^20^20.

05AB1E, 11 9 11 7 bytes
.²Šm*`›

Port of @Arnauld's JavaScript and @digEmAll's R approaches (I saw them post around the same time)
-2 bytes thanks to @Emigna
+2 bytes as bug-fix after @Arnauld's and @digEmAll's answers contained an error
-4 bytes now that a different input order is allowed after @LuisMendo's comments
Input as [a1,b1], [a3,b3], [a2,b2] as three separated inputs.
Try it online or verify all test cases.
Explanation:
.²       # Take the logarithm with base 2 of the implicit [a1,b1]-input
  Š      # Triple-swap a,b,c to c,a,b with the implicit inputs
         #  The stack order is now: [log2(a1),log2(b1)], [a2,b2], [a3,b3]
   m     # Take the power, resulting in [a2**a3,b2**b3]
    *    # Multiply it with the log2-list, resulting in [log2(a1)*a2**a3,log2(b1)*b2**b3]
     `   # Push both values separated to the stack
      ›  # And check if log2(a1)*a2**a3 is larger than log2(b1)*b2**b3
         # (after which the result is output implicitly)

You second version can be εć.²š]P`›

@Emigna Ah nice, I was looking at an approach with ć, but completely forgot about using š (not sure why now that I see it, haha). Thanks!

This seems to be incorrect (because Arnauld's answer was incorrect until the recent fix).

@Anush Fixed and 4 bytes saved by taking the inputs in a different order now. :)

Java (JDK), 56 bytes
(a,b,c,d,e,f)->a>Math.pow(d,Math.pow(e,f)/Math.pow(b,c))

Try it online!
Credits

@Ørjan Johansen for finding a bug in my solution.
Saved 10 bytes by reusing @tsh's advantageous operands agencing.

I believe this fails for 2^3^12 == 8^3^11.

@ØrjanJohansen Fixed

Wolfram Language (Mathematica), 23 bytes
#2^#3Log@#>#5^#6Log@#4&

Try it online!

This doesn't terminate for a1=20, a2=20, a3=20.

@Anush fixed...

Too bad about overflow, otherwise ##>0&@@(##^1&@@@#)& is only 19 bytes and even more mind-bogglingly un-Mathematica-like than the code above. (infput format {{a,b,c},{d,e,f}})

J, 11 9 bytes
>&(^.@^/)

Try it online!
Arguments given as lists.

> is the left one bigger?
&(...) but first, transform each argument thusly:
^.@^/ reduce it from the right to the left with exponention.  But because ordinary exponentiation will limit error even for extended numbers, we take the logs of both sides

Python 3, 68 bytes
lambda a,b,c,d,e,f:log(a,2)*(b**c)>log(d,2)*(e**f)
from math import*

Try it online!
Port of @Arnualds answer, but with the base for log changed.

^ is called ** in Python. And with that changed, you won't be able to run all the OP's test cases.

Should be all fixed now, 66 bytes though.

I believe this fails for 2^3^12 == 8^3^11.

@ØrjanJohansen should be fixed

Seems like it. Apart from the logarithmic base change for the fix, this looks like Arnauld's method.

@ØrjanJohansen I thought that too but then the ordene confused me. I see it know.

you don't need the extra sets of brackets around the exponents

Clean, 44 bytes
import StdEnv
$a b c d e f=b^c/e^f>ln d/ln a

Try it online!
Uses an adaptation of Arnauld's formula.

I believe this fails for 2^3^12 == 8^3^11.

@ØrjanJohansen Fixed.

Vyxal, 11 bytes
2(?9•??e*)>

I'm beginning to understand Vyxal.
Try it Online!

11 bytes

@lyxal Why did I not think of that.

9 bytes

@AaronMiller That doesn't work because time complexity.

05AB1E, 13 bytes
Uses the method from Arnauld's JS answer
2F.²IIm*ˆ}¯`›

Try it online!

This doesn't terminate for a1=20, a2=20, a3=20.

@Anush: Seems to terminate in less than a second to me.

you have to set all the variables to 20. See https://tio.run/##yy9OTMpM/f9f79Du3GK9Q6tzHzXs@v8/2shAB4xiuRBMAA

@Anush: Ah, you meant b1=b2=b3=20 ,yeah that doesn't terminate.

Yes, sorry. That is what I meant.

Ah, you edited and undeleted a few seconds before I finished my answer.. Your alternative is the same as I had. :D

@Anush: It is fixed now. Thanks for pointing out my mistake :)

This seems to be incorrect (because Arnauld's answer was incorrect until the recent fix).

@Anush: Yes, this had the same issue, which should now be fixed.

I'm a bit confused that you had to fix it, because when I tried to check my test case on all the answers with TIOs, the 05AB1E ones looked like they worked. Hm, trying the old TIO again it may be that your arguments are in the opposite order of what I thought.

Excel, 28 bytes
=B1^C1*LOG(A1)>E1^F1*LOG(D1)

Excel implementation of the same formula already used.

My understanding is that Excel has 15 digits of precision, so there may be cases where rounding result in this returning the wrong answer.

JavaScript, 51 bytes
f=(a,b,c,h,i,j)=>(l=Math.log)(a)*b**c-l(h)*i**j>1e-8

Surprisingly, the test cases doesn't show any floating-point error. I don't know if it ever does at this size.
This just compares the logarithm of the numbers.
Equality tolerance is equal to 1e-8.

Welcome to PPCG! Alas this does fail with my 2^3^12 == 8^3^11 test case. In fact your answer is very similar to the original answer by Arnauld (sadly deleted rather than fixed) that inspired most of those which failed it.

@Ørjan Johansen Moved l(h) to the right, and maybe it works now?
Edit: Wait, it doesn't.

Added equality tolerance 0.01.

I did a quick search and a tolerance should work, but this is a bit too high. The highest you need to exclude is (5.820766091346741e-11,(8.0,3.0,11,2.0,3.0,12)) (my test case), and the lowest you need to include is (9.486076692724055e-4,(17.0,19.0,1,3.0,7.0,2)) (3^7^2 > 17^19^1.) So something like 1e-8 should be safely in the middle and the same byte length.

@Ørjan Johansen Ok, thanks!

TI-BASIC, 27 31 bytes
ln(Ans(1))Ans(2)^Ans(3)>Ans(5)^Ans(6)(ln(Ans(4

Input is a list of length \$6\$ in Ans.
Outputs true if the first big number is greater than the second big number.  Outputs false otherwise.
Examples:
{3,4,5,5,4,3
   {3 4 5 5 4 3}
prgmCDGF16
               1
{20,20,20,20,20,19       ;these two lines go off-screen
{20 20 20 20 20 19}
prgmCDGF16
               1
{3,6,5,5,20,3
  {3 6 5 5 20 3}
prgmCDGF16
               0

Explanation:
ln(Ans(1))Ans(2)^Ans(3)>Ans(5)^Ans(6)(ln(Ans(4   ;full program
                                                 ;elements of input denoted as:
                                                 ; {#1 #2 #3 #4 #5 #6}

ln(Ans(1))Ans(2)^Ans(3)                          ;calculate ln(#1)*(#2^#3)
                        Ans(5)^Ans(6)(ln(Ans(4   ;calculate (#5^#6)*ln(#4)
                       >                         ;is the first result greater than the
                                                 ; second result?
                                                 ; leave answer in "Ans"
                                                 ;implicit print of "Ans"

Note:  TI-BASIC is a tokenized language.  Character count does not equal byte count.

I’m not that familiar with TI-BASIC, but this seems to be log(x) × y × z rather than log(x) × y ^ z. This won’t necessarily lead to the same ordering as the original inequality.

@NickKennedy Yes, you are correct about that!  I'll update the post to account for this.

Jelly, 8 bytes
l⁵×*/}>/

Try it online!
Based on Arnauld’s JS answer. Expects as input [a1, b1] as left argument and [[a2, b2], [a3, b3]] as right argument.
Now changed to use log to the base 10 which as far as correctly handles all the possible inputs in the range specified. Thanks to Ørjan Johansen for finding the original problem!

I believe this fails for 2^3^12 == 8^3^11.

Your Python TIO is incorrect.. You have 8* instead of 8**. @ØrjanJohansen is indeed correct that 2**(3**12) > 8**(3**11) is falsey, since they are equal.

@KevinCruijssen oops. Yes they are indeed equal. The reason the original two are marked as different relates to floating point error.

bc -l, 47 bytes
l(read())*read()^read()>l(read())*read()^read()

with the input read from STDIN, one integer per line.
bc is pretty fast; it handles a=b=c=d=e=f=1,000,000 in a little over a second on my laptop.

I love a bc answer! Just need one in bash now :)

C++ (gcc), 86 bytes
Thanks to @ØrjanJohansen for pointing out a flaw in this and @Ourous for giving a fix.
#import<cmath>
int a(int i[]){return pow(i[1],i[2])/pow(i[4],i[5])>log(i[3])/log(*i);}

Try it online!
Takes input as a 6-integer array. Returns 1 if \$a^{b^c} > d^{e^f}\$, 0 otherwise.

The formula after taking log twice should be i[2]*log(i[1])+log(log(*i)). E.g. the current one will fail for 2^2^20 > 4^2^18.

@ØrjanJohansen: good catch! I guess I have to use the pow method then.

The alternate one has the 2^3^12 == 8^3^11 problem I've pointed out for others.

@ØrjanJohansen: well, I guess I'm using your fixed formula then.

Oh, I'm afraid that formula is only mathematically correct. It still has a floating point error problem, just with a different case, 2^3^20 == 8^3^19. In fact on average the power method fails for fewer, probably because it tends to multiply by powers of two exactly. Others have managed to make it work by just tweaking it slightly.

You can use this for 86 bytes

@Οurous: thanks for the fix! updated.

Suggest int*i instead of int i[]

APL(NARS), chars 36, bytes 72
{>/{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b}¨⍺⍵}

Here below the function z in (a b c )z(x y t) would  return 1 if a^(b^c)>x^(y^t) else would return 0;
test
  z←{>/{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b}¨⍺⍵}
  3 4 5 z 5 4 3
1
  1 2 3 z 3 2 1
0
  3 6 5 z 5 20 3
0
  20 20 20 z 20 20 19
1
  20 20 20 z 20 20 20
0
  2 2 20 z 2 20 2
1
  2 3 12 z 8 3 11
0
  1 20 20 z 1 1 1
0
  1 1 1 z 1 20 20
0
  1 4 5 z 2 1 1
0

{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b} is the function p(a,b,c)=log(log(a))+c*log(b)=log(log(a^b^c))
and if aa=a^(b^c) with a,b,c >0 and a>1 bb=x^(y^t) with x,y,t >0 and x>1  than
aa>bb <=> log(log(a^b^c))>log(log(x^y^t))  <=>  p(a,b,c)>p(x,y,t)

There is a problem with the function p: When a is 1, log log 1 not exist so I choose to represent that with the number -1; when a=2 so log log a is a negative number but > -1 .
PS. Seen the function in its bigger set in which is defined
p(a,b,c)=log(log(a))+c*log(b)

appear range for a,b,c in 1..20 is too few... If one see when it overflow with log base 10, the range for a,b,c could be 1..10000000 or bigger for a 64 bit float type.