text:
Is my OS 32-bit or 64-bit?
It's not too important anymore, but occasionally somebody needs to know.
Here is a simple golf: Taking no user input, tell me if the computer on which the code is run is on a 64-bit operating system, or a 32-bit operating system!
If the code is run on a 32-bit operating system, print "32", if the code is run on a 64 bit operating system, output "64". Important:  Print any other non-empty string of alphanumeric characters if it's neither 32 or 64 bit.
Please note that a 32 bit program running on a computer with a 64 bit operating system should output "64". You can assume that users will use 64 bit software whenever possible.
To be eligible for entry, your code must be able to run on Windows 4.10 or newer Microsoft supported Windows systems, and at least one flavor of Linux of your choosing (so long as that flavor is gratis). Compatibility mods can be installed, so long as the program still returns the right value.
The usual code-golf rules apply.
Note: If your  answer is only meant to print out 32 or 64, but not the alt case, I'll accept it, but it is not a competing answer.
I'll try and post some results of running these codes on different OSes later!

What does "You can assume that users will use 64 bit software whenever possible" mean?  What software are you referring to?

So "Please note that a 32 bit program running on a computer with a 64 bit operating system should output "64". You can assume that users will use 64 bit software whenever possible."
means that if the interprettor/compiler etc is is available in both 32 bit and 64 bit, then a 32 bit OS, will always run the 32 bit version of the interpreter/etc, and the 64 bit OS will always run the 64 bit interpreter/etc.
So worrying about the difference between the program being 32 or 64,  and the OS  being 32 or 64, is basically only a problem for  languages with only 32 bit implementations. Right?

"must be able to run on Windows 4.10 or newer" - logical OR (4.10 OR newer)?

Many solutions here would print "32" on a 64-bit OS if a 32-bit compiler was used to compile program. Is this OK?

What in the world is "Windows 4.10"? Does that mean Windows 98? Or does it mean Windows NT 4? What do you consider to be "newer" than that? This seems an exceptionally poorly thought-out challenge.

Is there anything neither 32-bit nor 64-bit? Are you talking about ARM?

What about a 32-bit operating system running on a 64-bit CPU?

@SIGSEGV there are loads of 8-bit embedded systems, and some old systems you might get a qualifying OS to run on.

Please note that your code running on non-binary systems still has to print a non-empty string.

@JonnyBest we need a "Try it online" for nonbinary decimal computer (MIX?)

There is no "official windows spec", and nobody refers to Windows 98 as being "Windows 4.10". You are literally the first. So maybe instead of trying to sound cool or official by using version numbers, you should just use the actual product name. By the way, Windows 9x was never available in a 64-bit build, so is it actually legitimate for me to submit an entry that runs only on Windows 98 and just returns "32"? Seems very unfair/unsporting/uninteresting, but would technically be allowed by your rules.

@CodyGray Re: an answer that only runs on Windows 98

Doesn't seem to apply, @Mego. That says "a language's features". Windows 98 isn't a language, it is a target platform condoned by the official rules of the challenge (which, because stated explicitly, seem like they would override any "loopholes forbidden by default" anyway).

@CodyGray That would still clearly be in violation of the spirit of the loophole. Besides, a program that only runs on Windows 98 wouldn't be valid: To be eligible for entry, your code must be able to run on Windows 4.10 or newer, and at least one flavor of Linux of your choosing (so long as that flavor is free).

You mean I can't write a challenge that has explicit provisions that override the default loopholes, @Mego? That isn't what "default" means. And yes, I'd have to also find a Linux distribution that was 32-bit only and free. Or, I'd pick a free Linux distro that is 64-bit only (and there are a bunch of 'em), then the challenge is just detecting whether Linux or Windows. That goes beyond the point my original comment was trying to make, which is: why specify a family of 32-bit only operating systems as an acceptable minimum target, when the challenge is to detect bitness? Seems nonsensical.

You still haven't answered the question about the Windows version. Does must be able to run on Windows 4.10 or newer mean on Windows 4.10 and all newer versions or on any single Windows version, 4.10 or newer?

@CodyGray The "Windows 98 Resource Kit" published by Microsoft Press in 1998 refers to windows 98 as 2 different releases, depending on the year. 4.10.1998 and 4.10.2222. I omitted the last part as I didn't think it would matter.

I'm not sure why you have an OS restriction at all, but requiring answers to work on Windows 98 would probably invalidate most of the answers.

There's really no point in including Windows 98 in the mix. It didn't have a 64-bit version anyway and, more importantly, nobody has it anymore and testing whether an answer is valid or not becomes that much harder. The verifiability issue persists, to a lesser degree, for Windows XP (16 years old) and Vista (nobody liked it in the first place).

@LyndonWhite correct.

@tuskiomi maybe you could  add something more explict, like in my comment to the question then. You can see in lots of comments that there is lots of confusion about this.

@SIGSEGV the PowerMac G4 had a 128bit processor.

As soon as you add the "print something" requirement, you essentially rule out OS-independence apart from scripting languages, but then it seems that most of the answers don't handle the "neither 32- nor 64-bit" case because the corresponding language doesn't exist on those platforms anyway.

x86 Assembly (polyglot), 13 bytes
Bytecode:
31 c0 b4 80 48 70 05 04 40 83 e0 60 c3

Defines a function which returns 32 if interpreted as 32-bit, 64 if 64-bit, and 32767 if 16-bit.
I wanted to make a polyglot which ran on Windows and Linux, but this is a lot harder than I thought. As it is I'm not sure there's even any way to print a value on non-16-bit Windows without linking.
Explanation
This code uses two tells to determine the architecture it is running on. The first is the instruction 0x48—on 16 and 32 bits, this is dec %eax, but on 64 bits, it is an instruction-size prefix. The second tell is the same instruction, however, when we execute it on the value 0x8000, the most significant bit is flipped only if the register size is 16 bits, setting the overflow flag and letting us use jo.
In 16 bits, this code is interpreted as the following:
   0:   31 c0                   xor    %ax,%ax    /* 0x0000 */
   2:   b4 80                   mov    $0x80,%ah  /* 0x8000 */
   4:   48                      dec    %ax        /* 0x7fff */
   5:   70 05                   jo c              /* taken  */
   7:   04 40                   add    $0x40,%al
   9:   83 e0 60                and    $0x60,%ax
   c:   c3                      ret               /* 0x7fff */

In 32 bits, this code is interpreted as the following:
   0:   31 c0                   xor    %eax,%eax   /* 0x00000000 */
   2:   b4 80                   mov    $0x80,%ah   /* 0x00008000 */
   4:   48                      dec    %eax        /* 0x00007fff */
   5:   70 05                   jo c               /* not taken  */
   7:   04 40                   add    $0x40,%al   /* 0x00007f3f */
   9:   83 e0 60                and    $0x60,%eax  /* 0x00000020 */
   c:   c3                      ret

In 64 bits, this code is interpreted as the following:
   0:   31 c0                   xor    %eax,%eax   /* 0x00000000 */
   2:   b4 80                   mov    $0x80,%ah   /* 0x00008000 */
   4:   48 70 05                rex.W jo c         /* not taken  */
   7:   04 40                   add    $0x40,%al   /* 0x00008040 */
   9:   83 e0 60                and    $0x60,%eax  /* 0x00000040 */
   c:   c3                      ret

This is actually probably in the lead, very nice

A very neat idea, but as implemented, this will return the wrong value if assembled as a 32-bit binary and run on a 64-bit operating system.

@CodyGray from the rules: You can assume that users will use 64 bit software whenever possible. I suppose this also means that for functions we can assume that the caller code is 64 bit whenever possible.

Ah, I suppose that's a fair interpretation, @Ruslan. And I see you have already posted the answer I had in mind, were it not for this issue. :-) You've got my upvote.

does the byte 48 represent dec %eax in 16-bit mode?

@LưuVĩnhPhúc Fixed, thanks.

Can't edit because it would be too short, but there is a typo in the second listing offset 7, the result of the addition is 0x803F

@SamuelPeter shouldn't be, we're only adding to %al not %eax (which is necessary because adding to %eax would take an extra byte)

Why not B8 40 00 40 C3 48 24 60 98 C3 (MOV AX, 40H/INC AX/RET,MOV AX,0C3400040H/DEC AX/AND AL,60H/CWDE/RET,MOV AX,0C3400040H/AND AL,60H/CWDE/RET

x86 machine code, 12 bytes
8c c8 83 f8 23 b0 20 75 02 00 c0 c3

Ungolfed:
getKernelBitness:
    mov eax,cs
    cmp eax,0x23 ; 32 bit process on 64 bit kernel has this selector in CS
    mov al,32
    jne kernelIs32Bit
    add al,al    ; return value in eax
kernelIs32Bit:
    ret

This function works in Linux when used in ELF32, following i386 SysV ABI, as well as in Windows/Wine when used in PE32, following stdcall calling convention.

Actually one can reduce byte count even more if following another approach.

what would this theoretically do in a non 32/64 bit environment?

@tuskiomi In any case, this code will still return either 32 or 64. The only difference of interpreting this byte sequence in 16-bit mode will be a change of mnemonics from eax to ax. So, if the selector in cs happens to be 0x23, the result will be 64, otherwise 32.

this looks specific to two particular operating-systems, though.  You could easily have a 32-bit system with cs=0x23.  See instead my 8-byte answer that targets the CPU instead.

@peterferrie yeah, that's why I have another answer. But yours does outgolf it by 2 bytes.

Mathematica, 17 bytes
$SystemWordLength

Of course there's a builtin! \s (+1)

Shouldn't you either add an & or specify that this is in the REPL?

@LegionMammal978 "If the code is ran on a 32-bit operating system, print "32", if the code is ran on a 64 bit operating system, output "64". Print any (other) non-empty string of alphanumeric characters if it's neither." Not "provide a function that, when run, does this"; just "do this".

@PatrickStevens: If the question doesn't specify what form a submission should take, it's a program or function, but not a snippet, by default.

@ais523 I would argue there is no distinction in Mathematica between programs, functions, and snippets. Everything is just an expression.

@ngenisis: Sure there is. Can you apply it to arguments? If not, it's not a function. Does it take input in its own right from the user, standard input, etc.? If not, it's not a full program. (In fact, the fact that Mathematica allows you to export files that anyone can view using a separate viewer program makes it quite clear that full programs exist, and that they're different from arbitrary expressions, because in that situation a snippet wouldn't be able to take input at all.)

@ais523 I made a meta post for us to discuss this further, as this is something that's bugged me for a while. IMO, this is a full program, not a snippet, and it outputs via its return value.

@PatrickStevens Functions may return a function that returns the result.

Julia 14 13 bytes
n->8sizeof(1)

Explain:

Anon function, taking anything (including nothing) returning an integer 32, or 64
Integer literals are of type Int which depending if 32 bit or 64 bit, is either an Int32 or an Int64 (the 1 could be any digit)
placing a number before a function call does a juxtaposition multiplication
This is basically a minified version of the code for Sys.WORD_SIZE, used in rahnema1's answer

Other fun answer is ()->"$(Int)"[4:5], but I can't get the count down on that one.

-1 thanks to @Roman Gräf

You could use a dummy argument: https://codegolf.meta.stackexchange.com/a/12696/56341

Boot Loaders
Did you know that GRUB and IPXE both have Turing complete programming languages accessible at run-time? The Syslinux family of boot loaders don't but they can do this.
IPXE, 36 bytes
#!ipxe
cpuid --ext 29 && echo 64 || echo 32

the first line is needed if the script is run remotely, but not if typed directly at the command line.
GRUB, 42 bytes
if cpuid -l ; then
echo 64
else
echo 32
fi

Syslinux, 186 bytes
This takes three files the first is syslinux.cfg (or isolinux.cfg, etc.).
label a
  kernel ifcpu64.c32
  append s -- t

label s
  kernel menu.c32
  append s.cfg

label t
  kernel menu.c32
  append t.cfg

default a
prompt 0
timeout 0

and t.cfg
menu title 32

ans s.cfg
menu title 64

For this one the hard part is that syslinux does not have any simple text display capabilities, so the menu is abused.

I'm not sure if you can tell the os resolution with a boot loader,  but i like the idea

It checks the cpu and is used to select the right operating system. This is basically golfed code from my unboot project.

So it changes the os based on the architecture.  Thinking outside the box.  I like.

What's the bytecount?

@Restioson, which one? The best is ipxe with 36.

@hildred could you add them as a table or something?

@Restioson they are right after the name of the boot loader, although I don't know if there should be a penalty for multiple files for syslinux.

@hildred I believe it would be more readable if you used ## iPXE, 36 bytes instead of ### ipxe 36

@hildred oh haha I read that as a version number

Should "turning complete" be "turing complete"?

@styfle, possibly. My spelling is so bad I learned to spell with the help of gcc.

julia, 20 17 16 bytes
n->Sys.WORD_SIZE

*Thanks to @LyndonWhite saved 3 bytes
*Thanks to @RomanGräf saved a byte
Previous answers:
()->Sys.WORD_SIZE
print(Sys.WORD_SIZE)

Try it online!

I, personally, like this one!

By following convention: https://codegolf.meta.stackexchange.com/q/2419/62131
you can shave off 3 bytes by doing ()->Sys.WORD_SIZE

You could also use a dummy argument: https://codegolf.meta.stackexchange.com/a/12696/56341

JavaScript (Node.js), 24 bytes
_=>process.arch.slice(1)

This is a function and returns '32', '64', or if neither 'rm'.

+1, but I suppose a 64bit arch could be running a 32bit OS though

Gives me '32' on 32-bit Windows, so it does appear to work.

You can shave off 7 bytes if you're using the REPL and os instead of process: os.arch().slice(1)

This returns the OS architecture reported to the process, not the actual OS architecture. So this does not work on Linux. (Punch "setarch" into your favorite search engine.)

@DavidSchwartz it works fine on my linux box unless I'm misunderstanding, but on PPCG we can assume an unmodified environment in terms of user changing the arch

@Downgoat But there seem to be specific rules here that override that general assumptions permitted. "Please note that a 32 bit program running on a computer with a 64 bit operating system should output "64". You can assume that users will use 64 bit software whenever possible." (Which, honestly, I'm having a hard time making sense of.)

C, 33 31 29 23 bytes
f(){return sizeof&f*8;}

Thanks to commenters @ceilingcat and @Dennis for golfing tips!

No need for printf, you can simply return the integer.

@Dennis the challenge specifically says"print" in the OP

It also says that the usual code golf rules apply, and returning from a function is part of our defaults for I/O.

@Dennis Well in that case thanks for the tip!

Isn't that going to depend on whether you compile as a 32 or 64 bit program?

@KenY-N, you're right; this returns 32 when compiled with the -mx32 option in gcc. x32 mode is only available on x86_64 processors.

it also won't work if CHAR_BIT != 8

Since this only needs to work on some systems, can you just assign the result to a variable (so it's on top of the stack) instead of returning it?

This doesn't comply with the requirements. "Please note that a 32 bit program running on a computer with a 64 bit operating system should output "64"." This tells you how the program was compiled, not what the OS is.

@DavidSchwartz "You can assume that users will use 64 bit software whenever possible."

Sorry to say that but sizeof is evaluated at compile time. So if you compile a 32 bit exe and run it on a 64 bit machine, it will ouput 32 while it should output 64 (https://stackoverflow.com/questions/2615203/is-sizeof-in-c-evaluated-at-compilation-time-or-run-time). Nice idea though !

Python 2, 52, 48, 42 41 bytes
from struct import*;print calcsize("P")*8

Thanks to totallyhuman!

zoom! across the line in under a minute.

I'm going to hold off on testing this until i'm home, but i'm not sure this prints out "32" and "64", but other cases i'm confident.

@tuskiomi, this prints "32bit" or "64bit"

ahh, may want to wrap that in a left([arg],2) operator :-)

@tuskiomi done :)

I think __import__ will be shorter

@shooqie, thanks! I thought about doing that but for some reason I thought it would be longer. Luckily I was wrong

from struct import*;print calcsize("P")*8 is shorter.

If you run this on 32-bit Python in a 64-bit OS, I think this will lie to you. Most other answers also seem sensitive to that anyways...

As far as I can see, this gives a wrong result when running as a 32-bit binary on a 64-bit OS since it's calculating the pointer-size, which is 32 bits.

@NickT I confirm that it DOES lie!

Not sure what the protocol is, but I have an alternate solution (with the same weakness; it identifies the interpreters bittedness, not the OS's directly) that shaved off another 13 bytes.

Java 8, 45 bytes
()->System.getProperty("sun.arch.data.model")

@Dopapp What (s)he means is that this is a snippet, not a program or function. In Java 8, this should work: n=>System.getProperty("os.arch")

@NoOneIsHere, oh thank you that went way over my head

Ok, this works now. Just mention that it uses a null parameter n.

@NoOneIsHere, I thought lambdas were ->, so it would be n=()->...?

@Dopapp afaik it's ()-> or something like that in Java, _=> is JavaScript

@StephenS, yeah that's what I though. Oh well, it's just one byte more.

@Dopapp You can do n-> to save a byte, just mention it's a null parameter. n-> should work in Java too. I'm just not a Java programmer, so I am endlessly failing to compile the program.

@NoOneIsHere, are you sure that that is a thing in Java? I have never seen n like that in Java (granted I don’t use Java that much). I’ll check when I get back to a computer.

@Dopapp https://stackoverflow.com/a/25055739/4807393. I know I chose a bad answer, but the code uses e -> { sum += e.size(); }

"If the code is ran on a 32-bit operating system, print "32", if the code is ran on a 64 bit operating system, output "64". Print any (other) non-empty string of alphanumeric characters if it's neither.". This doesn't do that at all...

By the way, the code as written now (()->System.getProperty("os.arch")) is a valid syntax. It just doesn't do what is expected (printing "32", "64" or any other non-empty string).

Oh, and "sun.arch.data.model"returns exactly what is needed. Put it in a lambda for full correct stuff: ()->System.getProperty("sun.arch.data.model") (45 bytes). Codegolf doesn't require your answer to be fully portable: only that it works on some systems. So just a word saying it only works on Oracle JDK is enough. I don't think you'll be able to give a proper answer in less bytes using "os.arch".

@OlivierGrégoire, ah so the first version did work! Thanks for your diligence!

Can you get Java 8 for Windows 98 (v4.10) ?

@TessellatingHeckler Java 8 requires "i586" (whatever that means). The entry says: "your code must be able to run on Windows 4.10 or newer", not "your code must be able to run on Windows 4.10 and newer". It runs on a Windows newer.

@OlivierGrégoire It doesn't do what's needed. It reports the OS architecture provided to this process, not the actual, native OS architecture. These are not always the same on Linux. (Punch "setarch" into your favorite search engine.)

PowerShell, 16 bytes
8*[IntPtr]::Size

Gets the pointer size in bytes, multiplies by 8 to get bits.

-1 because your code must be able to run on Windows 4.10 or newer

@ub3rst4r or newer, not and newer. I'm willing to bet a good chunk of these answers are difficult, at best, to run on a long-unsupported version of Windows. It's also unreasonable to expect people to test on 98 of all OSes - it's not even easy to install in a VM these days (trust me, I've tried. Not gonna run on KVM, and it has interesting interactions with VBox display adapters). (Nor does it even have a concept of 64-bit... that's a truly ridiculous requirement.)

@ub3rst4r I doubt that all of the interpreted programming languages here have an implementation working on Windows 4.10!

This looks like it fails if it's a 32-bit powershell on a 64-bit OS.

@ChrisJ At least on Win10 and Win2012 R2 it returns the proper result from x86 PowerShell. Haven't tested on Linux.

@BoogaRoo - I don't get that on Win10 x64 with x86 PS: [environment]::is64bitoperatingsystem returns true; [environment]::is64bitprocess returns false; 8*[intptr]::size returns 32. Wonder if PS version matters (although I think 10 comes with v5 regardless).

Does this work in Linux?

Perl 6, 17 bytes
say $*KERNEL.bits

Try it

There is a related $?BITS which contains the number of bits that a native int has in the runtime.
say $?BITS

Try it

Windows CMD, 56 52 bytes (thanks Bob!)
if EXIST "%ProgramFiles(x86)%" (echo 64)else echo 32

Still surprisingly lengthy - longest so far!

I think you can actually get it shorter by checking for the existence of %ProgramFiles(x86)%

@Bob that didn't work! echo %thisdoesntexist% echoes %thisdoesntexist%, and DEFINED or EXISTS is longer than the ==x86.

You're forgetting the length of the variable itself. %ProgramFiles(x86)% is shorter than %PROCESSOR_ARCHITECTURE%. Also, the second set of parentheses is unnecessary.

Ahh, oops! Indeed I am. Let me update.

Actually, %windir%\SysWOW64 is even shorter, I think...

We probably need quotes around %windir%, though, just in case it is installed to c:\W I N D O W S, taking us back to 52.

if EXIST %windir%\SysWOW64 (echo 64)else echo 32 -- you could in theory check other files or shorten further with wildcards like %windir%\*64 but I feel that might be a bit too localised..?

I think assuming %windir% is C:\Windows is perfectly safe and allowed. There's a certain amount of assumptions allowed in codegolf, and a default OS install should be included :) I've also not heard of being able to change the Windows install directory since the days of 9x. But even if you insist on quotes, it's still shorter than %ProgramFiles(x86)% by 2 chars.

"must be able to run on Windows 4.10 or newer, and at least one flavor of Linux of your choosing" - which flavour of Linux for this?

@TessellatingHeckler if you install Wine...?

What about using shorthand? if EXIST "c:\Progra~3" (echo 64)else echo 32 By default you have ProgramData and Program Files so if a third exists, we should be 64

@Marie, only problem with that is if I make a directory called "ProgramsInAnotherFolder" on 32-bit Windows…

Bob's suggestion to use %windir%\SysWOW64 seems fine. We can assume %windir% doesn't have spaces or special characters, because otherwise, so many other things would break on the system. Thus, we shorten from 52 to 48 bytes.

What will this print for an 8-bit OS?

@TessellatingHeckler Works fine in the Ubuntu flavour, if you use the SysWOW64 detection: https://gist.github.com/BobVul/5e5022d5b62b9ef39d149a595ab338a6 -- added bonus, the 32-bit WINE on 64-bit Linux still prints 64 just as it would in Windows, and correct according to question spec.

Instructions unclear, 'echo' is not recognized as an internal or external command, operable program or batch file.

@Jase Doesn't the same problem manifest with the posted solution if you were on Win32 and had created a folder called "Program Files (x86)"?

Hey, how about "%ProgramW6432%" instead of %windir%\SysWOW64? Saves one byte.

"%ProgramW6432%" doesn't exist in Windows XP. But it saves one byte!

@tjbtech yep, definitely. I was just pointing out that this answer relies on the  root drive only containing the default Windows folders.

Ruby, 22 bytes
p [?a].pack(?p).size*8

["any string"].pack("p") returns a string whose bytes correspond to the pointer that pointed towards "any string", and is 8 characters if the OS is 64-bit, or 4 characters if the OS is 32-bit.

Since this is using the pointer size, this will print 32-bit when the Ruby interpreter is a 32-bit binary on a 64-bit OS. So misses a rule.

@DarkDust You can assume that users will use 64 bit software whenever possible. So 64-bit users will be assumed to be running 64-bit Ruby.

C#, 60 50 bytes
_=>System.Environment.Is64BitOperatingSystem?64:32

Thanks @TheLethalCoder

Welcome to the site! :)

Save 4 bytes if you remove 'Line'

can also remove 'Environment.' and 'console.' assuming use of using static System.Environment; and using static System.Console;

also, change WriteLine to Write

@John Last time I checked, imports must be included and so would add to the byte count

This is a code snippet and you should add in using System; as well. However, if you compile to an anonymous method you can get it to 50 bytes: _=>System.Environment.Is64BitOperatingSystem?64:32

@TheLethalCoder Thanks!

C, Win32 API, 103 183 bytes
#include <windows.h>
typedef int(WINAPI*F)(HANDLE,int*);b;main(){F f=GetProcAddress(GetModuleHandle("kernel32"),"IsWow64Process");return(f!=0&&f(GetCurrentProcess(),&b)&&!b)?32:64;}

Actually there are more than 2 cases here. Let's examine them

The easiest: IsWow64Process does not exist: We are on a 32 bit OS

For the next two cases we need to have the knowledge that our binary will be a 32 bit executable. And this description of what will be out into the out parameter of IsWow64Process

A pointer to a value that is set to TRUE if the process is running under WOW64. If the process is running under 32-bit Windows, the value is set to FALSE. If the process is a 64-bit application running under 64-bit Windows, the value is also set to FALSE.

That leaves us with two additional cases:

IsWow64Process exists, and yields TRUE -> We are on a 64 bit machine
IsWow64Process exists, and yields FALSE -> We are on a 32 bit machine

We don't wory about the part where a 64-bit application on a 64-bit Windows yields FALSE. As we know that our application is 32-bit
Oh and there is one additional case that is not covered by this challenge and should be rare anyways:

IsWow64Process exists, but it fails: We default to 32-bit machine.

This should cover most Windows NT Operating Systems. Have only tested on Win10 64-Bit, Win 7 64-Bit, Win 8.1 32-Bit and WinXP SP1 32-Bit

Original answer:
#include<windows.h>
main(){return GetProcAddress(GetModuleHandle("Kernel32"),"IsWow64Process")?64:32;}

To be sure we need to distinguish only 2 cases

IsWow64Process does not exist in kernel32.dll => We are on a 32 bit machine.
IsWow64Process does exist => We are on a 64 bit machine.

The actual value provided by IsWow64Process is irrelevant for this challange, since we want the binary to be 32bit in any case.
Unlike most of the answers, this doesn't rely on the binary itself being compiled on the machine that it's executed on.
If I knew a shorter function that is present only on 64bit and not 32bit machines, I could shorten the answer.

Drop the .dll from the module name string. Not only is this good for golfing, but it's actually a better practice in normal use, too. Also, for golfing purposes, you can drop the space after #include.

Thanks, I actually wanted to reduce the whole thing by just looking for a module that can be found on 64bit but not on 32bit. I'm still looking. Sadly (for this purpose) there is no module called WoW64.

There is actually a wow64.dll and Wow64Win.dll, but I have never tried to call GetModuleHandle with those. The problem, though, is that they would only be loaded for a 32-bit process running on a 64-bit machine, not for a 64-bit process running on a 64-bit machine.

I have. They return 0 even on a 64bit machine. Makes sense actually. They don't exist to be linked with directly. The system takes care of the redirection during runtime.

Ooh, problem though. From the SDK documentation: "Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function."

I had feared that. I was however convinced by some post on SO, that it will never be found on a 32bit machine. Ok, now I will have to call the function itself.

Probably an old post that you found on SO. I would have thought it wasn't on 32-bit systems, either, but my experience on this is all pretty old. Windows 8 changed a lot of things, and 10 changed even more. Calling it is going to be a lot more difficult and really ratchet that byte-length up. Perhaps better off checking for environment variables, or the existence of a "Program Files (x86)" folder. Or, maybe limit yourself to a particular, older version of Windows where this isn't there in 32-bit builds, like Windows XP? Unclear to me from the challenge whether this is OK.

Let us continue this discussion in chat.

but which linux is this compatible with?

None. At least not natively. Maybe with wine. Hi ever I don't know whether eine reflects the bigness of its host system or its own...

R, 16 bytes
.Machine[[18]]*8

Returns the pointer size.

Like all pointer-size solutions, this will print the wrong result when the program is a 32-bit binary running on a 64-bit OS.

@DarkDust R is interpreted, and we can assume the user uses 64-bit software where possible, so also a 64-bit interpreter. IMHO, the rule only applies to compiled languages

@NieDzejkob That is the exact same logic I have used for my answer in PHP when someone else put the same type of comment in response to my answer, I wish others read the same from the question as we have on assuming users will use 64-bit software where possible with interpreted languages.

Perl, 18 15 18 bytes
say length pack p8

I get 64␤ on my 32 bit computer, because perl was built with a 64bit IV. You'll find this is usually the case when running on 32bit version of Windows.

@BradGilbertb2gills I reverted the code to the previous version; this one should work even in this case. Let me know if it still doesn’t work, I’ll delete my answer.

That works correctly.

Seems wrong on HP 9000/785. Gives 32. But I do not think there were any 32-bit HP/PA-RISC CPUs.

x86 machine code, 8 bytes
31 C0 B0 40 48 24 60 C3

Ungolfed:
31 c0    xor eax,eax
b0 40    mov al, 0x40
48       dec al — in 32-bit mode; "REX.W" in 64-bit mode (ignored)
24 60    and al, 0x60
c3       ret

If compiled as a 64-bit executable, it returns 64 in eax, and if compiled as 32-bit, then returns 32 — regardless of the OS.
This answer relies on the rules saying:

You can assume that users will use 64 bit software whenever possible.

While this is an interesting approach, how can it be written into a program in such a way that it can actually be executed?  Every method I can think of executing binary code other than writing your own loader function uses files that are specific to 64-bit or 32-bit code.  Therefore, you'll need two copies of this code in order to actually run...

@Jules You can put it as inline assembly into a high-level language program, like here. Then you just need to use your platform-native compiler with its default options, and you'll get the bitness.

PHP, 18 Bytes
<?=PHP_INT_SIZE*8;

This correctly handles all of the cases of 32, 64 and other bit CPUs provided that PHP_INT_SIZE is correct, it will show the precise size of the CPU no matter what CPU PHP is running on!
If PHP is running on
32-bit OS PHP_INT_SIZE == 4,
64-bit OS PHP_INT_SIZE == 8,
16-bit OS PHP_INT_SIZE == 2 (theoretically)
8-bit OS PHP_INT_SIZE == 1 (again theoretically)
128-bit OS PHP_INT_SIZE == 16 (Not yet achieved but possible)

that constant has the size of the OS where PHP was built, not run

@Einacio Yes, but in the initial challenge the poster wrote "You can assume that users will use 64 bit software whenever possible", Therefore if the OS is 64-bit then the version of PHP running on the OS would have to be assumed to be 64-bit! (Note: I don't see this as a loophole just pure logic based off of the initial challenge.)

Shell, 26 bytes
uname -m|awk \$0=/_/?64:32

You can use arch instead of uname -m.

@Dennis Not necessarily. On macos: uname -m -> x86_64, but arch -> i386. Because macos :(
Also, this is bash-specific - fails on zsh.

@StevenPenny zsh will try to interpret the ? as a glob / single character wildcard.

Does this run on Windows?

@viraptor this is Code Golf, not a portability competition. As long as it works on Windows and at least one free Linux distribution, as the rules say, it is OK. Otherwise I could just as easily run it with linux32/setarch i386 command and break it.

@Ruslan I get it, but that's no reason not to fix simple things (rename shell -> bash)

@viraptor this works in dash and BusyBox's sh too, for example.

C, 22 bytes
f(){return(int**)0+8;}

This is a pointer-size based answer that assumes a native binary. The 0 is cast to int** (address 0x0). Then we add 8 to 0, which, in C advances, the pointer by sizeof(int*)*8. 4 bytes * 8 bits = 32, 8 bytes * 8 bits = 64. So we get (int**)0x20 and 0x40 which are then implicitly cast as integers by returning them from an implicitly int-returning function.
C, stand-alone, 34 bytes
main(){printf("%d\n",(int**)0+8);}

C, fun with Unicode, 30 code-points, 34 bytes(UTF-8)
main(){puts((int**)U" ㈳㐶"+1);}

I've been trying to understand how this works, but I'm clueless. Can you add an explaination?

@jbcreix clever...

C# (29 bytes)
Console.Write(IntPtr.Size*8);

Like all pointer-size solutions, this will print the wrong result when the program is a 32-bit binary running on a 64-bit OS.

Need to specify that this is compiled for "AnyCPU" with the "Prefer 32-bit" checkbox unchecked.

PowerShell, 17 52 bytes
try{32+32*((gci \*`))-or(arch)[-1]-eq52)}catch{32}

Returns 64 if either of the following is true:

You have a directory on your current drive with a filename ending in a close paren, the idea being to detect Program Files (x86).
arch returns a string ending in 4 (ASCII 52), like x86_64, as opposed to e.g. i686.

The try-catch is intended to circumvent the error you get if gci returns nothing and you don't have an arch. I haven't found a shorter way to do it so far. gci is used over ls because on Linux, ls will produce a visible error.
This version should detect whether the OS is 64-bit rather than just PowerShell, and is tested to work on Windows and Linux. For Mac support, replace arch with uname -m.
Previous Windows-only version: -!(ls \*`))*32+64

what linux distro does this run on?

@tuskiomi Oh, my bad - I see what you mean. Didn't read the challenge properly. Should I delete the answer?

If you know it'll work with WINE, you should keep it.

@tuskiomi At the very least Ubuntu 14.04, 16.04, RHEL7, CentOS7 and some version of SUSE: https://github.com/PowerShell/PowerShell/releases/

Swift 4 REPL/Playground, 12 bytes
Int.bitWidth

Int is word sized, acting like either Int32 or Int64 depending on the system.

Isn't this a code-snip it, so it should print?
Or does saying you are using the REPL get around that restriction?

That's up to the judges. The REPL usage isn't very common, but Swift Playgrounds are very popular (especially on iPad). Personally, I think it's fair game. People design custom programming languages for golfing that implicitly print values, and this is no different

Bash, 25 17 bytes
getconf LONG_BIT

Thanks to Dennis for golfing help.

Ruby, 10 bytes
p 0.size*8

While Ruby can use integers of any length, internally it stores the values that fit in a machine word as Fixnum. The method Fixnum#size always return the length in bytes of a machine word.
The Fixnum class was removed in Ruby 2.4.0, its functionality was included in class Integer. The code stands.

Java, 50 bytes
int b(){return com.sun.jna.Native.POINTER_SIZE*8;}

Is that a library? If yes, you should mention it! I don't see that class available in the Oracle's JDK 8 though (I don't have my usual JDK 6 and 7 at my disposal, atm).

This answer is invalid. It doesn't print.

Quoting Dennis: > It also says that the usual code golf rules apply, and returning from a function is part of our defaults for I/O.

Change it into a lamba function for less bytes: ()->com.sun.jna.Native.POINTER_SIZE*8

PHP, 29 bytes
<?=@php_uname(m)[-1]-4?32:64;

https://3v4l.org/Y6JXv

Ooh. I like this one. How does it work?

php_uname('m') returns x86_64 on a 64 bit OS, otherwise something like i386. 4 being the 6th character (5th 0 indexed) of the string, '4' - 4 == 0 == false. And @ just suppresses warnings for unquoted strings, and uninitialised offsets.

This detects the architecture of PHP, not of the OS. I'm running 32-bit PHP on a 64-bit Windows, php_uname('m') returns 'i586'.

@GrasDouble well I guess ymmv, I works for me with Windows NT USER-PC 10.0 build 15063 (Windows 10) AMD64.

I'm also getting i586 on win8.1 x64 PHP 5.5, so it may be defaulting to PHP architecture on windows (php 5.x only had x32 builds on stable)

@tuskiomi this will print 64 if there is an 8-bit operating system

Won't 1<<32>1 work to detect if it is 32 bits or 64 bits?

Python 3, 77 84 71 59 bytes
-13 bytes, thanks to @JonathanAllan!
Down to 59 by @Clearer
from platform import*;print({'4':64,'6':32}[machine()[-1]])

Try it online!
My fist time code-golfing :)
Should output the correct version even when running 32Bit-Python on 64bit-OS.
Assuming platform.machine() gives i*86 or x86 for 32Bit-OS. I don't have one available to check this. Output is 0 when OS is not in 64/32Bit
Edit: Added print statement, so it got 7 bytes longer

Not sure if it's acceptable because it is possible to run a 32 bit OS on a 64 bit machine (or to have some machine called a foo86 that is 64 bit :p), but if it is acceptable then you can save 9  (edit ...13!) bytes with print((a==64)*a+32*(a==86)).

from platform import*;print({'4':64,'6':32}[machine()[-1]]) would work too.

@Clearer This would miss following constraint:
Important: Print any other non-empty string of alphanumeric characters if it's neither 32 or 64 bit..

@tOmAtE if it's neither 32 nor 64 bit, it will throw an exception, which prints a non-empty string.

To add to what @tOmAtE said, you could use get or: {'4':64,'6':32}.get(machine()[-1],"/") (/ just for nonemptiness). It's a bit lengthy though

Try architecture(), saves the dict: from platform import*;print(architecture()[0][:2]) -> 50 bytes

C, 36 bytes
Note that the following program will need to be compiled on the system to be tested.
main(){printf("%u",8*sizeof(int*));}

Simple. Assumes that the machine's word length is the same as the pointer size, which seems to be a valid assumption.
sizeof(int*) (or any other pointer type, for that matter), should be 4 on a 32-bit system, and 8 on a 64-bit one (and 2 on a 16-bit system). This should also the be the most portable of all the solutions given here till now - and work back to any system with a ISO C89 compiler.
The gotcha here is that this program must be compiled for every system which it needs to be run on, otherwise it'll output the bitness of the operating system it was compiled on.

Like all pointer-size solutions, this will print the wrong result when the program is a 32-bit binary running on a 64-bit OS.

@DarkDust, I did add a note about it saying how it needs to be compiled for each system it'll be run on. I won't bother improving my answer before l because it looks like DexterCD got it working with the runtime

Does it explicitly need to have the .c extension?

@Restioson I'm not sure, but I think it'll work with GCC without the extension. I'll keep the penalty in interest of portability.

@Foo, I realize your edit is in good intention, but you have misunderstood why I've allowed a byte count penalty - this question requires the program run on multiple systems - mine needs to be compiled on each system it runs on. Hence I accept a penalty for a non-conforming answer, and I've rejected your edit.

@TamoghnaChowdhury it is unnecessary to indicate a compilation penalty as it can generally be assumed that your code will be compiled and executed on the end computer

@TaylorScott, the compilation penalty has been imposed because the question states that the program will be run, not compiled and then run. It is reasonable to assume that one binary may be used without recompilation on different systems.

@TamoghnaChowdhury, i understand your point but it is moot, compilation does not, by default, ever count towards score, but rather only non-standard compilation flags (like -ansi or -p) add to the count. this is because compilers are not always standardized and not all languages have an explicit compiler

@TaylorScott Accepted. Edited out the compilation penalty.

J, 8 bytes
2^5+IF64

Alternatively, from the metal up (as opposed to using built-ins), 23 bytes:
2^5+1<224-~a.i.{.3!:1''

Based on the approach in the relevant RosettaCode task, as well as the underlying J documentation.
A version which would work on the theoretical, non-existent 16- or 128-bit J interpreters, provided they use the same code base, 11 bytes:
>:2^.|{.i:_j1

This works in both the real-life 32- and 64-bit J interpreters, and is a function of the implementation, not the specification.

What does this theoretically print on a 128 bit  os?

@tuskiomi The first, IF64 has boolean semantics. I doubt a theoretical 128-bit J interpreter would set IF64 to 2; they'd likely introduce a new global IF128. The bare-metal one has a better chance of generalizing to greater bit widths, but of course the current documentation doesn't say what the code will be for 128 bit OSes.

Ah.  Maybe a different output for 16 bit then?

@tuskiomi This particular puzzle makes it hard to answer theoretical questions confidently. The results of the expression are interpreter-implementation specific (per the rules in your question). We'd have to have the documentation for the 16-bit interpreter, which was never built, or the 128-bit one, which never may be.

tcl, 40
puts [expr 8*$tcl_platform(pointerSize)]

demo
I think I can golf it using some bit-shift magic

I don't see a good way to make that shorter, other than assuming you're running interactively (which could let you drop the puts [...] wrapper.

You can probably do $tcl_platform(pointerSize)<<3, but this is bigger. Disclaimer: I don't know TCL. It works in Python anyways :)

@Restioson: Yes, it is bigger. I was thinking about something like puts [expr -1>>31==1?32:-1>>63==1?64:0] , but it didn't work.

@sergiol sorry, I don't know TCL :p

@Restioson: no problem

Batch, 54 53 51 bytes
Not the shortest.
@if defined ProgramFiles(x86) (echo 64)else echo 32

This checks for a 64-bit system only variable. If the variable exists, then return 64. In any other case, it returns 32.
To make this work on Linux(assuming Ubuntu):

Install wine using sudo apt-get install wine
Run wine cmd in the terminal
Call the script: scriptname.bat

I get Can't recognize 'x86' as an internal or external command, or batch script. before wine cmd prints 64.

Weird.. did you use the same script I posted?

@Ruslan I've edited the script, please check does this works on 32 bit systems

No, still the same error message, and both current and previous versions output 64 on a 32-bit system.

@Ruslan Did you get the Can't recognize error message on Wine or cmd?

I saved the command to test.bat and ran wine cmd /c test.bat. I also tried simply running wine cmd and typing the string there, with the same result.

I assume this issue is caused by 2 problems. A: Wine can't handle if statement syntax properly. B: Wine does not come with the thing we need for the script to work.

You don't need the ()s around the echo 32.

PHP, 25 Bytes
<?=PHP_INT_SIZE==4?32:64;

That detects if PHP is 32 or 64 bit, not the OS.

this will print 64 if there is an 8-bit operating system

@tuskiomi Have you tried running PHP on an arduino lately (or any other 8 bit operating system (Yes I know an arduino isn't an operating system))?
I see it as: since PHP only runs on 32 and 64 bit CPUs then it doesn't matter that it prints 64 on a 8-bit operating system. +1 from me.

@Bja https://codegolf.meta.stackexchange.com/a/11355/60951 if only 32 or 64 bit systems are supported, it will never print the 3rd case.

@tuskiomi Sorry I didn't know about the loophole rules in codegolf, My mistake. I have deleted my other comments.

@Bja I am not expecting it to compile into 8-bit code, but that it should theoretically work if compiled for 8-bit machines.

@tuskiomi how about "<?=PHP_INT_SIZE==4?32:PHP_INT_SIZE==8?64:0;" as an answer (45 Bytes)

@Bja that's a valid competitive answer.

Javascript (ES6), 46 41 40 38 Bytes
-5 Bytes thanks to @GustavoRodrigues
-2 Bytes thanks to @GustavoRodrigues!
_=>/64/.test(navigator.userAgent)+1<<5

I was only able to test it on my Windows x64 machine, so any feedback will be much appreciated :)
Edit: removed the x from x64 to fix an issue pointed out by @ThomasAyoub, I don't know if this is going to cause any unexpected behaviour.

var c=
_=>/64/.test(navigator.userAgent)+1<<5

console.log(c());

From other answers I don't think you need to return a string, if so: _=>navigator.userAgent.includes\x64`+1<<5`

@GustavoRodrigues Clever approach! Thanks :)

Doesn't work on my laptop, it prints 32 instead of 64

@ThomasAyoub Could you please post your laptop's full navigator.userAgent string?

"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0" and here's a screenshot

@ThomasAyoub Thanks, updated!

How about using regular expressions? _=>/64/.test(navigator.userAgent)+1<<5

@GustavoRodrigues Edited! ty :)

Java 7, 77 71 bytes
A java pointer-size solution
void a(){System.out.print(Integer.toHexString(hashCode()).length()*8);}

x86 machine code, 8 bytes
Bytecode:
b0 40 33 c9 41 d2 e8 c3
which decodes to:
mov al, 64
xor ecx, ecx
inc ecx
shr al, cl
ret
The "inc ecx/shr al,cl" in 32-bit becomes "shr r8b,cl" in 64-bit, and returns either 32 or 64 in the AL register.

PowerShell, 51 44 43 bytes
-7 bytes thanks to Wasif Hasan
32+32*[Environment]::Is64BitOperatingSystem

Try it online!

Here you go, omit the System. and save 7 bytes!

APL (Dyalog), 20 bytes
Runs on Windows NT/CE, Linux, AIX, macOS and Solaris. Assumes exposure of root properties.
32×1+'6'∊⊃APLVersion

Try it online!
APLVersion (Target Environment, Version Number, Version Type, Program Type)
⊃ pick the first element (OSName[-64])
'6'∊ is six a member thereof?
1+ add one to that Boolean
32× multiply 32 by that

If root properties are not exposed, use ⎕WG'APLVersion' instead of APLVersion.

SAS, 28
%put%eval(&syssizeoflong*8);

Runs on any OS that supports SAS - there are many...

JavaScript, 26 34 bytes

console.log((
_=>/\d\d/.exec(navigator.oscpu)[0]
)())

Tested with Firefox. Not all browsers support the navigator.oscpu property.
Edit: rewrote my answer to comply with the specification. Thanks to Restioson for pointing out my error.

I thought that it had to print 64, 32, and a non empty string respectively?

VB.NET (Mono), 99 65 Bytes
Full subroutine and module which take no input and outputs if the OS is 64 bit or not to the console.
Module M
Sub Main
Console.Write(8*IntPtr.Size)
End Sub
End Module

Try it Online. Returns 64 as TIO is run on a 64 Bit Unix 4.11.3.202 server
-34 Bytes thanks to @Alexander
VBA, 41 Bytes (Non-Competing)
Anonymous VBE immediate window function that takes no input and outputs OS Version to the VBE immediate window
This only works on Windows as VBA cannot be run on Linux
?Val(Mid(Application.OperatingSystem,10))

This seems more preferable: IntPtr.Size*8 https://msdn.microsoft.com/en-us/library/system.intptr.size(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

@Alexander thanks! I had looked for an Intger Bitwidth myself but I never would have thought to use IntPtr

Python 2.7, 49 bytes
from platform import*;print architecture()[0][:2]

TXR Lisp, 16 bytes
(*(sizeof val)8)

Same for long or cptr instead of val; but those are one character longer. val is the FFI type denoting a raw Lisp value. That corresponds to a pointer, whose size usually determines the "bitness" of a system.

Go, 94 bytes
package main;import"fmt";const wordsize=32<<(^uint(0)>>32&1);func main(){fmt.Println(wordsize)}

Perl 6, 17 bytes
say $*KERNEL.bits

Powershell, 56 bytes
$null=$env:Processor_Architecture-match"\d+";$matches[0]

Your code works with windows only :) You can save some bytes ls env:p*e|% v*|sls '\d+'|% m*|% v*

But @mazzy if something other exists such as pae or anything between p and e, let's try to be fool proof

Powershell, 47 bytes
(32,64)[[Environment]::Is64BitOperatingSystem]

Basically, it's an array that's indexed into by the truthy value returned by the environment.
This avoids the pointer methods, so will correctly identify the bitness of the OS rather than the bitness of the process.
Appears to work on Windows and Linux.

Wait, Powershell on Linux?? Sign me up!  But really, did you just paste this into the shell or what?

Yes - see https://github.com/PowerShell/PowerShell/blob/master/README.md (packages for Ubuntu, Debian, Redhat, etc, all from the Microsoft PS team); and yes - just pasted into the shell.

this will print 32 for an 8-bit os, no?

@tuskiomi - an 8-bit OS isn't one of the target systems according to the rules (at least a supported Windows and a Linux distribution of choice)

@ChrisJ agreed, but it does need an alternate case for non 32/64 bit systems in order to be competitive. Still valid though.

@tuskiomi I don't quite get what you mean by an alternate case. Do you mean that the program should determine all the possible bitnesses beyond 32 and 64? This doesn't seem to have been specified in the rules.

@ruslan from the main post: Important: Print any other non-empty string of alphanumeric characters if it's neither 32 or 64 bit.


text:
Lyndon word factorization
Background
A Lyndon word is a non-empty string which is strictly lexicographically smaller than all its other rotations. It is possible to factor any string uniquely, by the Chen–Fox–Lyndon theorem, as the concatenation of Lyndon words such that these subwords are lexicographically non-increasing; your challenge is to do this as succinctly as possible.
Details
You should implement a function or program which enumerates the Lyndon word factorization of any printable ASCII string, in order, outputting the resultant substrings as an array or stream of some kind. Characters should be compared by their code points, and all standard input and output methods are allowed. As usual for code-golf, the shortest program in bytes wins.
Test Cases
''           []
'C'          ['C']
'aaaaa'      ['a', 'a', 'a', 'a', 'a']
'K| '        ['K|', ' ']
'abaca'      ['abac', 'a']
'9_-$'       ['9_', '-', '$']
'P&O(;'      ['P', '&O(;']
'xhya{Wd$'   ['x', 'hy', 'a{', 'Wd', '$']
'j`M?LO!!Y'  ['j', '`', 'M', '?LO', '!!Y']
'!9!TZ'      ['!9!TZ']
'vMMe'       ['v', 'MMe']
'b5A9A9<5{0' ['b', '5A9A9<5{', '0']

Related

Note that this is equivalent to splitting by <=ness. (I have no idea how to express this better :| )

Is this equivalent to repeatedly taking the first character and the prefix of all characters bigger than it?

@xnor No. 'abac' is a Lyndon word.

@user1502040 I see, ties are interesting. I'd suggest adding some test cases that catch this.

@xnor Your proposed method can fail even when all characters are distinct. e.g. take the 'P&O(;' test case.

@user1502040 I think that one works. You first take the P, and the next character is smaller, so you just take P. Then, you take &, and the rest of the string is bigger than it, so you take all of &O(;.

@xnor Ah right, brain failure. I was thinking of monotonic substrings rather than just > the first character.

Pyth, 17 16 bytes
-1 byte thanks to isaacg!
hf!ff>Y>YZUYT+./

Try it online!
Explanation
hf!ff>Y>YZUYT+./
              ./    Take all possible disjoint substring sets of [the input]
             +      plus [the input] itself (for the null string case).
 f                  Filter for only those sets which
  !f        T       for none of the substrings
    f  >YZUY        is there a suffix of the substring
     >Y             lexographically smaller than the substring itself.
h                   Return the first (i.e. the shortest) such set of substrings.

hf!ff>Y>YZUYT+./ accounts for the empty string case with 1 less byte.

Nice, thanks! I felt like there must have been a shorter way.

Jelly, 18 bytes
ṙJ¹ÐṂF⁼
ŒṖÇ€Ạ$ÐfṀȯ

Try it online!

Pyth - 28 bytes
hf&SI_T.Am.A>Rdt.u.>N1tddT./

Test Suite.

This seems to fail on the empty string.

05AB1E, 15 bytes
.œé.Δεā<._ć›P}P

Try it online or verify all test cases.
Explanation:
.œ            # Get all partitions of the (implicit) input-string
  é           # Sort them by length
   .Δ         # Find the first/shortest which is truthy for:
     ε        #  Map over each part of the current partition:
      ā       #   Push a list in the range [1,length] (without popping the part-string)
       <      #   Decrease it to a 0-based range [0,length)
        ._    #   For each value, rotate the string that many times
          ć   #   Extract head; pop and push remainder-list and first item separately
              #   (where the head is the unmodified part-string)
           ›  #   Check for each rotated part if it's lexicographically larger than the
              #   unmodified part-string
            P #   Check whether this is truthy for all rotations
     }P       #  After the inner map: check whether it's truthy for all parts in the
              #  partition
              # (after which the found result is output implicitly as result)

source: Stack Exchange

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

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

sort: votes


text:
Smallest unused number sharing a factor
This is a pretty run of the mill question.  I will define a sequence and you golf some code to output a entry given a index.

The first item in the sequence is 2.
The nth item in the sequence is the smallest positive integer other than n and 1 sharing at least one factor with n (other than 1) that has not already appeared in the list.

Test cases
Here are the first 25 items in the sequence:
1  2
2  4
3  6
4  8
5  10
6  3
7  14
8  12
9  15
10 5
11 22
12 9
13 26
14 7
15 18
16 20
17 34
18 16
19 38
20 24
21 27
22 11
23 46
24 21
25 30

Related (offset by one) OEIS

Jelly, 19 bytes
R»2ɓ²Rg⁸>1Tḟ⁸ḟḢṭµ/Ṫ

Try it online!

I was so happy that I had you out-golfed on the Lyndon word factorization question but then you hit me with this... (in all seriousness though this is a great answer)

Python 3, 118 117 bytes
 -1 byte thanks to Cameron Aavik!
import math
def f(n,i=3):
 if n<2:return 2
 while 1:
  if math.gcd(n,i)>1>(i in map(f,range(n)))<i!=n:return i
  i+=1

Try it online!
The code is pretty inefficient (it brute-forces a value that doesn't exist in the previous results, and calculates the previous results again on every new value), so it works properly but I wouldn't recommend running it on large numbers.

Small tip: You can save a newline by making it def f(n,i=3): and removing the i=3 line

115 bytes.

Haskell, 60 59 bytes
EDIT:

-1 byte: @xnor pointed out all(/=x) was shorter than x`notElem`.

f takes an integer and returns an integer.
f n=[x|x<-[2..],gcd x n>1||n<2,all(/=x)$n:map f[1..n-1]]!!0

Try it online!
This is very exponential time, so TIO times out after 21, while my interpreted GHCi got up to 22 before I stopped it just now. The following 9 bytes longer version memorizing into a list easily goes up into the thousands:
f n=[x|x<-[2..],gcd x n>1||n<2,all(/=x)$n:take(n-1)l]!!0
l=f<$>[1..]

Try it online!

f n uses a list comprehension to generate candidates x, taking the first passing one with !!0.
gcd x n>1 checks that x and n have common factors.
||n<2 exempts n==1 from the factor requirement.
all(/=x)$n:map f[1..n-1] checks that x is neither n nor a preceding sequence element.

@WheatWizard Hm, probably no difference in that case. Just used to doing it by default. It's one of the few alphanumerical functions that has a fixity defined to fit well that way.

all(/=x)$ is 1 shorter there

No built-in for GCD in C#, so...
C# (.NET Core), 197 196 194 bytes
n=>{if(n<2)return 2;var p=new int[n-1];int i=0,a,b;for(;i<n-1;)p[i]=f(++i);for(i=2;;i++)if(n!=i){for(a=n,b=i;a*b>0;)if(a>b)a%=b;else b%=a;if(b!=1&a!=1&!System.Array.Exists(p,e=>e==i))return i;}}

Try it online!
Once again, refrain from using this code to calculate numbers in the sequence for n>30...

-1 byte by changing the GCD while loop for a for loop.
-2 bytes thanks to Kevin Cruijssen! Nice one!

a>0&b>0 can be golfed to a*b>0

APL (Dyalog), 46 bytes
{⍺←2⋄1=⍵:2⋄(~∨/⍺∊∇¨⍳⍵-1)∧(1<⍺∨⍵)∧⍺≠⍵:⍺⋄⍵∇⍨1+⍺}

Try it online!

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


text:
Is the question undeleted?
Challenge
Given a positive integer, determine whether that number is currently being used to represent a question on PPCG.
The question must not have been removed, but may be open or closed.
The number is the one being used in the URL of the question, such as:

https://codegolf.stackexchange.com/questions/[input]

Note that this questions is tagged stack-exchange-api, but you may not need this to complete the challenge.

Examples

1: Truthy (represents Just Another Perl Hacker)
3: Falsey (was once Solve the Tower of Hanoi, but was removed by a moderator.
127030: Falsey (was once Helping Danny to Maximize his Score, but was removed by the author.)
127147: Truthy (Fastest algorithm to take the product of all subsets)

Scoring
This is code-golf, so the shortest answer in each language wins.

Just Another Perl Hacker is closed.

@ATaco It is closed, but the criteria state that The question must not have been removed, but may be open or closed. This is to benefit answers that don't use the Stack Exchange API because, I believe, a page will give 404 Not Found iff it is not a question or was removed

@totallyhuman Yes, standard I/O apply

Sandbox for those who can see deleted posts

Uhm, why is the title "Is it an open question?" if the question may be open or closed?

bash, 52 bytes
curl -IL codegolf.stackexchange.com/q/$1|grep 2\ 200

Takes input as a command line argument, and outputs in the form of exit code: 0 or "success" (truthy) for an undeleted question, and 1 or "failure" (falsy) for a nonexistent or deleted question.
It also prints a bunch of junk to STDERR and potentially STDOUT, but this is allowed to be ignored as per meta.
As an explanation, the -I flag to curl sends an HTTP HEAD request (fetch only the headers), and -L will follow redirects (http to https, and then /q to /questions). The full output from the curl command will look something like this:
HTTP/1.1 301 Moved Permanently
Location: https://codegolf.stackexchange.com/q/127030
X-Request-Guid: 1a0b6059-057c-448c-bfc9-a96f1b373abf
Content-Length: 160
Accept-Ranges: bytes
Date: Tue, 20 Jun 2017 04:07:30 GMT
Via: 1.1 varnish
Age: 503
Connection: keep-alive
X-Served-By: cache-itm7423-ITM
X-Cache: HIT
X-Cache-Hits: 1
X-Timer: S1497931651.709631,VS0,VE0
Vary: Fastly-SSL
X-DNS-Prefetch-Control: off
Set-Cookie: prov=933ae4b0-81b0-2b37-e26e-59a0fbb6991a; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly

HTTP/2 302
date: Tue, 20 Jun 2017 04:07:31 GMT
content-type: text/html; charset=utf-8
location: https://codegolf.stackexchange.com/questions/127030/helping-danny-to-maximize-his-score
x-frame-options: SAMEORIGIN
x-request-guid: fdcaf556-7ae6-4240-89a1-ace7625f8821
strict-transport-security: max-age=15552000
accept-ranges: bytes
via: 1.1 varnish
age: 0
x-served-by: cache-nrt6132-NRT
x-cache: MISS
x-cache-hits: 0
x-timer: S1497931651.085546,VS0,VE166
vary: Fastly-SSL
x-dns-prefetch-control: off
set-cookie: prov=5e314a4f-0c50-08ef-afa2-9388b37e3b7a; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
cache-control: private
content-length: 204

HTTP/2 404
date: Tue, 20 Jun 2017 04:07:31 GMT
content-type: text/html; charset=utf-8
x-frame-options: SAMEORIGIN
x-request-guid: 3f72afb7-81e8-4e69-a8ad-474534f2abe6
strict-transport-security: max-age=15552000
accept-ranges: bytes
via: 1.1 varnish
age: 0
x-served-by: cache-nrt6132-NRT
x-cache: MISS
x-cache-hits: 0
x-timer: S1497931651.323339,VS0,VE189
vary: Fastly-SSL
x-dns-prefetch-control: off
set-cookie: prov=cede4119-eba5-d799-e376-848e4e457f07; domain=.stackexchange.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
cache-control: private
content-length: 42158

Note that the 2\ 200 (equivalent to '2 200') will match the line HTTP/2 200 if it exists (HTTP OK), and it will not match HTTP/2 404 (Not Found) for questions that do not exist. (The inclusion of the 2 is necessary to avoid false positives if some of the other headers happen to contain the sequence 200.)

Python 2 + Requests, 112 bytes
Takes input as a string or integer and outputs 1 for truthy and 0 for falsy.
lambda n:len(get('http://api.stackexchange.com/posts/%s?site=codegolf'%n).json()['items'])
from requests import*

Won't this return truthy if the integer provided is the ID of an answer?

@Shaggy All of these answers do. This is an oversight on my part.

Python 3 + Requests, 107 99 98 92 79 bytes
lambda m:get("http://codegolf.stackexchange.com/q/"+m).ok
from requests import*

-8 bytes by changing question to q
-1 byte by changing != to <, since 200 OK is less than 404 NOT FOUND.
-1 byte by changing https to http
-6 bytes by changing to a lambda
-13 bytes using the ok attribute

You should add + Requests in the header as it's not in the Python standard library.

Mathematica, 70 bytes
Takes input as a string and outputs 1 for truthy and 0 for falsy.
Check[Import["https://codegolf.stackexchange.com/questions/"<>#];1,0]&

JavaScript (ES6), 104 102 bytes
Returns a Promise containing a JSON object for truthy or undefined for falsey.
n=>fetch(`//api.stackexchange.com/questions/${n}?site=codegolf`).then(r=>r.json()).then(j=>j.items[0])

Try it

f=
n=>fetch(`//api.stackexchange.com/questions/${n}?site=codegolf`).then(r=>r.json()).then(j=>j.items[0])
oninput=_=>f(+i.value).then(console.log);f(i.value=1).then(console.log)
<input id=i type=number>

Stratos, 16 bytes
f"¹⁵s/%²"r"⁷s"
l

Explanation (decompressed:
f"api.stackexchange.com/questions/%?site=codegolf"         Replace % with the input, and get from this URL
                                                  r"items" Get the JSON array named "items"
l                                                          Length

Prints 1 for truthy, and 0 for falsy.
Try it!


text:
Finding the smallest sets
Consider three sets A, B and C each containing n integers.  From this we can make the set
S_n = {a * b + c | a in A, b in B, c in C}.

Given an n, there are one or more minimal sized S_n which depend on which sets A,B and C have been chosen.
The sets can contain any n distinct integers (positive, zero or negative). There is no need for them to be consecutive integers or for the sets to be equal to each other for example.  A = {-1, 0, 5, 10, 27}, B = {2, 5, 6, 10, 14} and C = {-23, 2, 100, 1000,10000} is acceptable (although not a good idea) for example.
Task
The task is to write code to find the smallest set S_n it can for each n from 1 to 20.
For each n from 1 to 20 your code should output the chosen A, B and C along with the resulting size of S_n
Score
Your score will be  the sum of the sizes of the S_n you create.  That is it will be a sum of twenty numbers.
The lower the score the better.
Examples
If A = B = C = {1, 2, 3, 4} then S_4 =  {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} which is of size 19.
This is however in no way optimal. For example, A = B = C = {-1, 0, 1, 2} gives S_4 = {0, 1, 2, 3, 4, 5, 6, -1, -3, -2} which  is of size 10.
Timings
As I will need to run your code to verify the output, please make sure it takes no more than 30 minutes and 4GB of RAM to run on a normal desktop.
Notes
Your code must actually compute the output. You are not allowed to hardcode precomputed answers into your code.

Could someone find the sets using more time and computing power, then write code to output them hardcoded?

@xnor That looks like cheating to me.  Please don't do that.  Having said that, I am not sure what a computationally expensive approach would be that would still terminate. There are a lot of integers!

Rust, score 1412 1411
src/main.rs
extern crate gmp;

use std::collections::BinaryHeap;
use std::collections::hash_map::{HashMap, Entry};
use gmp::mpz::Mpz;

fn visit(
    queue: &mut BinaryHeap<(i32, i32, i32, Mpz, Mpz)>,
    visited: &mut HashMap<(i32, Mpz), i32>,
    score: i32,
    h: i32,
    k: i32,
    d: Mpz,
    c: Mpz,
) {
    match visited.entry((k, d.clone())) {
        Entry::Occupied(mut e) => {
            if *e.get() < score {
                e.insert(score);
                queue.push((score, h, k, d, c));
            }
        }
        Entry::Vacant(e) => {
            e.insert(score);
            queue.push((score, h, k, d, c));
        }
    }
}

fn main() {
    let mut total = 0;
    for n in 1..21 {
        let a_range = n / 2 - n + 1..n / 2 + 1;
        let min_ab = a_range.start * (a_range.end - 1);
        let mut ab = Mpz::zero();
        for a in a_range.clone() {
            for b in a_range.clone() {
                ab.setbit((a * b - min_ab) as usize);
            }
        }

        let heuristic = |k: i32, d: &Mpz| if k == n {
            0
        } else {
            k + 1 - n -
                (0..d.bit_length())
                    .map(|i| (&ab & !(d >> i)).popcount())
                    .min()
                    .unwrap() as i32
        };

        let mut queue = BinaryHeap::new();
        let mut visited = HashMap::new();

        let (k1, d1) = (0, Mpz::zero());
        let h1 = heuristic(k1, &d1);
        visit(&mut queue, &mut visited, h1, h1, k1, d1, Mpz::zero());
        while let Some((score, h, k, d, c)) = queue.pop() {
            if k == n {
                println!("n={} |S|={}", n, -score);
                println!("  A={:?}", a_range.clone().collect::<Vec<_>>());
                println!("  B={:?}", a_range.clone().collect::<Vec<_>>());
                println!(
                    "  C={:?}",
                    (0..c.bit_length())
                        .filter(|&i| c.tstbit(c.bit_length() - 1 - i))
                        .collect::<Vec<_>>()
                );
                total += -score;
                break;
            }

            let kd = (k, d);
            if score < visited[&kd] {
                continue;
            }
            let (k, d) = kd;

            let (k1, d1) = (k, &d >> 1);
            let h1 = heuristic(k1, &d1);
            visit(
                &mut queue,
                &mut visited,
                score - h + h1,
                h1,
                k1,
                d1,
                &c << 1,
            );

            let (k1, d1) = (k + 1, (&d | &ab) >> 1);
            let h1 = heuristic(k1, &d1);
            visit(
                &mut queue,
                &mut visited,
                score - h - (&ab & !&d).popcount() as i32 + h1,
                h1,
                k1,
                d1,
                &c << 1 | Mpz::one(),
            );
        }
    }

    println!("total={}", total);
}

Cargo.toml
[package]
name = "small"
version = "0.1.0"
authors = ["Anders Kaseorg <andersk@mit.edu>"]

[dependencies]
rust-gmp = "0.5.0"

Compile and run with cargo run --release.
Output
n=1 |S|=1
  A=[0]
  B=[0]
  C=[0]
n=2 |S|=3
  A=[0, 1]
  B=[0, 1]
  C=[0, 1]
n=3 |S|=5
  A=[-1, 0, 1]
  B=[-1, 0, 1]
  C=[0, 1, 2]
n=4 |S|=10
  A=[-1, 0, 1, 2]
  B=[-1, 0, 1, 2]
  C=[0, 1, 2, 3]
n=5 |S|=13
  A=[-2, -1, 0, 1, 2]
  B=[-2, -1, 0, 1, 2]
  C=[0, 1, 2, 3, 4]
n=6 |S|=21
  A=[-2, -1, 0, 1, 2, 3]
  B=[-2, -1, 0, 1, 2, 3]
  C=[0, 2, 3, 4, 5, 6]
n=7 |S|=25
  A=[-3, -2, -1, 0, 1, 2, 3]
  B=[-3, -2, -1, 0, 1, 2, 3]
  C=[0, 2, 3, 5, 6, 7, 8]
n=8 |S|=35
  A=[-3, -2, -1, 0, 1, 2, 3, 4]
  B=[-3, -2, -1, 0, 1, 2, 3, 4]
  C=[0, 3, 4, 6, 7, 8, 10, 11]
n=9 |S|=39
  A=[-4, -3, -2, -1, 0, 1, 2, 3, 4]
  B=[-4, -3, -2, -1, 0, 1, 2, 3, 4]
  C=[0, 3, 4, 6, 7, 8, 10, 11, 14]
n=10 |S|=53
  A=[-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
  B=[-4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
  C=[0, 1, 4, 5, 6, 9, 10, 11, 14, 15]
n=11 |S|=58
  A=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
  B=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
  C=[0, 1, 4, 5, 6, 9, 10, 11, 14, 15, 19]
n=12 |S|=74
  A=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
  B=[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
  C=[0, 4, 5, 6, 9, 10, 11, 12, 15, 16, 17, 21]
n=13 |S|=80
  A=[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
  B=[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
  C=[0, 4, 5, 6, 9, 10, 11, 12, 15, 16, 17, 21, 22]
n=14 |S|=100
  A=[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  B=[-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  C=[0, 1, 6, 7, 8, 12, 13, 14, 15, 19, 20, 21, 26, 27]
n=15 |S|=106
  A=[-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  B=[-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
  C=[0, 5, 6, 7, 11, 12, 13, 14, 18, 19, 20, 21, 25, 26, 27]
n=16 |S|=128
  A=[-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
  B=[-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
  C=[0, 6, 7, 8, 13, 14, 15, 16, 20, 21, 22, 23, 28, 29, 30, 36]
n=17 |S|=135
  A=[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
  B=[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
  C=[0, 6, 7, 8, 13, 14, 15, 16, 20, 21, 22, 23, 28, 29, 30, 36, 44]
n=18 |S|=161
  A=[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  B=[-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  C=[0, 7, 8, 9, 15, 16, 17, 18, 23, 24, 25, 26, 27, 32, 33, 34, 35, 41]
n=19 |S|=167
  A=[-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  B=[-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  C=[0, 7, 8, 9, 15, 16, 17, 18, 23, 24, 25, 26, 27, 32, 33, 34, 35, 41, 42]
n=20 |S|=197
  A=[-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  B=[-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  C=[0, 1, 8, 9, 10, 11, 17, 18, 19, 20, 21, 26, 27, 28, 29, 30, 36, 37, 38, 46]
total=1411

On my laptop, this used about 8 minutes and about 1.5 GiB of memory.
How it works
We assume (without any particular justification) that A and B are the obvious range of consecutive integers centered at 0 or ½, then do an A* search for an optimal C given A and B.

If you fix B and C can you do the same A* search on A? I am thinking of a sort of coordinate descent approach. Fix all but one sets, optimize on the last one and repeat.

@Arthur I doubt a search on A can run as efficiently as a search on C because the space of partial results doesn’t collapse as nicely, and it was already nontrivial to get the search on C to run within the time limit.

Interesting. Maybe I set 10 minutes too low.  I am just intrigued if A = B and both consecutive integers is really always optimal. Just one counter example would be exciting.

C, score 1448 1431
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define P printf
#define R return
#define F for

int cmp(const void*a,const void*b)
{int aa, bb;
 aa=*(int*)a; bb=*(int*)b;
 R aa>bb?1:(aa<bb?-1:0);
}

void show(int* a,unsigned n){unsigned i;P("[ ");F(i=0;i<n;++i) P("%d ", a[i]);P("]");}

// l'insieme "a" deve essere del tipo {0,1} {-1,0,1} {-1,0,1,2} {-2,-1,0,1,2} ecc di numero elementi n
// l'insieme "c" e' un insieme di numero elementi n
// l'insieme a cui "r" punta sarà *r={x*y+z : x in a, y in a, z in c }
// ritorna -1 per errore altrimenti il numero di elementi
// di {x*y+z : x in a, y in a, z in c }

int g(int**r,int*a,int*c,unsigned n)
{static int *arrs,*res;
 static unsigned  alen;
 unsigned i,j,k,m,v,vv,len;

 if(a==0||c==0||n<=0||n>128) R -1;
 len=n*n*n;
 if(alen<n)
    {if(arrs) free(arrs);  // leaks: arrs and res remain until the program end
     if(res ) free(res);
     arrs=0; res=0; alen=0;
     arrs=malloc(sizeof(int)*len);
     if(arrs==0)             R -1;
     res =malloc(sizeof(int)*len);
     if(res==0)
         {free(arrs); arrs=0;R -1;}
     alen=n;
    }
 v=0;
 F(k=0;k<n;++k) arrs[v++]=c[k]; // il caso 0

 F(m=0;m<n&&a[m]<0;++m);// da una parte i positivi dall'altra i negativi; m punta a 0
                        // il caso 0 non e' trattato
 F(i=0;i<m;++i)    // positivi per negativi
   F(j=m+1;j<n;++j)
      F(k=0;k<n;++k)
         if(-a[i]<=a[j]) arrs[v++]=a[i]*a[j]+c[k];
 F(i=m+1;i<n;++i)  // positivi per positivi
   F(j=i;j<n;++j)
      F(k=0;k<n;++k)
          arrs[v++]=a[i]*a[j]+c[k];
 qsort(arrs,v,sizeof(int),cmp);
 res[0]=arrs[0];  // elimina i doppioni
 F(vv=1,i=1; i<v; ++i)
       if(arrs[i-1]!=arrs[i]) res[vv++]=arrs[i];
 *r=res;
 R vv;
}

int inc(int* a,int len,int b)
{int i,j;
 if(len<1||b<1)R 1;
 F(i=0;;)
   {if(i>=len)
         {F(j=0;j<len;++j)a[j]=0;
          R 1;
         }
    if(i==len-1||a[i]<a[i+1])
               {if(a[i]<b)
                   {a[i]+=1;
                    F(j=0;j<i;++j)a[j]=0;
                    break;
                   }
               }
    i+=1;
   }
 R 0;
}

// a,b,c,cmin sono array e devono avere size n
// s          e' un array deve avere size n*n*n
//            come risultato la sua lunghezza e' *slen
//
int f(int* a,int* b,int* cmin,int* s,int* slen, int n)
{int i,j,k, *c, *aix, *cp, smin, *rs;

 if(slen)*slen=0;
 if(n<1||a==0||b==0||cmin==0||s==0||slen==0)R -1;

 // costruisce a e b
 j=-n/2;
 if(n%2==0)++j;
 F(i=0;i<n;++i,++j) s[i]=cmin[i]=a[i]=b[i]=j;
 // {-x..x}  oppure {-x..(x+1)}

 *slen=n;
 if(n==1)R 1; // caso di un solo elemento
 c  =malloc(sizeof(int)*(n+1)); // **
 if(c==0)R -1;
 aix=malloc(sizeof(int)*(n+1)); // **
 if(aix==0){free(c);R -1;}
 cp =malloc(sizeof(int)*(n+1)); // **
 if(cp==0){free(aix);free(c);R -1;}

 F(i=0;i<n;++i){cp[i]=aix[i]=0;c[i]=i;}
 if(n>=16)//16
    {c[n-1]=c[n-1]+3;c[n-2]=c[n-2]+3;c[n-3]=c[n-3]+3;}
 F(smin=n*n+10;;)
    {cp[0]=c[0];
     F(i=1;i<n;++i) cp[i]=c[i]+aix[i-1];
     k=g(&rs,a,cp,n);
     if(k<smin){F(smin=k,i=0;i<n;++i) cmin[i]=cp[i];
                //P("Assign: %d,  ", k);
                //show(aix,n);P(",");
                //P("Cmin=");show(cmin,n);P("\n");
               }
     //show(aix,n);P("\n");
     if(inc(aix,n-1,7))break;
    }
 free(cp);free(aix);free(c);
 k=g(&rs,a,cmin,n);
 if(k==-1)R -1;
 F(i=0;i<k;++i)s[i]=rs[i];
 *slen=k;
 R k;
}

unsigned h(unsigned nmax)
{time_t                             ti, tf;
 double  dft;
 int i,j, *a, *b, *cmin, *s, slen, rlen, r;
 unsigned                            n,len;
 if(nmax>128||nmax<1)R -1;
 len =nmax*nmax*nmax+1;
 s   =malloc(sizeof(int)*len);      // **
 a   =malloc(sizeof(int)*(nmax+1)); // **
 b   =malloc(sizeof(int)*(nmax+1)); // **
 cmin=malloc(sizeof(int)*(nmax+1)); // **
 if(s==0||a==0||b==0||cmin==0){free(s);free(a);free(b);free(cmin);R -1;}
 ti=time(0);
 F(n=1,r=0;n<=nmax;++n)
    {rlen=f(a,b,cmin,s,&slen,n);
     if(rlen!=-1)
         {P("%d %d", n, rlen); show(cmin,n);P("\n");}
     else break;
     r+=rlen;
    }
 tf=time(0);
 dft=difftime(tf, ti);
 P("Result=%d  secondi=%.0f  minuti=%.0f\n", r, dft, dft/60.0);
free(s);free(a);free(b);free(cmin);
 R r;
}

int main(){h(20); R 0;}

It would be the same +/- algo of Axiom implementation
results
1 1[ 0 ]
2 3[ 0 1 ]
3 5[ 0 1 2 ]
4 10[ 0 1 2 3 ]
5 13[ 0 1 2 3 4 ]
6 21[ 0 1 2 3 4 5 ]
7 25[ 0 1 2 3 4 5 6 ]
8 35[ 0 1 3 4 5 7 8 11 ]
9 39[ 0 3 4 6 7 8 10 11 14 ]
10 53[ 0 1 4 5 6 8 9 10 13 14 ]
11 59[ 0 1 2 4 5 6 7 9 10 11 14 ]
12 75[ 0 1 2 5 6 7 8 11 12 13 17 18 ]
13 81[ 0 1 2 5 6 7 8 11 12 13 14 17 18 ]
14 101[ 0 1 2 3 6 7 8 9 10 13 14 15 16 20 ]
15 107[ 0 1 2 3 6 7 8 9 10 13 14 15 16 20 21 ]
16 130[ 0 1 2 6 7 8 9 10 13 14 15 16 17 21 22 23 ]
17 137[ 0 1 2 3 7 8 9 10 11 15 16 17 18 19 23 24 25 ]
18 163[ 0 1 2 3 7 8 9 10 11 12 16 17 18 19 20 25 26 27 ]
19 171[ 0 1 2 3 4 8 9 10 11 12 13 17 18 19 20 21 26 27 28 ]
20 202[ 0 1 2 3 7 8 9 10 11 12 13 17 18 19 20 21 22 27 28 29 ]
Result=1431  secondi=618  minuti=10

Axiom, score 1466
)time on

g(a:List INT,b:List INT,c:List INT):List INT==
   s:List INT:=[]
   for i in 1..#a repeat
     for j in 1..#b repeat
       for h in 1..#c repeat
            s:=cons(a.i*b.j+c.h, s)
   removeDuplicates(s)

inc(a:List INT, b:INT):List INT==
    #a=0=>a
    i:=1; len:=#a
    repeat
       if i>len then
             for j in 1..len repeat a.j:=0
             return a
       if i<len then
         if a.i<a.(i+1) then
               if a.i<b then
                          a.i:=a.i+1
                          for j in 1..(i-1) repeat a.j:=0
                          break
               for j in 1..i repeat a.j:=0
       else
         if a.i<b then
                   a.i:=a.i+1
                   for j in 1..(len-1) repeat a.j:=0
                   break
       i:=i+1
    a

f(n:PI):List List INT==
   a:List INT:=[0];  b:List INT:=[0];   c :List INT:=[0]
   aix:List INT:=[]; cmin:List INT:=[]; cp:List INT:=[ ]
   s:List INT :=[ ];   c1:List INT:=[0]; smin:INT
   -- costruisce gli insiemi a,b
   i:=1
   for j in 1..n-1 repeat
      if member?(i,a) then (a:=cons(-i,a);b:=cons(-i,b);i:=i+1)
      else                 (a:=cons( i,a);b:=cons( i,b))
   if n=1 then return [a,b,c,[0],[1]]
   a:=sort(a)
   c :=copy(a); cmin:=copy(a); cp:=copy(a)
   for i in 1..n repeat c.i:=i-3
   for i in 1..n repeat aix:=cons(0, aix)
   -- ottimizzati per i vari casi... si parte da particolari insiemi c
   -- da cui fare le variazioni
   if n>=8         then c.n:=c.n+2
   if n=10 or n=13 then c.(n-1):=c.(n-1)+2
   if n=9  or n=16 or n=19 then (c.(n-2):=c.(n-2)+1; c.(n-1):=c.(n-1)+1; c.n:=c.n+1)
   smin:=n*n+10
   repeat
       for i in 1..n repeat cp.i:=c.i+aix.i
       k:=# g(a,b,cp)
       if k<smin then
                smin:=k;
                for i in 1..n repeat cmin.i:=cp.i
                --output ["assign",c,aix,cmin, k]
       inc(aix, 3)
       --output aix
       i:=0;repeat(i:=i+1;if i>n or aix.i~=0 then break)
       if i>n then break
   [sort(a),sort(b),sort(cmin),g(a,b,cmin),[smin]]

h(n:PI):NNI==
    k:=0
    r:List List INT:=[]
    for i in 1..n repeat
         r:=f(i)
         output [i,r.5.1,r.1,r.3]
         k:=k+r.5.1
    k

The sets would be A=B=[-n/2..n/2] if n%2==0 else A=B=[-n/2..((n/2)+1)]
The set C is the sum of the array as [-2,-1,..(n-2)]
 to one array arr[] of this kind
[0,0,0,0,0] or
[0,1,1,1,2] or
[0,0,0,0,3]
so that array it has property
 arr[i] <= arr[i+1] for i in 1..n-1

If you want to be more precise or you PC is more fast
you can try to increase '3' in 'inc(aix, 3)'
that increase the number of arrays for the C set variation
and so it would increase the result precision.
In the results the string printed is
 [n, |{a*b+c for a in A for b in B for c in C}|,A,C]

where B=A  and |S| is the number of element of S
(6) -> h 20
   [1,1,[0],[0]]
   [2,3,[0,1],[- 2,- 1]]
   [3,5,[- 1,0,1],[- 2,- 1,0]]
   [4,10,[- 1,0,1,2],[- 2,- 1,0,1]]
   [5,13,[- 2,- 1,0,1,2],[- 2,- 1,0,1,2]]
   [6,21,[- 2,- 1,0,1,2,3],[- 2,- 1,0,1,2,3]]
   [7,25,[- 3,- 2,- 1,0,1,2,3],[- 2,- 1,0,1,2,3,4]]
   [8,35,[- 3,- 2,- 1,0,1,2,3,4],[- 2,- 1,1,2,3,5,6,9]]
   [9,39,[- 4,- 3,- 2,- 1,0,1,2,3,4],[- 2,1,2,4,5,6,8,9,12]]
   [10,53,[- 4,- 3,- 2,- 1,0,1,2,3,4,5],[- 2,- 1,2,3,4,6,7,8,11,12]]
   [11,59,[- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5],[- 2,- 1,0,2,3,4,5,7,8,9,12]]
   [12,76,[- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6],[- 2,- 1,0,3,4,5,6,8,9,10,11,14]]
   [13, 82, [- 6,- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6],[- 2,- 1,0,3,4,5,6,8,9,10,11,14,15]]
   [14, 103, [- 6,- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6,7],[- 2,- 1,0,3,4,5,6,7,9,10,11,12,13,16]]
   [15, 110, [- 7,- 6,- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6,7],[- 2,- 1,0,1,4,5,6,7,8,10,11,12,13,14,17]]
   [16, 134, [- 7,- 6,- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6,7,8],[- 2,- 1,0,1,4,5,6,7,8,9,11,12,13,15,16,19]]
   [17, 142, [- 8,- 7,- 6,- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6,7,8],[- 2,- 1,0,1,4,5,6,7,8,9,11,12,13,14,15,16,19]]
   [18, 169, [- 8,- 7,- 6,- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6,7,8,9],[- 2,- 1,0,1,2,3,4,6,7,8,9,10,11,12,15,16,17,20]]
   [19, 178, [- 9,- 8,- 7,- 6,- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6,7,8,9],[- 2,- 1,0,1,2,5,6,7,8,9,10,11,13,14,15,16,18,19,22]]
   [20, 208, [- 9,- 8,- 7,- 6,- 5,- 4,- 3,- 2,- 1,0,1,2,3,4,5,6,7,8,9,10],[- 2,- 1,0,1,2,3,4,5,7,8,9,10,11,12,13,14,17,18,19,22]]

   (6)  1466
                                                    Type: PositiveInteger
      Time: 0.03 (IN) + 910.75 (EV) + 0.02 (OT) + 24.00 (GC) = 934.80 sec

SQL Server, 1495
declare @N int=20;
--set @N=40;
with
  n as(select 1 n union all select n+1 from n where n<@N),
  s as(select n,n/2-n+1 m from n union all select n,m+1 from s where m<n/2),
  t as(select n,m,row_number()over(partition by n order by m) p from s),
  a as(select n,m a,p from t),
  b as(select n,m b,p from t),
  c as(select n,m c,p from t),
  u as(
    select a.n,count(distinct a*b+c) q
    from a,b,c
    where b.n=a.n and c.n=a.n
    group by a.n
  )
select u.n,a,b,c,q,sum(distinct q) N
from u,a,b,c
where a.n=u.n and b.n=u.n and c.n=u.n and b.p=a.p and c.p=a.p
group by grouping sets((u.n,a,b,c,q),());

The solution can be verified here.Excuse me for the output is in the tabular form.

Python 2, score 1495
f=lambda n:range(-n/2+1,n/2+1)
f_A=f_B=f_C=f

def comb_set(A, B, C):
	return sorted({a*b+c for a in A for b in B for c in C})

def S(n):
	return comb_set(f_A(n), f_B(n), f_C(n))

Try it online!
A simple baseline of having each set be a length-n interval centered around 0, slightly unbalanced for even n. The TIO has Python code to compute your score.
1   1
2   3
3   5
4   10
5   13
6   21
7   25
8   36
9   41
10  55
11  61
12  78
13  85
14  105
15  113
16  136
17  145
18  171
19  181
20  210

Total: 1495

The size is (n*n+1)/2 for odd n and (n*n+n)/2 for even n.

@Arthur Added. I'd like to say this is just a start, but I have no idea yet how to do better :) Something like the sum-product phenomenon gets in the way.

I plugged the sequence of results into OEIS. It's there, and with an entirely different definition.

Looks like it was just a start after all.

C++, score 1411
Conjecturing A and B are consecutive integers centered near 0, simply use simulated annealing to find C.
Source:
#include <algorithm>
#include <iostream>
#include <random>
#include <bitset>
#include <cmath>

using namespace std;

using bools = bitset<270>;
using irand = uniform_int_distribution<int>;
ranlux48 gen;
uniform_real_distribution<double> frand(0, 1);

int evaluate(const bools& a, const vector<int>& v)
{
    bools t = a;
    for (int i : v) t |= a << i;
    return t.count();
}

vector<int> best;
int best_score, prev_score;

void transition(double Temp, int Q, const bools& a, vector<int>& now)
{
    int rep, pos, tmp;
    do rep = irand(1, Q)(gen); while (find(now.begin(), now.end(), rep) != now.end());
    pos = irand(0, now.size() - 1)(gen);
    tmp = now[pos];
    now[pos] = rep;
    int now_score = evaluate(a, now);
    if (now_score <= prev_score || frand(gen) < exp((double)(prev_score - now_score))) {
        prev_score = now_score;
        if (now_score < best_score) best_score = now_score, best = now;
    }
    else now[pos] = tmp;
}

int main()
{
    int score = 0;
    for (int N = 1; N <= 20; N++) {
        gen.seed(0);
        int first = -N / 2, last = first + N, Q = N * 3;
        bools st;

        for (int i = first; i < last; i++)
            for (int j = first; j < last; j++)
                st[i * j + last * last] = true;

        vector<int> lst;
        for (int i = 1; i < N; i++) lst.push_back(i);

        best = lst;
        prev_score = best_score = evaluate(st, lst);

        if (N != 1)
            for (double Temp = 70.; Temp > 0; Temp -= 3e-5) transition(Temp, Q, st, lst);
        sort(best.begin(), best.end());
        cout << "N = " << N << "; |S| = " << best_score << endl;
        cout << " A = B = {";
        for (int i = first; i < last; i++) cout << i << (i != last - 1 ? ", " : "}\n");
        cout << " S = {0";
        for (int i : best) cout << ", " << i;
        cout << "}\n";

        score += best_score;
    }
    cout << "Score: " << score << endl;
}

Results:
N = 1; |S| = 1
 A = B = {0}
 S = {0}
N = 2; |S| = 3
 A = B = {-1, 0}
 S = {0, 1}
N = 3; |S| = 5
 A = B = {-1, 0, 1}
 S = {0, 1, 2}
N = 4; |S| = 10
 A = B = {-2, -1, 0, 1}
 S = {0, 1, 2, 3}
N = 5; |S| = 13
 A = B = {-2, -1, 0, 1, 2}
 S = {0, 1, 2, 3, 4}
N = 6; |S| = 21
 A = B = {-3, -2, -1, 0, 1, 2}
 S = {0, 1, 2, 3, 4, 5}
N = 7; |S| = 25
 A = B = {-3, -2, -1, 0, 1, 2, 3}
 S = {0, 1, 2, 3, 4, 5, 6}
N = 8; |S| = 35
 A = B = {-4, -3, -2, -1, 0, 1, 2, 3}
 S = {0, 3, 4, 6, 7, 10, 11, 14}
N = 9; |S| = 39
 A = B = {-4, -3, -2, -1, 0, 1, 2, 3, 4}
 S = {0, 3, 4, 6, 7, 8, 10, 11, 14}
N = 10; |S| = 53
 A = B = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4}
 S = {0, 1, 4, 5, 6, 9, 10, 11, 14, 15}
N = 11; |S| = 58
 A = B = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}
 S = {0, 1, 4, 5, 6, 9, 10, 11, 14, 15, 19}
N = 12; |S| = 74
 A = B = {-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}
 S = {0, 4, 5, 6, 9, 10, 11, 12, 15, 16, 17, 21}
N = 13; |S| = 80
 A = B = {-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6}
 S = {0, 6, 10, 11, 12, 15, 16, 17, 18, 21, 22, 23, 27}
N = 14; |S| = 100
 A = B = {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6}
 S = {0, 5, 6, 7, 11, 12, 13, 14, 18, 19, 20, 21, 25, 26}
N = 15; |S| = 106
 A = B = {-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}
 S = {0, 5, 6, 7, 11, 12, 13, 14, 18, 19, 20, 21, 25, 26, 32}
N = 16; |S| = 128
 A = B = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}
 S = {0, 6, 7, 8, 13, 14, 15, 16, 21, 22, 23, 24, 29, 30, 31, 37}
N = 17; |S| = 135
 A = B = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8}
 S = {0, 6, 7, 8, 13, 14, 15, 16, 21, 22, 23, 24, 29, 30, 31, 37, 45}
N = 18; |S| = 161
 A = B = {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8}
 S = {0, 7, 8, 9, 14, 15, 16, 17, 18, 22, 23, 24, 25, 26, 31, 32, 33, 40}
N = 19; |S| = 167
 A = B = {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
 S = {0, 7, 8, 9, 15, 16, 17, 18, 23, 24, 25, 26, 27, 32, 33, 34, 35, 41, 42}
N = 20; |S| = 197
 A = B = {-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
 S = {0, 8, 9, 10, 16, 17, 18, 19, 20, 25, 26, 27, 28, 29, 35, 36, 37, 38, 45, 46}
Score: 1411

With -O2 on my computer, it takes 50 secs to compute all the results.

Mathematica, score 1495
z = 0;
For[n = 1, n <= 20, n++,
r = Range[n] - Ceiling[n/2];
Print["S_n size=", x = (s = Length@#;
  Length@
   Union@Flatten@
     Table[#[[i]]*#[[j]] + #[[k]], {i, s}, {j, s}, {k, s}]) &[r],
"  ", "A=B=C=", r]; z = z + x]
Print["SCORE=", z]

S_n size=1  A=B=C={0}
S_n size=3  A=B=C={0,1}
S_n size=5  A=B=C={-1,0,1}
S_n size=10  A=B=C={-1,0,1,2}
S_n size=13  A=B=C={-2,-1,0,1,2}
S_n size=21  A=B=C={-2,-1,0,1,2,3}
S_n size=25  A=B=C={-3,-2,-1,0,1,2,3}
S_n size=36  A=B=C={-3,-2,-1,0,1,2,3,4}
S_n size=41  A=B=C={-4,-3,-2,-1,0,1,2,3,4}
S_n size=55  A=B=C={-4,-3,-2,-1,0,1,2,3,4,5}
S_n size=61  A=B=C={-5,-4,-3,-2,-1,0,1,2,3,4,5}
S_n size=78  A=B=C={-5,-4,-3,-2,-1,0,1,2,3,4,5,6}
S_n size=85  A=B=C={-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6}
S_n size=105  A=B=C={-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7}
S_n size=113  A=B=C={-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7}
S_n size=136  A=B=C={-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8}
S_n size=145  A=B=C={-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8}
S_n size=171  A=B=C={-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9}
S_n size=181  A=B=C={-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9}
S_n size=210  A=B=C={-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10}
SCORE=1495