text:
Build a Faulty XKCD Browser
Challenge
Given the number of an XKCD comic, output the title text of that comic (the mouseover text).
However, the program must throw an error when given the numbers 859 or 404.
Rules
The number given will always be an existing comic (except 404).
Your program must not throw an error for any other numbers than 859 or 404.
For reference, comic 404 does not exist and 859 is:
Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or ;;"''{<<[' this mouseover text."

Url shorteners are disallowed. You may use the internet to get the title text.
Examples
Input > Output
1642 > "That last LinkedIn request set a new record for the most energetic physical event ever observed. Maybe we should respond." "Nah."
1385 > ::PLOOOOSH:: Looks like you won't be making it to Vinland today, Leaf Erikson.
1275 > If replacing all the '3's doesn't fix your code, remove the 4s, too, with 'ceiling(pi) / floor(pi) * pi * r^floor(pi)'. Mmm, floor pie.
1706 > Plus, now I know that I have risk factors for elbow dysplasia, heartworm, parvo, and mange.

Bounty
I will award a bounty to the shortest answer which fails on comic 859 because it's poorly written instead of checking for the number.
Your program may break on other alt texts (such as 744) providing they have unmatched parentheses, quotation marks etc.
Winning
Shortest code in bytes wins.

Is returning null valid as Error?

@RomanGräf Uhh yeah, I think it can be

Do we need to parse html entities like '?

@thegreatemu Yes

Since there are other comics with script-breaking alt texts (see 744), is it okay if a program breaks on those too?

@totallyhuman You should've added a slightly-NSFW-warning to that :P

@totallyhuman Yes, that's fine

Contradiction in the challenge: "must not throw an error for any other numbers than 859 or 404" and "may break on other alt texts".

@aschepler The latter is only for the bounty

@BetaDecay this suggests the bounty may be applied to an answer that is invalid, inviting invalid answers.

Or should the invalid code be included as an aside in a valid answer?

Isn't this likely to be akin unto a DDOS against the site?  And thus should be done with permission?

@Kzqai Good question, but I think you may be slightly underestimating how much traffic is involved in a DDOS, and also how much traffic xkcd.com already has. I wouldn't expect the traffic generated from answers here to be significant compared to either of those.

Python 2.7 + xkcd,  55 bytes
xkcd is a third-party Python package. In Python, there is a package for everything!
lambda n:[xkcd.getComic(n).altText][n==859]
import xkcd

For 404: urllib2.HTTPError: HTTP Error 404: Not Found
For 859: IndexError: list index out of range

The package was written before this challenge and wasn't written specifically for this challenge, it just ends up being highly appropriate.

Wow, Python just got more attractive!

@Nat Come join Us!

The pypi page says it's Python 2 compatible also, fwiw. Great find!

Coincidentally, python does indeed support import'ing antigravity.

Did Python just Mathematica this challenge?

Python 2 + Requests, 104 102 95 94 bytes
-2 bytes thanks to Erik the Outgolfer. -1 byte thanks to Jonathan Allan.
lambda n:[get('http://xkcd.com/%d/info.0.json'%n).json()['alt']][n==859]
from requests import*

Obligatory:
import antigravity

Poorly written script, 98 bytes
So, writing poor scripts is actually hard to do intentionally... This also breaks on other comics because they contain quotes, not sure if that's okay.
from requests import*
exec'print "%s"'%get('http://xkcd.com/%d/info.0.json'%input()).json()['alt']

I think you can remove ,a.

Oh, I didn't think of that. Thanks!

You can change n in[404,859] to n==859, because the JSON decoder fails for 404 anyway.

@musicman523 Ninja'd you. ;)

@totallyhuman Ya got me ;)

... http:// can be used here too, I think.

how do you actually run this with a parameter?  Like, how do you run a nameless lambda?

@MrZander The first line is an anonymous lambda that can be assigned to a variable to be run. For example, both f = lambda n: n * 2; print f(2) or (lambda n: n * 2)(2) will print 4.

@totallyhuman Is it standard on codegolf.se that user input doesn't need to be counted towards total character count?

@MrZander Yes, it is standard, and unused function names do not add towards the score.

If you're willing to add 4 extra bytes, you can stop it from breaking on any comic with quotes: from requests import*;exec'print """%s"""'%get('http://xkcd.com/%d/info.0.json'%input()).json()['alt']

Python 2 + xkcd, 82 bytes
Poorly written script
lambda n:eval("'''%s'''"%xkcd.getComic(n).altText.replace(';;',"'''"))
import xkcd

Appends and prepends ''', which, unless the text contains ''', will not break, even for other quotation marks. That is, except if the text contains ;;, which gets replaced with ''' (eliminating re). This only applies for 859, and thus this code breaks on 859. :P
Also, one should never eval random internet content, because if xkcd.getComic(n).altText somehow became '''+__import__('os').system('rm -rf / --no-preserve-root')+''', it would cause many bad things to happen. Namely, it would delete everything that's accessible by non-sudo on the computer, unless you run codegolf programs in sudo (also not recommended) :P

Poorly written and fails for that test case, 859? Someone is going to get a bounty, I suppose...

Ah the cringe for evaling random content from the internet - bravo! :P

@LukeBriggs It should theoretically be safe... I mean, my computer hasn't exploded (yet) so it should be fine, right? :P But alternatively you could use __import__('ast').literal_eval in place of eval if you really wanted :P

Does it break on 744?

@Draco18s It shouldn't, because the triple quotes don't care about the mismatched quotes, and there's no ;;.

Noted. :) Was just curious.

Wolfram Language/Mathematica, 118 117 bytes
saved a byte thanks to numbermanic
If[ImportString[#,"HTML"]===#,#,$Failed]&@Import[StringTemplate["http://xkcd.com/``/info.0.json"]@#,"RawJSON"]@"alt"&

Explanation:
Use StringTemplateto form the URL from the input.
Import[..., "RawJSON"] imports the JSON object and parses it into an Assocation.
Select the value for the key "alt".
Take this result and try to interpret the string as HTML (Import[#,"HTML"]).  If this doesn't change anything pass the result through, if it does return $Failed.  This catches 859 because
ImportString[
 "Brains aside, I wonder how many poorly-written xkcd.com-parsing
  scripts will break on this title (or ;;\"''{<<[' this mouseover text.\"","HTML"]

results in:
Brains aside, I wonder how many poorly-written xkcd.com-parsing
scripts will break on this title (or ;;"''{

404 fails because
If[
 ImportString[$Failed["alt"], "HTML"] === $Failed["alt"],
 $Failed["alt"],
 $Failed]

results in $Failed.

What version are you using? I get The Import element "RawJSON" is not present when importing as JSON on 10.0.1.

@totallyhuman Well it probably doesn't need to check for 859. (See the bounty condition in the question)

@JulianWolf I am using 11.1.0. I think "RawJSON" support was added in 10.2.

@totallyhuman It doesn't do an explicit check, but that's what the ImportString[#,"HTML"] bit is all about.

Could you save a byte by using @"alt" at the end?

@numbermaniac Indeed I can.  Can't believe I missed that, thanks!

Java 8, 255 176 bytes
Thanks to @OlivierGrégoire for making me feel like an idiot and 79 bytes off. ;)
i->new java.util.Scanner(new java.net.URL("http://xkcd.com/"+i+"/info.0.json").openStream()).useDelimiter("\\a").next().replaceFirst(".*\"alt\": \"","").replaceFirst("\".*","")

This feels way too heavy... Still heavy, but "okay" for java...
Explanation:

i->{...} Lambda that works like String <name>(int i) throws Exception
new java.util.Scanner(...).setDelimiter("\\a").next() read everything from the given InputStream

new java.net.URL("http://xkcd.com/"+i+"/info.0.json").openStream() this creates an InputStream which references the response body of http://xkcd.com/{comic_id}/info.0.json which is the info page of the desired comic
replaceFirst(".*\"alt\": \"","").replaceFirst("\".*","") Removes everything except for the alt text (till the first double quote)

implicit return

Alternate shorter approach, Java + json.org, 150
i->i==859?new Long(""):new org.json.JSONObject(new org.json.JSONTokener(new java.net.URL("http://xkcd.com/"+i+"/info.0.json").openStream())).get("alt")

This is not my solution so I don't want to post this as the first. All the credits belong to @OlivierGrégoire.

Your imports are missing!. Also, there's nearly zero attempt to golf this answer...

Added. Just under 2^8. At least the size of my programm fits in one byte :)

i->new java.util.Scanner(new java.net.URL("http://xkcd.com/"+i+"/info.0.json").openStream()).useDelimiter("\\a").next().replaceFirst(".*\"alt\": \"","").replaceFirst("\".*","") (176 bytes, careful to the SO's comment cutter characters) And I just barely golfed anything here.

Oh! I thought Scanner#useDelimiter returns void... Better read the docs next time ;)

I just noticed you can create your own Function class that allows you to throw Exception.. Today's not my day.

If you use the basic, official JSON library (need to change the title to "Java + JSON.org"), you can get it down to 131 bytes: i->new org.json.JSONObject(new org.json.JSONTokener(new java.net.URL("http://xkcd.com/"+i+"/info.0.json").openStream())).get("alt")

I think that one doesn't fail on #859.. But wait! There is a java json default library? I always used gson...

It is not required to fail on 859! It says that we may not throw errors on numbers other than 404 and 859! Meaning, we may but aren't forced to throw errors on those numbers.

"However, the program must throw an error when given the numbers 859 or 404." ~Second paragraph of ##Challenge

Then be creative! i->i==859?new Long(""):new org.json.JSONObject(new org.json.JSONTokener(new java.net.URL("http://xkcd.com/"+i+"/info.0.json").openStream())).get("alt") for 150 bytes.

I think that is your own solution and not mine anymore. if you still want me to include it I'll do that :)

It's your call: I won't post it as mine. My goal on this website is to make my brain work, not to gain rep.

But still you've done very well... I should also get my brain working (or go to bed, I've slept too few yesterday)

By the way, there is no official Java Json library (there's a Java EE spec, and Jackson is its reference implementation). The library I mentioned is the library done by the guys who made the Json spec (so it's "official" by Json.org, not by Java). You're free to use whatever library you want. I personally use Gson as well, but the byte-count is unreasonable for golfing.

Python + xkcd, 54 bytes
import xkcd
lambda n:xkcd.getComic(*{n}-{859}).altText

Verification
>>> import sys
>>> sys.tracebacklimit = 0
>>>
>>> import xkcd
>>> f = lambda n:xkcd.getComic(*{n}-{859}).altText
>>>
>>> print f(149)
Proper User Policy apparently means Simon Says.
>>>
>>> f(404)
urllib2.HTTPError: HTTP Error 404: Not Found
>>>
>>> f(859)
TypeError: getComic() takes at least 1 argument (0 given)

I've only just noticed this. Nice golf!

Bash + curl + jq: 73 66 bytes
Shortest answer that doesn't use an xkcd-specific library. jq is a tool for manipulating json objects in the shell, and it comes complete with a parsing language to do that.
curl -Ls xkcd.com/$1/info.0.json|jq -r 'if.num==859then.num.a else.alt end'
curl -Ls xkcd.com/$1/info.0.json|jq -r '(.num!=859//.[9]|not)//.alt'
Expansion below:
curl -Ls - Query, but feel free to redirect (in this case to the https site) and give no unrelated output.
xkcd.com/$1/info.0.json - Shamelessly stolen from another answer.
|jq -r - Run jq in "raw output" mode on the following command.
if
    .num == 859
then
    .num.a # This fails because you can't get the key 'a' from a property that's an integer
else
    .alt # And this pulls out the 'alt' key from our object.
end

Now the script has been re-worked to use // which is the equivalent of a or b in python, and we use a |not to make any true value be considered false, so the second // can print .alt

PHP, 89 86 85 bytes
<?=($a=$argv[1])==859?_:@json_decode(file("http://xkcd.com/$a/info.0.json")[0])->alt;

Returns null for 404 and 859
Save as xkcd.php and run with the comic number...
$ php xkcd.php 386

use $argninstead of $argv[1] , _ instead of NULL

@JörgHülsermann Thanks! I didn't know about _. $argn doesn't seem to work though.

http://php.net/manual/en/features.commandline.options.php $argn is available if you run PHP from the command Line with the -R or the -F option

_ is not equivalent to NULL in PHP. This script throws an error about _ being an undefined constant.

@Andy If a Notice is not allowed "" is a better alternative as NULL Jared here is an example for $argn https://codegolf.stackexchange.com/questions/114146/get-your-dubs-together/114161#114161

@JörgHülsermann ah, I didn't realise you meant use it as an arbitrary character to throw a notice :)

Didn't know he was serving JSON ... nice work!

Per the other PHP answer, you can save one byte by replacing "https" with "http".

The Python one has already won, but regardless...
bash + curl + sed; 88 ~91 heh bytes
printf "$(curl -s https://xkcd.com/2048/info.0.json|sed 's/.*"alt": "//;s/", "img":.*//')\n"

Yay for regex JSON parsing!
EDIT NoLongerBreathedIn noticed (648 days into the future!) that this failed on post 2048 because of an unexpected \" in that entry's JSON. The regex has been updated above; it used to be sed 's/.*alt": "\([^"]\+\).*/\1/').
The printf wrapper neatly handles the fact that Unicode characters are represented in \unnnn notation:
$ printf "$(curl -s https://xkcd.com/1538/info.0.json | sed 's/.*"alt": "//;s/", "img":.*//')\n"
To me, trying to understand song lyrics feels like when I see text in a dream but it hอᵣd t₀ ᵣeₐd aกd  canٖt fཱྀcu༧༦࿐༄

This fails with posts 404 and 859:
404
$ printf "$(curl -s https://xkcd.com/404/info.0.json | sed 's/.*alt": "\([^"]\+\).*/\1/')\n"

<title>404 Not Found</title>

404 Not Found

nginx

859
$ printf "$(curl -s https://xkcd.com/859/info.0.json | sed 's/.*alt": "\([^"]\+\).*/\1/')\n"
Brains aside, I wonder how many poorly-written xkcd.com-parsing scripts will break on this title (or ;;\n$

The $ at the end of the output is my prompt, and the literally-printed \n immediately before it is part of the printf string.
I deliberately used printf because it would parse Unicode and fall over terribly on this specific post.

Also barfs on 2048. I think it barfs on double quotes?

Nice catch. Post updated. Looking at the sed bit, you can see it was looking for alt": " then reading until it found a ". Woops, apparently... (I wonder how many of these solutions would fail a unit test of
e̲͕̲̪v̲̺̗̱̬er̶͎y̦ ͖̙̝̦s҉̟̜i͓͜n̡g̸l͎̠̹̪͈͉͚͟e̩͙̙̣̲͕͘ ̴͎͉̳̮a̢͕l̯̦̮̥̺̱̤t̕ ͕̮̪̙̬̲̪͘t̰͙̘̪̼ͅex̺͕͍͔̠̮ͅt̪͔̀? :P)

PHP 5.3, 280 268 262 261 180 bytes

1. Saved 11 thanks to some of Roman Gräf's suggestions
2. Saved 1 byte by using http link instead of https
3. Saved another 6 bytes thanks to Kevin_Kinsay
4. Saved another 1 byte with Andy's suggestion
5. A major revision:

suppressed errors with @ instead of changing libxml_use_internal_errors
used implode(0,file("")) instead of file_get_contents("") (2 bytes)
moved the $x definition inside the if
Using throw 0 instead of actually throwing an exception (it crashes the program)
with the @ I now can omit the comicLink replace.

My first try on golfing.
The DOMDocument breaks when encounters dobule ID comicLinks so I had to remove these. There's probably a nicer way of doing that.
Crashes when trying to get no. 859 ;)
<?php if(($x=$argv[1])==859)throw 0;$a=new DOMDocument;$b=@$a->loadHTML(implode(0,file("http://xkcd.com/$x")));echo $a->getElementsByTagName('img')->item(1)->getAttribute('title');

Welcome to PPCG! I think you can remove the test whether $x==404 because the other code will fail on the 404 response... Also you can replace throw new Exception by a die call and remove the brackets around throw new Exception("")/die because it is only a single statement

Thanks!
I wasn't sure if die() would count as "throw an error" ;)

Use "1" instead of 'true' on libxml_use_internal_errors. You can probably pass 0 to the Exception and save one quote equivalent.  Closing ?> should be optional.

Variables are interpolated inside double quotes, so "http://xkcd.com/".$x can become "http://xkcd.com/$x" saving one byte :)

BTW, +1 for using "proper" parsing technique (XML parser) as opposed to my ugly regex hack ;)

..Just managed to cut 81 bytes :D

Python 2, 115 106 bytes
-8 bytes thanks to ovs. -1 byte thanks to Jonathan Allan.
Just thought I'd put a standard library answer out there.
lambda n:[json.load(urllib.urlopen('http://xkcd.com/%d/info.0.json'%n))['alt']][n==859]
import urllib,json

lambda n:[json.load(urllib.urlopen('https://xkcd.com/%d/info.0.json'%n))['alt']][n==859] for -8 bytes.

Should work with http:// too saving a byte.

PHP, 160 bytes
<? preg_match_all('/(tle=\")(.+)(\")\sa/',join(0,file('http://xkcd.com/'.$argv[1])),$a);echo(strstr($c=$a[2][0],'Brains asid'))?$b:html_entity_decode($c,3);

Hang on ... this isn't to spec.  Fixing ...

Fixed.  Had to add about 50 bytes though ... :(

And a few more to handle the ' :( :(

Shaved 1 byte with "implode/file"...

Shaved 10 bytes on the regexp and by using join (alias to implode()), etc.

Nice job. You could probably reduce "Brains aside" to "Brains a"

you can remove 7 chars removing the echo and moving the $c assign inside the substr

Why check the substring instead of check the input?

@BetaDecay because not checking for the input number gives extra points

That's not what I meant. Your program should be poorly written: whether it be the unmatched parentheses, the semicolons or the unmatched quotation marks which break the program

@BetaDecay well, a script that depends on content looks poorly written to me. Any other title starting like that would break it.
Kevin_Kinsey you can replace ENT_QUOTES by its value=3

Thanks Einacio ... I was looking for that but couldn't figure it from the manual.

Ooh, I need to update it though ... the last version I wc'ed used something besides 'Brains aside' ... hopefully I can get back on this after work and the theatre tonight....

JavaScript (ES6), 177 175 bytes
p=(x)=>{eval(`console.log("${x.alt}")`)};f=(y)=>{var d=document,e=d.createElement("script");e.src=`//dynamic.xkcd.com/api-0/jsonp/comic/${y}?callback=p`;d.body.appendChild(e)}}

Paste this into your browser console, then execute f(859) or f(404) etc - those two should error in the console, despite not being hard coded, the others display.
First post in a while, sorry if it doesn't quite meet the rules...!

Use x=> instead of (x)=>.

APL (Dyalog Unicode), 110 73 bytes
{'('∊⎕←⍵.safe_title:-⍵⋄⍵.alt}⎕JSON∊⎕SH∊'curl -L xkcd.com/'⍞'/info.0.json'

-37 bytes from Adám.
Explanation
⎕JSON∊⎕SH∊'curl -L xkcd.com/'⍞'/info.0.json'
                                     ⍝ Get the json data for the required page
                                     ⍝ Using ⎕SH to execute curl shell command
'('∊⎕←⍵.safe_title:                  ⍝ If the safe title does not contain a bracket,
                    ⋄⍵.alt           ⍝ Print alt text
                  -⍵                 ⍝ Otherwise negate json data(Domain error)

It's does not match. I copied the wrong code. Sorry for the confusion.

61: (⎕JSON∊⎕SH'/859/'⎕R''∊'curl -L xkcd.com/'⍞'/info.0.json').alt

Btw, you don't need Extended for this. And the TIO link can't work.

Could you update the explanation?

Sure, I'll update it.

Javascript (ES6), 118 96 94 bytes
f=n=>fetch(`//xkcd.com/${n}/info.0.json`).then(x=>x.json()).then(y=>eval(`alert('${y.alt}')`))

You can paste that in your browser console and run f(123). But do so on a page that is already on xkcd.com or else you'll see a CORS error.
For 404, it fails with:

Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

For 859, it fails with:

Uncaught (in promise) SyntaxError: missing ) after argument list

Update: the lastest version properly checks the alt text instead of checking for just 859 and shaves of another 2 bytes.

Sadly, this fails on any titletext containing an apostrophe (e.g. 1084).

Perl, 129 167 bytes
use LWP::Simple;use HTML::Entities;print decode_entities($1)if(get("http://www.xkcd.com/$ARGV[0]")=~m/text: ([^<]*)\}\}<\/div>/)

EDIT: Psyche it's actually
use LWP::Simple;use HTML::Entities;$x=$ARGV[0];if($x==404||$x==859){die}else{print decode_entities($1)if(get("http://www.xkcd.com/$x")=~m/text: ([^<]*)\}\}<\/div>/)}

Import HTML decoding and HTTP accessing, then print the group matching the (...) in
{{Title text: (...)}}

(saving a bit by omitting {{Title  from the query)
For 404 and 859, death.

What do you mean by "properly handles 859"?

@BetaDecay It prints the actual alt-text

the program must throw an error when given the numbers 859 or 404

What is "throw an error" defined as?

Nvm die is short enough

s/print/say/g also you can use -MModule

BASH, 111 108 bytes
    a=$(cat)
    curl -s https://xkcd.com/$a/ |grep -oP '(?<=Title text:)([^}}]*)'
    [ $a = 404 ] && echo "$a not found"

a=#;curl -s https://xkcd.com/$a/ |grep -oP '(?<=Title text:)([^}}]*)';[ $a = 404 ] && echo "$a not found"

To Run:
change # to number of comic. Run from command line.
Thanks @Ale for the suggestion!

Why reading from standard input using cat instead of just using $1 from the command line? It would save some bytes...


text:
Is my number a de Polignac number?
A number is a de Polignac number if and only if it is odd and cannot be represented in the form p + 2n where n is a non-negative integer and p is a prime integer.
Task
Write some code that takes a positive integer and determines if it is a de Polignac number.  You may output two distinct values one for true and one for false.  You should aim to minimize your byte count.
Test Cases
For positive cases here's the OEIS
1, 127, 149, 251, 331, 337, 373, 509, 599, 701, 757, 809, 877, 905, 907, 959, 977, 997, 1019, 1087, 1199, 1207, 1211, 1243, 1259, 1271, 1477, 1529, 1541, 1549, 1589, 1597, 1619, 1649, 1657, 1719, 1759, 1777, 1783, 1807, 1829, 1859, 1867, 1927, 1969, 1973, ...

Here are some negative cases:
22, 57

Can we have truthy and falsy outputs instead of two distinct outputs?

@Okx I'm going to say no.

Let us continue this discussion in chat.

Err... for the negative cases, it's basically any number not in the OEIS right? Making sure I've not missed something obvious.

@MagicOctopusUrn Yes.

Japt, 9 14 13 bytes
o!²mnU dj |Uv

Test it online! or Find all de Polignac integers under 1000.
Outputs 1 for falsy inputs and 0 for truthy.
Explanation
 o!²  mnU dj |Uv
Uo!p2 mnU dj |Uv  : Ungolfed
                  : Implicit: U = input integer (e.g. 9)
Uo                : Create the range [0..U), and map each item X to
  !p2             :   2 ** X.               [1, 2, 4, 8, 16, 32, 64, 128, 256]
      m           : Map each of these powers of 2 by
       nU         :   subtracting from U.   [8, 7, 5, 1, -7, -23, -57, -119, -247]
          d       : Return whether any item in the result is
           j      :   prime.                (5 and 7 are, so `true`)
             |    : Take the bitwise OR of this and
              Uv  :   U is divisble by (missing argument = 2).
                  : This gives 1 if U cannot be represented as p + 2^n or if U is even.
                  : Implicit: output result of last expression

This seems to be giving the wrong results for 2 & 3; it's returning false but they're not de Polignac numbers.

@Shaggy 3 is fixed, but we didn't have to handle even cases at first. Fixing.

@Shaggy Fixed now.

I was about to say it was a good thing the fix for 3 didn't cost any bytes then I saw the fix for 2 - Ouch!

:O +1 for competitive program that doesn't look like encoding error

JavaScript (ES6),  56 54  53 bytes
Returns \$0\$ or \$1\$.
f=(n,p=1,x=y=n-p)=>n>p?y%--x?f(n,p,x):x!=1&f(n,p*2):n

Try it online!
How?
We start with \$p = 1\$. We test whether \$y = n - p\$ is composite and yield a boolean accordingly. The next test is performed with \$p \times 2\$.
As soon as \$p\$ is greater than \$n\$, we stop the recursion and return \$n\$.
The results of all iterations are AND'd together, coercing the boolean values to either \$0\$ or \$1\$.
Provided that all intermediate results were truthy, we end up with a bitwise test such as:
1 & 1 & 1 & n
This gives \$1\$ if and only if \$n\$ is odd, which is the last condition required to validate the input as a de Polignac number.

Great technique. Probably the only valid answer that doesn't explicitly say n%2 or similar :P

This has false negatives for de Polignac numbers of the form 2^M+1, such as 262145 and 2097153 (subsequent ones are 4722366482869645213697, 38685626227668133590597633, 5192296858534827628530496329220097, etc.). It's not the largeness of the numbers that's a problem, since it correctly identifies 262139, 262259, 2097131, and 2097187, for example. Of course due to the recursion, I had to enlarge the stack size to something very huge to test this, and only tested the ranges around the first two 2^M+1 de Polignac numbers listed above.

@Deadcode Thanks for reporting this. Now fixed.

@Arnauld I don't think that fixes it. I haven't managed to get it to run in JavaScript with an increased stack size, but when I apply your patch to my C port of your function, it still has the bug.

@Deadcode I think a correct port would be this one.

@Arnauld Ah, you're right :) Just to be certain, I did this and sure enough, it's fixed.

I finally figured out how to test this properly :)

@Deadcode Neat! :)

Jelly, 11 10 bytes
Saved 1 byte thanks to @Dennis
Ḷ2*³_ÆPS<Ḃ

Try it online!
How it works
Ḷ2*³_ÆPS<Ḃ   Main link. Argument: n (integer)
Ḷ            Lowered range; yield [0, 1, 2, ..., n-1].
 2*          Reversed exponentiation with 2; yield [1, 2, 4, ..., 2**(n-1)].
   ³_        Reversed subtraction with the input; yield [n-1, n-2, n-4, ..., n-2**(n-1)].
     ÆP      Replace each item with 1 if it is prime, 0 otherwise.
       S     Sum; yield a positive integer if any item was prime, 0 otherwise.
         Ḃ   Yield n % 2.
        <    Yield 1 if the sum is less than n % 2, 0 otherwise.
             This yields 1 if and only if the sum is 0 and n is odd.

Ḷ2*⁸_ÆPS<Ḃ  saves a byte. https://tio.run/##ASQA2/9qZWxsef//4bi2Mirigbhfw4ZQUzzhuIL/MTAwMMOHw5BmWf8

@Dennis Thanks, I knew there had to be a 3-byte alternative to ¬;ḂẠ. S<Ḃ is way outside the box though, at least for me :-)

05AB1E, 9 8 bytes
-1 byte thanks to Emigna
Ýo-pZ¹È~

Outputs 0 for truthy inputs and 1 for falsy inputs.
Try it online!

1å could be Z.

@Emigna Ah. I knew there was a 1-byte alternative to that!

Python 2, 60 57 56 bytes
f=lambda n,k=1,p=-1:k/n or(n-k&n-k-p%k>0)&n&f(n,k+1,p*k)

Try it online!

Wow, this is impressively inefficient. Prime test via Wilson's theorem. On the plus side it works correctly for 262145 and 2097153 (assuming unlimited stack and bignum size); some of the other submissions don't. Its is-prime algorithm yields "truthy" for 4, because (-6)%4=2, but this ends up not being a problem because even numbers are rejected by the &n&. The number 5 would be a false negative if it were a de Polignac number, because 1+4=5, but this isn't a problem because 2+3=5 anyway.

Jelly, 10 bytes
An alternative 10-byte Jelly submission to the one already posted.
_ÆRBS€’×ḂẠ

A monadic link returning 1 for de Polignac numbers and 0 otherwise.
Try it online! or see those under 1000.
How?
_ÆRBS€’×ḂẠ - Link: number, n  e.g.  1    3      5                  6                   127
 ÆR        - prime range            []   [2]    [2,3,5]            [2,3,5]             [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127]
_          - subtract from n        []   [1]    [3,2,0]            [4,3,1]             [125,124,122,120,116,114,110,108,104,98,96,90,86,84,80,74,68,66,60,56,54,48,44,38,30,26,24,20,18,14,0]
   B       - convert to binary      []   [[1]]  [[1,1],[1,0],[0]]  [[1,0,0],[1,1],[1]  [[1,1,1,1,1,0,1],[1,1,1,1,1,0,0],[1,1,1,1,0,1,0],[1,1,1,1,0,0,0],[1,1,1,0,1,0,0],[1,1,1,0,0,1,0],[1,1,0,1,1,1,0],[1,1,0,1,1,0,0],[1,1,0,1,0,0,0],[1,1,0,0,0,1,0],[1,1,0,0,0,0,0],[1,0,1,1,0,1,0],[1,0,1,0,1,1,0],[1,0,1,0,1,0,0],[1,0,1,0,0,0,0],[1,0,0,1,0,1,0],[1,0,0,0,1,0,0],[1,0,0,0,0,1,0],[1,1,1,1,0,0],[1,1,1,0,0,0],[1,1,0,1,1,0],[1,1,0,0,0,0],[1,0,1,1,0,0],[1,0,0,1,1,0],[1,1,1,1,0],[1,1,0,1,0],[1,1,0,0,0],[1,0,1,0,0],[1,0,0,1,0],[1,1,1,0],0]
    S€     - sum €ach               []   [1]    [2,1,0]            [1,2,1]             [6,5,5,4,4,4,5,4,3,3,2,4,4,3,2,3,2,2,4,3,4,2,3,3,4,3,2,2,2,3,0]
      ’    - decrement              []   [0]    [1,0,-1]           [0,1,0]             [5,4,4,3,3,3,4,3,2,2,1,3,3,2,1,2,1,1,3,2,3,1,2,2,3,2,1,1,1,2,-1]
        Ḃ  - n mod 2                1    1      1                  0                   1
       ×   - multiply               []   [0]    [1,0,-1]           [0,0,0]             [5,4,4,3,3,3,4,3,2,2,1,3,3,2,1,2,1,1,3,2,3,1,2,2,3,2,1,1,1,2,-1]
         Ạ - all truthy?            1    0      0                  0                   1

Took me about 10 minutes to understand how this works... great technique, I couldn't think of a good way to check if an array contained no powers of two :-)

Python 2, 99 bytes
lambda n:n&1-any(n-2**k>1and all((n-2**k)%j for j in range(2,n-2**k))for k in range(len(bin(n))-2))

Try it online!
-4 bytes thanks to Leaky Nun
-2 bytes thanks to Wondercricket
+8 bytes to fix a mistake
-1 byte thanks to Mr. Xcoder
-3 bytes thanks to Einkorn Enchanter
+12 bytes to fix a mistake

I think this is also a Python 3 compatible answer?

This has a false negative for 1 and for all de Polignac numbers of the form 2^M+1, such as 262145 and 2097153 (subsequent ones are 4722366482869645213697, 38685626227668133590597633, 5192296858534827628530496329220097, etc.). It's not the largeness of the numbers that's a problem, since it correctly identifies 262139, 262259, 2097131, and 2097187, for example.

@Deadcode explicit check to make sure the "prime" isn't 1; should work now

Regex (ECMAScript), 97 bytes
This problem posed an interesting case for working around the problem of lacking non-atomic lookahead. And it's the only time so far that I've had a good reason to put both versions of the power of 2 test, ((x+)(?=\2$))*x$ and (?!(x(xx)+)\1*$), in the same regex, and the only time so far I've needed to protect the prime test against matching 1, as (?!(xx+)\1+$)xx, when used in a larger regex.
^(?!(xx)*$|(x+)((?!(xx+)\4+$).*(?=\2$)((x+)(?=\6$))*x$|(?!(x(xx)+)\7*$).*(?=\2$)(?!(xx+)\9+$)xx))
Try it online!
# For the purposes of these comments, the input number = N.
^
# Assert that N is not the sum of a prime number and a power of 2.
(?!
    (xx)*$                 # Assert that N is odd.
|
    # Since we must cycle through all values for a number X and a corresponding number
    # N-X, this cannot be in an atomic lookahead. The problem then becomes that it
    # consumes characters. Thus we must let X be the larger of the two and N-X be the
    # smaller, and do tests on X followed by tests on N-X. We can't just test X for
    # being prime and N-X for being a power of 2, nor vice versa, because either one
    # could be smaller or larger. Thus, we must test X for being either prime or a
    # power of 2, and if it matches as being one of those two, do the opposite test on
    # N-X.
    # Note that the prime test used below, of the form (?!(xx+)\2+$), has a false match
    # for 0 and 1 being prime. The 0 match is harmless for our purposes, because it
    # will only result in a match for N being a power of 2 itself, thus rejecting
    # powers of 2 as being de Polignac numbers, but since we already require that N is
    # odd, we're already rejecting powers of 2 implicitly. However, the 1 match would
    # break the robustness of this test. There can be de Polignac numbers of the form
    # 2^M+1, for example 262145 and 2097153. So we must discard the 1 match by changing
    # the prime test to "(?!(xx+)\2+$)xx". We only need to do this on the N-X test,
    # though, because as X is the larger number, it is already guaranteed not to be 1.
    (x+)           # \2 = N-X = Smaller number to test for being prime or a power of 2;
                   # tail = X = larger number to test for being prime or a power of 2.
    (
        (?!(xx+)\4+$)      # Test X for being prime.
        .*(?=\2$)          # tail = N-X
        ((x+)(?=\6$))*x$   # Test N-X for being a power of 2. Use the positive version
                           # since it's faster and doesn't have a false match of 0.
    |
        (?!(x(xx)+)\7*$)   # Test X for being a power of 2. Use the negative version
                           # because the testing of X has to be in a lookahead, and
                           # putting the positive version in a positive lookahead would
                           # be worse golf. It doesn't matter that this can have a false
                           # match of 0, because X is guaranteed never to be 0.
        .*(?=\2$)          # tail = N-X
        (?!(xx+)\9+$)xx    # Test N-X for being prime. We must prevent a false match of
                           # 1 for the reason described above.
    )
)

Regex (ECMAScript + molecular lookahead), 53 52 bytes
^(?!(xx)*$|(?*xx+(((x+)(?=\4$))*x$))\2(?!(xx+)\5+$))
# For the purposes of these comments, the input number = N.
^
# Assert that N is not the sum of a prime number and a power of 2.
(?!
    (xx)*$                   # Assert that N is odd.
|
    (?*
        xx+                  # Force N - \2 to be > 1, because the prime test used
                             # below has a false match of 1, which would otherwise
                             # give us false negatives on de Polignac numbers of the
                             # form 2^M+1, such as 262145 and 2097153.
        (((x+)(?=\4$))*x$)   # Cycle through subtracting all possible powers of 2 from
                             # tail, so we can then test {N - {power of 2}} for being
                             # prime.
                             # \2 = the power of 2
    )
    \2                       # tail = N - \2
    (?!(xx+)\5+$)            # Test tail for being prime. If it matches, this will fail
                             # the outside negative lookahead, showing that N is not a
                             # de Polignac number.
)

This version is not only much cleaner, but much faster, because instead of having to cycle through all possible ways that N is the sum of two numbers, it can just cycle through subtracting every power of 2 from N and test the difference for being prime.
The molecular lookahead can be easily converted to a variable-length lookbehind:
Regex (.NET or ECMAScript 2018), 55 54 bytes
^(?!(xx)*$|xx+(((x+)(?=\4$))*x$)(?<=(?<!^\5+(x+x))\2))
Try it online! (.NET)
Try it online! (ECMAScript 2018)
# For the purposes of these comments, the input number = N.
^
# Assert that N is not the sum of a prime number and a power of 2.
(?!
    (xx)*$                 # Assert that N is odd.
|
    xx+                    # Force N - \2 to be > 1, because the prime test used
                           # below has a false match of 1, which would otherwise
                           # give us false negatives on de Polignac numbers of the
                           # form 2^M+1, such as 262145 and 2097153.
    (((x+)(?=\4$))*x$)     # Cycle through subtracting all possible powers of 2 from
                           # tail, so we can then test {N - {power of 2}} for being
                           # prime.
                           # \2 = the power of 2
    (?<=
        (?<!^\5+(x+x))     # Test tail for being prime. If it matches, this will fail
                           # the outside negative lookahead, showing that N is not a
                           # de Polignac number.
        \2                 # tail = N - \2
    )
)

Your regex can be optimised to ^(?!(x+)((?!(xx+)\3+$)x*(?!(x(xx)+)\4*$)|x(?!(x(xx)+)\6*$)x*(?!(xx+)\8+$)x)?\1$) without too much difficulty. Then, with some careful thought, can be golfed further to ^(?!(x+)((x?)(?!(x(x\3)+)\4+$)x*(?!(x(xx)+|\3\3+)\6+$)\3)?\1$). Shorter may yet be possible

My shortest is very slow, though

oh, (x(xx)+|\3\3+) -> (x\3?(xx)+)

Mathematica, 41 bytes
OddQ@#&&!Or@@PrimeQ[#-2^Range[0,Log2@#]]&

There's no builtin for this? Wow, I'm surprised.

It's so annoying here that Mathematica deems negative primes to be prime, or else you could save bytes by replacing PrimeQ[#-2^Range[0,Log2@#]] with PrimeQ[#-2^Range[0,#]] and then by PrimeQ[#-2^Range@#/2].

Pari/GP, 34 bytes
n->n%2*prod(i=0,n,!isprime(n-2^i))

Try it online!

PHP, 75 bytes
prints 1 for truthy and 0 for falsy

for($t=1&$argn;0<$d=$n=$argn-2**$i++;$d-1?:$t&=0)for(;--$d&&$n%$d;);echo$t;

Try it online!
Try it online! Polignac Integers under 10000

Brachylog, 15 13 bytes
/₂ℕ|>ṗ;?-₍ḃ+1

Try it online!
Output de Polignac numbers upto 1000.
Returns false. for de Polignac numbers and true. otherwise.
Based on @LeakyNun's deleted answer, with a few bugfixes (posted with their permission).
(-2 bytes by using @Jonathan Allan's method to check if the number is a power of two.)
The given number is not a de Polignac number if:
/₂ℕ              It's an even number
   |>ṗ           Or there exists a prime number less than the input
      ;?-₍       which when subtracted from the input
          ḃ      gives a result that has a binary form
           +     such that the sum of the bits
            1    is 1

=h2 would be 1 byte shorter but it doesn't work for 3 either.

Note to (non mobile) self: 14 bytes Try it online!. Inspired by Jonathan Allan's Jelly answer.

13 Try it online!

Reminder for your notes i guess?

@Kroppeb Heh, thanks, I didn't even remember making these comments (while half-asleep, probably).

(Also, sorry for the delay in response, I've (finally!) moved to an SSD, and so was away from the site for a while setting things back up.)

This does not work, at least not on TIO. Both the 13 and 15 byte versions identify a list of numbers that bear no resemblance to de Polignac numbers, regardless of whether true/false is inverted.

@Deadcode It used to be working when this was posted, and something about division seems to have changed in the meantime - for eg. Try it online! returns false instead of 64. The change is likely from this commit to the language, but I haven't been active here in a while, so don't know if it's intentional or a bug.

Jelly, 13 bytes
ÆRạl2=Ḟ$o/o‘Ḃ

Try it online!
ÆRạl2=Ḟ$o/     Main link; argument is z
ÆR             Generate all primes in the range [2..z]
  ạ            Absolute difference with z for each prime
   l2          Logarithm Base 2
     =Ḟ$       For each one, check if it's equal to its floored value (i.e. if it is an integer)
        o/     Reduce by Logical OR to check if any prime plus a power of two equals the z
          o‘Ḃ  Or it's not an odd number. If it's not an odd number, then automatically return 1 (false).

Outputs 1 for false and 0 for true.

Ḷ2*ạfÆRṆ then check for parity

@LeakyNun Ḷ2*ạfÆRṆo‘Ḃ returns 1 for both 127 and 22; that's not right. Unless that's not what you suggested.

you need to use and, not or. (or you can remove my last negation and then proceed to do it in 9/10 bytes)

@LeakyNun Your snippet there gives 0 for 149.

@ETHproductions right. Changing ạ to _@ fixes it.

This throws an error for 1, which is one of the test cases.

Perl 6, 55 bytes
{so$_%2&&$_∉((1,2,4...*>$_) [X+] grep &is-prime,^$_)}

Try it online!

(1, 2, 4 ... * > $_) is a sequence of the powers of two until the input argument (Perl infers the geometric series from the provided elements).
grep &is-prime, ^$_ is the list of prime numbers up to the input argument.
[X+] evaluates the sum of all elements of the cross product of the two series.

I could have done without the so for two bytes less, but then it returns two distinct falsy values (0 and False).

Axiom, 86 bytes
f(n:PI):Boolean==(~odd?(n)=>false;d:=1;repeat(n<=d or prime?(n-d)=>break;d:=d*2);n<=d)

test and results
(21) -> for i in 1..600 repeat if f(i) then output i
   1
   127
   149
   251
   331
   337
   373
   509
   599

Haskell, 104 102 bytes
p x=[x]==[i|i<-[2..x],x`mod`i<1]
h k|even k=1>2|2>1=notElem k$((+)<$>(2^)<$>[0..k])<*>filter(p)[1..k]

Explanation

p is a function that finds prime numbers (very inefficient!)
Creating a list of (+) applied to 2^ partial function which is applied to a list [0..input]
Applying the above to a list filtered 1 to input for primes
Resulting cartesian product of every possible value is searched to ensure input does not exist in cartesian product
Guarded to ensure that an even input is automatically false.

UPDATE: Shout out to Einkorn Enchanter for golfing two bytes!

p x=[x]==[i|i<-[2..x],x\mod`i<1]` is a shorter primality test.

@EinkornEnchanter Great catch!  You golfed me two bytes!

You can also do filter p[1..k] instead of filter(p)[1..k]

Common Lisp, 134 bytes
(lambda(x)(flet((p(x)(loop for i from 2 below x always(>(mod x i)0))))(or(evenp x)(do((j 1(* j 2))(m()(p(- x j))))((or(>= j x)m)m)))))

Return NIL when the argument is a Polignac number, T otherwise.
Try it online!
Ungolfed:
(lambda (n)
  (flet ((prime? (x)                 ; x is prime
           loop for i from 2 below x ; if for i in [2..n-1]
           always (> (mod x i) 0)))  ; is x is not divisible by i
    (or (evenp n)                    ; if n is even is not a Polignac number
        (do ((j 1( * j 2))           ; loop with j = 2^i, i = 0, 1,...
             (m () (prime? (- n j)))); m = n - 2^i is prime?
            ((or (>= j n)            ; terminate if 2^i ≥ n
                 m)                  ; or if n - 2^i is prime
             m)))))                  ; not a polignac if n - 2^i is prime

APL (Dyalog Extended), 12 bytes
⍱2∘|⍲0⍭⊢-2*…

Try it online!
Anonymous prefix tacit function. Returns 1 for truthy, 0 for falsy.
Largely based on ETHProductions' Japt answer.
Thanks to @Adám for helping with golfing my original answer, and for making Dyalog Extended for that matter.
How:
⍱2∘|⍲0⍭⊢-2*…   ⍝ Tacit prefix function; input will be called ⍵
           …    ⍝ Inclusive Range [0..⍵]
         2*     ⍝ 2 to the power of each number in the range
       ⊢-       ⍝ Subtract each from ⍵
     0⍭         ⍝ Non-primality check on each resulting number
    ⍲           ⍝ Logical NAND
 2∘|            ⍝ Mod 2
⍱               ⍝ Not any (bitwise OR reduction, then negated)

Julia 0.4, 31 bytes
n->n%2*!any(ispow2,n-primes(n))

Try it online!

Python 2, 98 bytes
lambda x:not(x%2<1or any((lambda x:x>1and all(x%j for j in range(2,x)))(x-2**i)for i in range(x)))

Try it online!

Pyth, 14 bytes
&%Q2!smP-^2dQl

Try it!

C# (Visual C# Interactive Compiler), 107 bytes
x=>{var r=Enumerable.Range(2,x);return x%2>0&r.All(p=>r.Any(d=>d<p&p%d<1)|r.All(n=>x!=p+Math.Pow(2,n-2)));}

Try it online!
Not the most efficient code, but seems to work. My original solution filtered for primes before testing them in the formula and it performed much better. The current version is 11 bytes shorter.
// input x is an integer
x=>{
  // we need to generate several
  // ranges. since this is verbose,
  // generate 1 and keep a reference
  var r=Enumerable.Range(2,x);
  // this is the main condition
  return
     // input must be odd
     x%2>0&
     // generate all possible p's
     // over our range and ensure that
     // they satisfy the following
     r.All(p=>
       // either p is not prime
       r.Any(d=>d<p&p%d<1)
       |
       // or there is no n that satisfies
       // the formula: x=p+2^n
       r.All(n=>x!=p+Math.Pow(2,n-2))
     );
}

APL(NARS) 80 chars, 160 bytes
∇r←f w;n
r←¯1⋄→0×⍳(w≤0)∨w≥9E9⋄r←0⋄→0×⍳0=2∣w⋄n←r←1
→0×⍳w≤n⋄→3×⍳0πw-n⋄n×←2⋄→2
r←0
∇

The function 0π is the function that return its argument is prime or not. For me this function has not be recursive so it is a little more long... Test:
  {1=f ⍵:⍵⋄⍬}¨1..1000
1  127  149  251  331  337  373  509  599  701  757  809  877  905  907  959  977  997

for input <=0 or input >=9E9 it return ¯1 (error)
  f¨0 ¯1 ¯2 900000000001
¯1 ¯1 ¯1 ¯1

source: Stack Exchange

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

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

sort: votes


text:
Convert CMYK values to RGB
Given Color codes in CMYK, convert it to RGB value.
Input:
string of 4 integers(ranging from 0-100) separated by space
86 86 0 43
28 14 0 6
0 41 73 4

Output:
#141592
#ABCDEF
#F49043

Shortest code wins!

HINT: For converting CMYK to RGB you may use formula such as:
Red   = 255 x (1 - Cyan/100)    x (1 - Black/100)
Green = 255 x (1 - Magenta/100) x (1 - Black/100)
Blue  = 255 x (1 - Yellow/100)  x (1 - Black/100)

and use these three variables to get the value in #RRGGBB format

Can we take CMYK values as decimals from 0 to 1 or is it required to do 0 to 100?

Also, are we supposed to input multiple CMYK codes at once or just one and convert it?

Can we take the input as a list of numbers or does it have to be a delimited string?

Is the output required to have a # at the beginning?

@Mr.Xcoder Yes it is required.

@BusinessCat String

@HyperNeutrino It is okay if your code just works for one input and converts it. But, you can also submit code that handles multiple CMYK codes as well. However, try to reduce source code size as much as you can.

@HyperNeutrino 0-100.

The input / output that you provided doesn't match the formula, also how should we handle the rounding?

Is uppercase required for #RRGGBB format?

@Rod It's a bit unclear yet how floating-point inaccuracies should be handled.

PHP, 90 bytes
<?="#";for($c=explode(" ",$argn);$i<3;)printf("%02X",255*(1-$c[+$i++]/100)*(1-$c[3]/100));

Try it online!

Javascript (ES6), 106 bytes

f=
(s,z=s.split` `,k=z.pop())=>'#'+z.map(x=>('0'+(.0255*(100-x)*(100-k)+.5|0).toString(16)).slice(-2)).join``
<input id=i value="28 14 0 6"/><button onclick="o.innerHTML=f(i.value)"/>Go</button>

Python 3, 100 98 bytes
-2 bytes thanks to Rod.
lambda s:'#'+''.join('%02X'%int(.0255*(100-int(i))*(100-int(s.split()[3])))for i in s.split()[:3])

Try it online!

Golfing the math. o0 Thanks!

Retina, 103 bytes
\d+
$*1;100$*
(1*);\1

1(?=.* (1*))|1
$1
1
51$*
(1{32000})*(1{2000})*1*.
;$#1;$#2
T`d`L`1\d
;B\B|;

^
#

Try it online! Note: This code is very slow, so please don't hammer Dennis's server. Explanation:
\d+
$*1;100$*
(1*);\1

Convert each number to unary and subtract from 100.
1(?=.* (1*))|1
$1

Multiply all the numbers by the last number, which is deleted.
1
51$*

Multiply by 51, so that once we divide by 2000, we get 100 * 100 * 51 / 2000 = 255 as desired.
(1{32000})*(1{2000})*1*.
;$#1;$#2

Divide by 32000 and floor divide the remainder by 2000, thus generating a pair of base 16 values, although sadly themselves still written in base 10.
T`d`L`1\d
;B\B|;

Convert from base 10 to base 16.
^
#

Insert the leading #.

Jelly, 24 bytes
ḲV÷ȷ2ạ1×Ṫ$×255ḞṃØHṙ1¤ṭ”#

A full program which prints the result.
Try it online!
Note: rounding rather than flooring may be used by inserting the two bytes of code +. between 255 and Ḟ.
How?
ḲV÷ȷ2ạ1×Ṫ$×255ḞṃØHṙ1¤ṭ”# - Main link: list of character, s
Ḳ                        - split at spaces (makes a list of lists of characters)
 V                       - evaluate as Jelly code (makes a list of the decimal numbers)
   ȷ2                    - literal 100
  ÷                      - divide (vectorises to yield [C/100, M/100, Y/100, K/100])
     ạ1                  - absolute difference with 1 -> [1-(C/100),...]
         $               - last two links as a monad:
        Ṫ                -   tail (this is 1-(K/100))
       ×                 -   multiply (vectorises across the other three)
          ×255           - multiply by 255 (vectorises)
              Ḟ          - floor to the nearest integer
                    ¤    - nilad followed by link(s) as a nilad:
                ØH       -   hex-digit yield = "0123456789ABCDEF"
                  ṙ1     -   rotate left by 1 -> "123456789ABCDEF0"
               ṃ         - base decompress (use those as the digits for base length (16))
                      ”# - literal character '#'
                     ṭ   - tack
                         - implicit print

Another way to round would be _.Ċ instead of +.Ḟ...but the latter is maybe more widely used.

Java 8, 166 bytes
s->{int i=0,c[]=java.util.Arrays.stream(s.split(" ")).mapToInt(Byte::new).toArray();for(s="#";i<3;)s+=s.format("%02X",(int)(.0255*(100-c[i++])*(100-c[3])));return s;}

Try it online!

C++ (gcc), 169 166 bytes
#import<iostream>
#import<iomanip>
#define F(x)int(.0255*(100-x)*(100-k))
int main(){
int c,m,y,k;
std::cin>>c>>m>>y>>k;
std::cout<<"#"<<std::hex<<F(c)<<F(m)<<F(y);
}

Try it online!
Using the optimized formula. Added +.5 to convert CMYK=0 0 0 0 correct to RGB=0xffffff which is not necessary.

Javascript, 104 bytes
s=>"#"+[0,1,2].map(n=>("0"+((255-2.55*s[n])*(1-s[3]/100)|0).toString(16)).slice(-2),s=s.split` `).join``

Example code snippet:

f=

s=>"#"+[0,1,2].map(n=>("0"+((255-2.55*s[n])*(1-s[3]/100)|0).toString(16)).slice(-2),s=s.split` `).join``

console.log(f("86 86 0 43"))
console.log(f("28 14 0 6"))
console.log(f("0 41 73 4"))

Python 3, 114 110 108 106 104 bytes

@xnor saved 4 bytes: deleted unnecessary code
@rod saved 2 bytes: shorter formula
saved 2+2 bytes: range[3] as [0,1,2], unwanted [] removed

n=input().split()
print('#'+''.join(hex(int(.0255*(100-int(n[i]))*(100-int(n[3]))))[2:]for i in[0,1,2]))

Try it online!

Ruby, 92+1 for -p flag= 93 bytes
gsub(/(.+) (.+) (.+) (.+)/){'#%X%X%X'%[$1,$2,$3].map{|n|255*(1-n.to_i/1e2)*(1-$4.to_i/1e2)}}

Try it online!

Perl 5, 58 52 + 1 (-a) = 59 53 bytes
printf"#%2X%2X%2X",map{.0255*(100-$_)*(100-$F[3])}@F

Try it online!

05AB1E, 18 bytes
$#т/-¤s¨*255*hJ'#ì

Try it online!
-1 thanks to kalsowerus.
Has floating-point inaccuracies, so results might be off-by-one, but the formula in the question is used.

You can save a byte: $ is just the same as 1¹

@kalsowerus Well, not exactly, but it'd work in this case...

Oh right.. I'm not sure which input is input when there would be multiple

dc, 53 bytes
16o?35Pskrsprlpr[Fk100/1r-255*1lk100/-*0k1/nz0<b]dsbx

Try it online!

q/kdb+, 55 bytes
Solution:
"#",raze{(last($)0x0 vs)each"h"$.0255*x[3]*x 0 1 2}100-

Examples:
q)"#",raze{(last($)0x0 vs)each"h"$.0255*x[3]*x 0 1 2}100-86 86 0 43
"#141491"
q)"#",raze{(last($)0x0 vs)each"h"$.0255*x[3]*x 0 1 2}100-28 14 0 6
"#adcef0"
q)"#",raze{(last($)0x0 vs)each"h"$.0255*x[3]*x 0 1 2}100-0 41 73 4
"#f59042"

Explanation:
Fairly straightforward, stole the 0.0255 trick from other solutions (thanks!). Evaluation is performed right to left.
"#",raze {(last string 0x0 vs) each "h"$ .0255 * a[3] * a 0 1 2}100- / ungolfed
         {                                                     }     / lambda function
                                                                100- / subtract from 100 (vector)
                                                        a 0 1 2      / index into a at 0, 1 and 2 (CMY)
                                                 a[3]                / index into at at 3 (K)
                                                      *              / multiply together
                                         .0255 *                     / multiply by 0.255
                                    "h"$                             / cast to shorts
          (                  ) each                                  / perform stuff in brackets on each list item
                       0x0 vs                                        / converts to hex, 1 -> 0x0001
                string                                               / cast to string, 0x0001 -> ["00", "01"]
           last                                                      / take the last one, "01"
    raze                                                             / join strings together
"#",                                                                 / prepend the hash

Notes:
Rounds numbers by default, would cost 3 bytes (_) to floor instead before casting to short.

Haskell, 165 bytes
q=(1-).(/100)
x!y=h$ceiling$q x*(q y)*255
f c m y k=concat["#",c!k,m!k,y!k]
h x|x<16=[s!!x]|0<1=(h((x-m)`quot`16))++[s!!m] where m=x`mod`16
s=['0'..'9']++['a'..'f']

Fortran, 156 bytes
PROGRAM C
REAL,DIMENSION(4,3)::d
READ(*,*)((d(i,j),i=1,4),j=1,3)
WRITE(*,'((A,3(Z2)))')(35,(INT(.0255*(100-d(i,j))*(100-d(4,j))),i=1,3),j=1,3)
END PROGRAM C

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


text:
SQL select number ranges
I found it quite hard to achieve a range of numbers as rows in MySQL.
For example the range 1-5 is achieved by:
SELECT 1
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4
UNION
SELECT 5

will result in:

1
2
3
4
5

for 0-99 I can cross join two 0-9 tables:
CREATE TABLE nums as
SELECT 0 as num
UNION
SELECT 1
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4
UNION
SELECT 5
UNION
SELECT 6
UNION
SELECT 7
UNION
SELECT 8
UNION
SELECT 9
;

Select n.num*10+nums.num v
From nums n cross join nums

I'm tired of writing all these UNIONs and looking for a way to shrink the code.
Any ideas how to golf it (for example 0-1,000,000 range) in MySQL or any SQL syntax ?
Extra points are given for:

single statement
no procedures
no variables
no DDL statements
only DQL statements

Not sure if this belongs in meta, or in dba.stackexchange.com or maybe in the tips for Golfing in SQL thread.

To close voters: This is an on-topic challenge; questions that aren't challenges that are related to golfing code are considered on-topic tips questions.

I kinda like this answer from SO. Hackish at best, but you asked for a golfing solution after all.

@Arnauld that's amazing!

Large list of methods for creating a number table, although they're evaluated by speed, not by golfing ability.

If “any SQL” includes PostgreSQL, see generate_series(). We have a couple of usage examples here.

@manatwork Looks useful, I'd say add it as an answer. Mine are already platform specific.

See http://www.itprotoday.com/microsoft-sql-server/virtual-auxiliary-table-numbers (for SQL Server 2005 or later).

For SQL dialects that support recursive CTEs like sqlite, you can do something like the following:
WITH RECURSIVE f(x) AS
(
  SELECT 1 UNION ALL SELECT x + 1 FROM f LIMIT 1000000
)
SELECT x
FROM f;

This doesn't depend on any existing table and you can change the LIMIT clause as desired. I originally saw a variant of this on StackOverflow.

Excellent. Here's a golfed version that works in MS SQL: WITH t AS(SELECT 1n UNION ALL SELECT n+1FROM t WHERE n<36)SELECT n FROM t  For different end points, just change the 1 and 36 to whatever you want.

Oops, if you want more than 100 rows in MS SQL, you might need to add option (maxrecursion 0) to the end of my above statement , otherwise it errors out for recursion over 100. (Either set maxrecursion to a specific value, or to 0 to allow infinite).

Similar to @BradC's method.
I used MS SQL, which has a table in [master] with a number range of -1 through 2048. You can use the BETWEEN operator to create your range.
SELECT DISTINCT(number)
FROM master..[spt_values]
WHERE number BETWEEN 1 AND 5

If you want to golf this, you can do:
SELECT TOP 5 ROW_NUMBER()OVER(ORDER BY number)FROM master..spt_values

For golfing you save 2 bytes with WHERE number>0AND number<21

Why do you use distinct? Seems redundant.

@MagicOctopusUrn Because there are duplicate numbers in that table.

Yep you either need to use DISTINCT or use WHERE type='P'. Distinct is slightly shorter.

@BradC, or SELECT DISTINCT(number+2)... WHERE number<19

PostgreSQL, 35 bytes
PostgreSQL has this easy:
SELECT * FROM generate_series(1,5)

If you need it named:
SELECT num FROM generate_series(1,5)AS a(num)

You can also do this with timestamps. https://www.postgresql.org/docs/9.5/static/functions-srf.html

I guess I'm moving to postgres

Great option from this post (found by @Arnauld):
SELECT id%1000001 as num
FROM <any_large_table>
GROUP BY num

For me - it's pretty much solves the challenge.

This seems to be relying on an existing table already having an id field populated through very large values. So pretty database specific, and you could miss a row if, say, someone deleted product ID = 4021.

Yep, but it really good for relatively small ranges (1-7 for days, 1-12 for months etc...)

PostgreSQL specific
generate_series() generates a set, so you can user it not only in from clause, but anywhere where a set may occur:
psql=# select generate_series(10, 20, 3);
 generate_series
-----------------
              10
              13
              16
              19
(4 rows)

You can also do operations directly on the set:
psql=# select 2000 + generate_series(10, 20, 3) * 2;
 ?column?
----------
     2020
     2026
     2032
     2038
(4 rows)

If multiple sets have the same length, you can traverse them in parallel:
psql=# select generate_series(1, 3), generate_series(4, 6);
 generate_series | generate_series
-----------------+-----------------
               1 |               4
               2 |               5
               3 |               6
(3 rows)

For sets with different lengths a Cartesian product is generated:
psql=# select generate_series(1, 3), generate_series(4, 5);
 generate_series | generate_series
-----------------+-----------------
               1 |               4
               2 |               5
               3 |               4
               1 |               5
               2 |               4
               3 |               5
(6 rows)

But if you use them in from clause, you get Cartesian product for same length sets too:
psql=# select * from generate_series(1, 2), generate_series(3, 4) second;
 generate_series | second
-----------------+--------
               1 |      3
               1 |      4
               2 |      3
               2 |      4
(4 rows)

It can also generate set of timestamps. For example you born on 2000-06-30 and want to know in which years you celebrated your birthday in a weekend:
psql=# select to_char(generate_series, 'YYYY - Day') from generate_series('2000-06-30', current_date, interval '1 year') where to_char(generate_series, 'D') in ('1', '7');
     to_char
------------------
 2001 - Saturday
 2002 - Sunday
 2007 - Saturday
 2012 - Saturday
 2013 - Sunday
(5 rows)

(These work in MS-SQL, not sure if they works for mySQL or other platforms.)
For smaller sets (ordered or non-ordered), use the VALUES constructor:
--Generates 0-9
SELECT a
FROM(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9))x(a)

(This works for anything, although strings can get pretty long with all the repeated single quotes.)
Then you can cross-multiply using a named CTE (common table expression) so you don't have to repeat it:
--Generates 0-999
WITH x AS(SELECT a FROM(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9))x(a))
SELECT 100*x.a+10*y.a+z.a
FROM x,x y,x z
ORDER BY 1

There are tons of other techniques out there, look for "SQL generating a number table", although most aren't optimized for golfing.

Would this work with a limit Y to make arbitrary ranges?

@Rod In MS-SQL you'd have to use SELECT TOP 250 ...

Oh, I didn't saw the MSSQL header =X

doesn't work on MySQL, but still is useful :)

MS SQL has an undocumented system table in the master database called spt_values. Among other things, it contains a range of numbers from 0 to 2047:
--returns 0 to 2,047
SELECT number n
FROM master..spt_values
WHERE TYPE='P'

Useful as a numbers table just by itself, but in a CTE you can get some big numbers pretty quickly:
--returns 0 to 4,194,304
WITH x AS(SELECT number n FROM master..spt_values WHERE TYPE='P')
SELECT 2048*x.a+*y.a
FROM x,x y
ORDER BY 1

One more option, this one specific to MS SQL 2016 and above:
SELECT value v
FROM STRING_SPLIT('1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16', ',')

I'll likely find this more handy for lists of strings, but I can see ways it will be useful with numbers as well.

T-SQL, 98 bytes
WITH H AS(SELECT 0i UNION ALL SELECT i+1FROM H WHERE i<99)SELECT H.i+1e4*A.i+B.i*1e2FROM H,H A,H B

✓ single statement
✓ no procedures
✓ no variables
✓ no DDL statements
✓ only DQL statements

This is a nice tidy T-SQL version of langelgjm's answer. The exponents are a neat trick, as well.

Another for SQL Server...
WITH
    cte_n1 (n) AS (SELECT 1 FROM (VALUES (1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) n (n)),   -- 10
    cte_n2 (n) AS (SELECT 1 FROM cte_n1 a CROSS JOIN cte_n1 b),                             -- 100
    cte_Tally (n) AS (
        SELECT TOP (<how many ROWS do you want?>)
            ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
        FROM
            cte_n2 a CROSS JOIN cte_n2 b                                                    -- 10,000
        )
SELECT
    t.n
FROM
    cte_Tally t;


text:
Printing criss cross of two strings
Given a set of two strings guaranteed to be the same length, print their criss cross.
The criss cross of two strings is obtained as follows.

Yield the second character of the second string, then the first character of the first string.
Yield the first character of the second string, then the second character of the first string.
Discard the first character of each string.
If the strings have more than one character each, go back to step 1.

For example, if the two strings are
Truck
Tower

the criss cross is
oTTrwroueuwcrcek

as illustrated in the following diagram.

Each color represents a different iteration of criss-crossing. The numbers show the corresponding character's indices in the output.

You shouldn't accept an answer until at the very least around a week has passed, it might be beaten at any time.

@Phoenix okay I'll keep that in mind next time (this was my first question on this stackexchange)

Jelly, 10 8 bytes
żṚj@¥2\U

Try it online!
How it works
żṚj@¥2\U  Main link. Arguments: s, t (strings)

          Arguments:    "Truck", Tower"
ż         Ziphwith; create all pairs of corresponding characters.
          Return value: ["TT", "ro", "uw", "ce", "kr"].
     2\   Reduce each pair of adjacent strings by the quicklink to the left.
    ¥       Combine the two links to the left into a dyadic chain.
 Ṛ            Reverse the left string.
  j@          Join the second string, using the previous result as separator.
          Map:          "TT", "ro" -> join("ro", "TT") -> "rTTo"
                        "ro", "uw" -> join("uw", "or") -> "uorw"
                        etc.
          Return value: ["rTTo", "uorw", "cwue", "kecr"]
       U  Upend; reverse each string.
          Return value: ["oTTr", "wrou", "euwc", "rcek"]
          (implicit) Flatten and print.

Wow thats pretty amazing

Explanation, please?

@Shaggy I've edited my answer.

JavaScript (ES6), 51 bytes
f=([G,...O],[L,...F])=>O[0]?F[0]+G+L+O[0]+f(O,F):''

f=([G,...O],[L,...F])=>O[0]?F[0]+G+L+O[0]+f(O,F):''

console.log(f("Truck", "Tower"))

Haskell, 44 38 bytes
Crossed out 44 is still 44
[_]#_=""
(a:b)#(x:y)=y!!0:a:x:b!!0:b#y

Slightly less golfed / maybe a little more readable:
[_]      # [_]      = ""
(a:b:bs) # (x:y:ys) = y:a:x:b:((b:bs) # (y:ys))

Fun Fact: On my browser at least, crossed out 44 is no longer 44 in the header :o

Python 3, 56 bytes
f=lambda s,t:s[1:]and t[1]+s[0]+t[0]+s[1]+f(s[1:],t[1:])

Try it online!

PowerShell, 71 bytes
param($a,$b)-join($a|% t*y|%{$b[+$i],$a[$i-1],$b[$i-1],$a[+$i]*!!$i++})

Try it online!
Less golfed:
param($a,$b)
-join(
    $a|foreach ToCharArray|foreach{  # transform each string from $a to an array and apply for each char...
        $CrissCross = $b[+$i],$a[$i-1],$b[$i-1],$a[+$i]
        $NotFirst   = !!$i++         # =0 if $i is 0; =1 if $i is not 0
        $CrissCross*$NotFirst        # repeat the $CrissCross array $NotFirst times
    }                                # and implicitly output
) # join all outputed chars to one string and implicitly output it as result

Whaaaaaaat? In 71 bytes????????????

PHP>=7.1, 64 bytes
for([,$a,$b]=$argv;$c=$b[++$i];)echo$c,$a[$i-1],$b[$i-1],$a[$i];

PHP Sandbox Online

PowerShell, 203 bytes
param($a,$b)$s=$k=@()
function q($x){$u=$x|% t*y;($u|%{$u[--$q]})-join''}
$a|% t*y|%{$s+=$_+$b[($i++)]}
$n=1;$s|%{$k+="$($s[$n][0])$(q($s[$n-1]))$($s[$n][1])";$n++}
($k[0..($k.length-2)]|%{q($_)})-join''

Try it online!
golfed, used negative indexing iteration for reversing array
PowerShell, 210 bytes
param($a,$b)$s=$k=@()
function q($x){$u=$x|% t*y;[array]::reverse($u);$u-join''}
$a|% t*y|%{$s+=$_+$b[($i++)]}
$n=1;$s|%{$k+="$($s[$n][0])$(q($s[$n-1]))$($s[$n][1])";$n++}
($k[0..($k.length-2)]|%{q($_)})-join''

Try it online!
To Criss-Cross the string, I use the following algorithm:

Take two strings: Truck and Tower
Zip them and form a new array. Two zip them means to pair each character in the string with another, so it results an array with these 5 elements: TT ro uw ce kr
Iterate the array in 0,1 1,2 2,3 pairs. So it results a new array in TT ro ro uw uw ce ce kr form.
Iterate the array again and swap the elements in each iteration and reverse the new second element. So it results ro TT uw or ce wu kr ec
Reverse each element in the array again and join them oTTrwroueuwcrcek!

Code explanation

First take two parameters $a and $b, it is done using param() block
Then define two empty arrays $s and $k, in Powershell Empty array is @()
Then define a function q to reverse strings (I wonder why there is no string .reverse() method on .NET), First it takes a string $x, then defines $u as the character array of $x (t*y is the shorthand for ToCharArray() .NET string method, Powrshell can automatically expand it using Foreach loop), then reverse the $u array in-place using the reverse() static method of [array] type (:: is used to invoke a static method), and at last, join the $u array with seperator '' meaning nothing (-join is an operator which does that), which result in the reversed string
Then again iterate over the character array of first string ($a, I have said in the previous step how character array works), and build a string with the each element of array ($_ represents that, it is an automatic variable which contains the iterated element in an object supplied from pipeline) and $i++th index of $b string (You can see that I haven't defined $i anywhere, because it is not needed, in powershell non-declared variables are automatically assigned to 0, ++ operator increments a variable, and surrounding parentheses around this increments and then outputs the variable, no need to explicitly increment and use latter), and each builded string is added to the $s array through the assignment operator += (Does the 2nd step in algorithm, no builtin Zip function in powershell)
Then I declare another variable $n to value of 1 (a semicolon ; is used to seperate statements and fit in a single line), iterate over the $s array, and build a string with the first character in $nth indexed element of the $s array, then $n-1th indexed element in the $s array and then the second (In fact the last, but negative indexing with -1 would cost one more precious byte) character in $nth indexed element of the $s array and append to $k array using += assignment operator, and increment $n variable using ++ operator at end (Does the 3rd and 4th step in algorithm, In python and some other languages it would be easier using enumeration and slicing)
Then I iterate in the $k array with the last element removed (In powershell .NET .RemoveAt() method for removing array elements using index don't work for normal arrays), to do this I used indexing, first started index from 0 and ended 2 subtracted from array length, and .. range operator is used to multiple index here, and I then apply q() function (reverse, that I built earlier), and parenthesise the whole expression to form an array, and then join it with '' seperator using -join operator, and the string is implicitly outputted (Does the last step in algorithm, .NET has severe lack of builtins, at least it should have a map function!)

Wasif, please read the Tips for golfing in PowerShell and use it! For example, Reversing an array and other tips.

@mazzy thanks for the tips, I have golfed the solution more, I will add it to the post soon

I believe you will make a shorter code

J, 14 bytes
[:,19&A.@,;._3

Try it online!
J's "Max cubes" verb ;._3 is made to order here.  It works by creating a maximal "sliding window" and then using that to tile a matrix.  So for example if we just box things to see how it works:
echo i.2 6

0 1 2 3  4  5
6 7 8 9 10 11

echo <;._3 i.2 6

┌───┬───┬───┬────┬─────┐
│0 1│1 2│2 3│3  4│ 4  5│
│6 7│7 8│8 9│9 10│10 11│
└───┴───┴───┴────┴─────┘

Now we just flatten each of those boxes ,, apply the required permutation 19&A., and flatten the final result [:,.

Great answer! This answer qualifies for 200 rep from this bounty if you want it.

@OriginalOriginalOriginalVI Sweet!  I'll edit per your instructions.

K (ngn/k), 17 bytes
,/{(|x),y}.'+2':'

Try it online!
Takes (implicit) input as a list of two strings, e.g. f ("Tower"; "Truck").

+2':' take 2-length sliding windows, transposing the results to obtain (("To";"Tr");("ow";"ru");("we";"uc");("er";"ck"))
{(|x),y}.' apply the desired transformation to each pair of the above
,/ flatten the result

C++14, 115 112 bytes
As unnamed lambda, parameters should be like std::string:
#define P putchar(
[](auto A,auto B){for(int i=0;++i<A.size()&&i<B.size();P B[i]),P A[i-1]),P B[i-1]),P A[i]));}

Ungolfed and usage:
#include<iostream>
#include<string>

using namespace std;

#define P putchar(
auto f=
[](auto A,auto B){
 for(int i=0;
     ++i<A.size() && i<B.size();
     P B[i]),
     P A[i-1]),
     P B[i-1]),
     P A[i]));
}
;

int main(){
 string A="Truck",B="Tower";
 f(A,B);
}

Factor, 101 bytes
2 clump [ reverse 1 group ] map concat swap 2 clump [ 1 group ] map concat swap [ write write ] 2each

Try it online!

This isn't a valid answer because it's neither a full program (which underflows) nor a function. Also, you can shorten it quite a bit without grouping and by using 2merge. Try it online!

@chunes Of-coarse it's valid, as a stack based language it expects the input strings to be on the stack, so it's a full program. The OP didn't restrict the answer to functions either. Thanks for the 2merge hint!

It's true that stack languages expect input to be on the stack, but unless what you wrote is a function, you have to put things on the stack yourself with readln etc. Consider your program has stack effect ( x x -- ). A full program would have stack effect ( -- ).

Vyxal s, 9 bytes
Z2lƛṠ÷$Ṙj

Try it Online!
Z         # Zip
 2l       # Slices of length 2
   ƛ      # Map...
    Ṡ     # Stringify
     ÷$Ṙj # Join second by first reversed


text:
Divide a string
Challenge
Given a string and a number, divide the string into that many equal-sized parts. For example, if the number is 3, you should divide the string into 3 pieces no matter how long the string is.
If the length of the string does not divide evenly into the number provided, you should round down the size of each piece and return a "remainder" string. For example, if the length of the input string is 13, and the number is 4, you should return four strings each of size 3, plus a remainder string of size 1.
If there is no remainder, you may simply not return one, or return the empty string.
The provided number is guaranteed to be less than or equal to the length of the string. For example, the input "PPCG", 7 will not occur because "PPCG" cannot be divided into 7 strings. (I suppose the proper result would be (["", "", "", "", "", "", ""], "PPCG"). It's easier to simply disallow this as input.)
As usual, I/O is flexible. You may return a pair of the strings and the remainder string, or one list of strings with the remainder at the end.
Test cases
"Hello, world!", 4 -> (["Hel", "lo,", " wo", "rld"], "!") ("!" is the remainder)
"Hello, world!", 5 -> (["He", "ll", "o,", " w", "or"], "ld!")
"ABCDEFGH", 2 -> (["ABCD", "EFGH"], "") (no remainder; optional "")
"123456789", 5 -> (["1", "2", "3", "4", "5"], "6789")
"ALABAMA", 3 -> (["AL", "AB", "AM"], "A")
"1234567", 4 -> (["1", "2", "3", "4"], "567")

Scoring
This is code-golf, so the shortest answer in each language wins.
Bonus points (not really ) for making your solution actually use your language's division operator.

Bonus points? Oh man I gotta do this

For the bonus, Jelly, 3 bytes ;⁹/

Related, but neither part is quite the same as this challenge.

To make it clearer please add a testcase PPCG ,7 so the remainder is PPCG

@JörgHülsermann That input is disallowed. I have added more details pertaining to that type of input and reformatted things to be more clear.

Python 2, 63 59 bytes
s,n=input()
b=len(s)/n
exec'print s[:b];s=s[b:];'*n
print s

Try it online!

Well done! I really don't think this can be golfed any further.

Haskell, 62 bytes
# is an operator taking a String and an Int, and returning a list of Strings.
Use as "Hello, world!"#4.
s#n|d<-length s`div`n=[take(d+n*0^(n-i))$drop(i*d)s|i<-[0..n]]

Try it online!
How it works

s is the input string and n is the number of non-remainder pieces.
d is the length of each "normal" piece. div is integer division.
The list comprehension constructs n+1 pieces, with the last being the remainder.

i iterates from 0 to n, inclusive.
For each piece, first the right amount (i*d) of initial characters are dropped from the beginning of s, then an initial substring is taken from the result.
The substring length taken should be d, except for the remainder piece.

The actual remainder must be shorter than n, as otherwise the normal pieces would be lengthened instead.
take returns the whole string if the length given is too large, so we can use any number >=n-1 for the remainder piece.
The expression d+n*0^(n-i) gives d if i<n and d+n if i==n. It uses that 0^x is 1 when x==0, but 0 if x>0.

I'll need to watch for where I can use list comprehensions.

Pip, 21 bytes
20 bytes of code, +1 for -n flag.
a~C(#a//b*XX)XbP$$$'

Takes inputs as command-line arguments; outputs strings and remainder newline-separated. Try it online!
Explanation
Fun with regex operations!
Let's take abcdefg as our string and 3 as our number. We construct the regex (.{2})(.{2})(.{2}), which matches three runs of two characters and stores them in three capture groups. Then, using Pip's regex match variables, we can print 1) the list of capture groups ["ab";"cd";"ef"], and 2) the remainder of the string that wasn't matched "g".
                      a,b are cmdline args; XX is the regex `.` (match any one character)
    #a//b             Len(a) int-divided by b: the length of each chunk
         *XX          Apply regex repetition by that number to `.`, resulting in something
                        that looks like `.{n}`
  C(        )         Wrap that regex in a capturing group
             Xb       Repeat the whole thing b times
a~                    Match the regex against a
               P$$    Print $$, the list of all capture groups (newline separated via -n)
                  $'  Print $', the portion of the string after the match

PHP>=7.1, 75 bytes
[,$s,$d]=$argv;print_r(preg_split('/.{'.(strlen($s)/$d^0).'}\K/',$s,$d+1));

Testcases
PHP>=7.1, 52 bytes
print only the remainder

[,$s,$d]=$argv;echo substr($s,(strlen($s)/$d^0)*$d);

Test Cases

Python 2, 68 67 65 bytes

@musicman123 saved 2 bytes:output without enclosing with []
Thanks to @Chas Brown for 1 Byte: x[p*i:p+p*i] as x[p*i][:p]

def f(x,n):p=len(x)/n;print[x[p*i:][:p]for i in range(n)],x[p*n:]

Try it online!

Save 1 byte by replacing x[p*i:p+p*i] with x[p*i:][:p]

+1 for :p  Well done outgolfing the other Python answers!

Haha.. that was not intended at all.... :p

This answer has now been outgolfed

C++14, 209 180 bytes
That's a bit too long, but uses the division operator:
#include<bits/stdc++.h>
using q=std::string;using z=std::vector<q>;z operator/(q s,int d){int p=s.length()/d,i=0;z a;for(;i<d+1;){a.push_back(s.substr(i++*p,i^d?p:-1));}return a;}

Usage:
vector<string> result = string("abc")/3;

Online version: http://ideone.com/hbBW9u

Pyth, 9 bytes
cz*L/lzQS

Try it online
How it works
First Q is autoinitialized to eval(input()) and z is autoinitialized to input().
cz*L/lzQSQ
     lz      length of z
    /  Q     integer division by Q
  *L         times every element of
        SQ       [1, 2, …, Q]
cz           chop z at those locations

Jelly, 11 bytes
Ld⁹x,1$}R⁸ṁ

Try it online!

Fails for the "123456789", 5 testcase

Completely misread the challenge. Thanks!

Rust, 107 bytes
fn f(s:&str,n:usize)->(Vec<&str>,&str){let c=s.len()/n;((0..n).map(|i|&s[i*c..i*c+c]).collect(),&s[c*n..])}

Try it online!
Formatted:
fn q129259(s: &str, n: usize) -> (Vec<&str>, &str) {
    let c = s.len() / n;
    ((0..n).map(|i| &s[i * c..i * c + c]).collect(), &s[c * n..])
}

This simply maps indices onto the correct slices of the source str (collecting into a Vec) and slices out the remainder.
Unfortunately, I cannot make this a closure (74 bytes):
|s,n|{let c=s.len()/n;((0..n).map(|i|&s[i*c..i*c+c]).collect(),&s[c*n..])}

as the compiler fails with
error: the type of this value must be known in this context
 --> src\q129259.rs:5:18
  |
5 |          let c = s.len() / n;
  |                  ^^^^^^^

and if I provide the type of s:&str, the lifetimes are wrong:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
 --> src\q129259.rs:6:27
  |
6 |          ((0..n).map(|i| &s[i * c..i * c + c]).collect(), &s[c * n..])
  |                           ^^^^^^^^^^^^^^^^^^^
  |
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the body at 4:18...
 --> src\q129259.rs:4:19
  |
4 |       (|s: &str, n| {
  |  ___________________^
5 | |          let c = s.len() / n;
6 | |          ((0..n).map(|i| &s[i * c..i * c + c]).collect(), &s[c * n..])
7 | |      })(s, n)
  | |______^
note: ...so that reference does not outlive borrowed content
 --> src\q129259.rs:6:27
  |
6 |          ((0..n).map(|i| &s[i * c..i * c + c]).collect(), &s[c * n..])
  |                           ^
note: but, the lifetime must be valid for the lifetime 'a as defined on the body at 3:58...
 --> src\q129259.rs:3:59
  |
3 |   fn q129259<'a>(s: &'a str, n: usize) -> (Vec<&str>, &str) {
  |  ___________________________________________________________^
4 | |     (|s: &str, n| {
5 | |          let c = s.len() / n;
6 | |          ((0..n).map(|i| &s[i * c..i * c + c]).collect(), &s[c * n..])
7 | |      })(s, n)
8 | | }
  | |_^
note: ...so that expression is assignable (expected (std::vec::Vec<&'a str>, &'a str), found (std::vec::Vec<&str>, &str))
 --> src\q129259.rs:4:5
  |
4 | /     (|s: &str, n| {
5 | |          let c = s.len() / n;
6 | |          ((0..n).map(|i| &s[i * c..i * c + c]).collect(), &s[c * n..])
7 | |      })(s, n)
  | |_____________^

Retina, 92 bytes
(.+)¶(.+)
$2$*1¶$.1$*1¶$1
(1+)¶(\1)+
$1¶$#2$*1¶
\G1(?=1*¶(1+))
$1¶
¶¶1+

O^$`.

¶1+$

O^$`.

Try it online! Explanation: The first stage converts the number of parts to unary and also takes the length of the string. The second stage then divides the length by the number of parts, leaving any remainder. The third stage multiplies the result by the number of parts again. This gives us the correct number of strings of the correct length, but they don't have the content yet. The number of parts can now be deleted by the fourth stage. The fifth stage reverses all of the characters. This has the effect of switching the original content with the placeholder strings, but although it's now in the right place, it's in reverse order. The placeholders have served their purpose and are deleted by the sixth stage. Finally the seventh stage reverses the characters back into their original order.

Perl 6, 36 bytes
{$^a.comb.rotor($a.comb/$^b xx$b,*)}

Try it online!
Returns a list of lists of strings, where the last element is the remainder (if there is one).
Explanation:
{                                  }  # Anonymous code block
 $^a.comb                             # Split the string into a list of chars
         .rotor(                  )   # And split into
                            xx$b      # N lists
                $a.comb/$^b           # With string length/n size
                                ,*    # And whatever is left over

JavaScript (ES6), 77 bytes
(s,d,n=s.length)=>[s.match(eval(`/.{${n/d|0}}/g`)).slice(0,d),s.slice(n-n%d)]

Returns an array of two elements: the divided string parts and the remainder part.
Test Snippet

f=
(s,d,n=s.length)=>[s.match(eval(`/.{${n/d|0}}/g`)).slice(0,d),s.slice(n-n%d)]

String: <input id=I> Number: <input id=J size=3>

Japt, 18 bytes
¯W=Ul fV)òW/V pUsW

Test it online! (uses -Q flag to visualize the output)
Explanation
¯W=Ul fV)òW/V pUsW  : Implicit: U = input string, V = input integer
   Ul fV            : Floor U.length to a multiple of V.
 W=                 : Assign this value to variable W.
¯       )           : Take the first W characters of U (everything but the remainder).
         òW/V       : Partition this into runs of length W / V, giving V runs.
              pUsW  : Push the part of U past index W (the remainder) to the resulting array.
                    : Implicit: output result of last expression

Python, 95, 87, 76 73 Bytes
def f(s,n):
 a=[];i=len(s)/n
 while n:a+=s[:i],;s=s[i:];n-=1
 print a+[s]

Try it online!

Welcome to PPCG! I added a "Try it online" link to your post. I think you can slightly shorten your solution by making it a full program rather than a function. Try it online!

05AB1E, 12 bytes
²g¹‰`s¹.D)R£

Try it online!
Explanation
²g¹‰`s¹.D)R£
²g           # Push length of string
  ¹          # Push amount of pieces
   ‰         # divmod of the two
    `s       # Flatten the resulting array and flip it around
      ¹.D    # Repeat the resulting length of the pieces amount of pieces times(wow that sounds weird)
         )   # Wrap stack to array
          R  # Reverse (so the remainder is at the end)
           £ # Split the input string into pieces defined by the array

9 bytes by reversing the input-order.

Python, 82 76 74 bytes
def G(h,n):l=len(h);r=l/n;print[h[i:i+r]for i in range(0,n*r,r)],h[l-l%n:]

Well, looks like this qualifies for the bonus points.  May I please receive a cookie instead? Oh wait, they aren't real? Darn...
Try It Online!

Would you prefer a cookie, or saving 6 bytes by factoring out len(h)? :)

Brachylog, 16 bytes
kʰ↙Xḍ₎Ylᵛ&ht↙X;Y

Try it online!
Takes input as a list [string, number] and outputs as a list [remainder, parts]. (Commas were replaced with semicolons in the "Hello, world!" test cases for clarity, since the string fragments don't get printed with quotes.)
                    The input
 ʰ                  with its first element
k ↙X                having the last X elements removed
    ḍ               and being cut into a number of pieces
     ₎              where that number is the last element of the input
      Y             is Y
       lᵛ           the elements of which all have the same length,
         &          and the input
          h         's first element
           t↙X      's last X elements
              ;     paired with
               Y    Y
                    are the output.

(I also replaced a comma in the code with a semicolon for a consistent output format. With the comma, cases with no remainder would just output the parts without an empty remainder, and as nice as that is for some purposes, I don't actually know why it works that way...)
After this came out to be a whole 16 bytes, I tried to make something based on +₁ᵗ⟨ġl⟩ work, but as the fixes got longer and longer I decided that I would just stick with my original solution for now.

C(gcc), 72 bytes
d;f(s,n)char*s;{for(d=strlen(s)/n;n--;puts(""))s+=write(1,s,d);puts(s);}

Try It Online

Excel Formula, 185 173 165 161 149 bytes
The following should be entered as an array formula (Ctrl+Shift+Enter):
=MID(A1,(ROW(OFFSET(A1,,,B1+1))-1)*INT(LEN(A1)/B1)+1,INT(LEN(A1)/B1)*ROW(OFFSET(A1,,,B1+1))/IF(ROW(OFFSET(A1,,,B1+1))=B1+1,1,ROW(OFFSET(A1,,,B1+1))))

Where A1 contains your input (e.g. 12345678) and B1 contains the divisor. This also uses Excel's division operator for a bonus.
After entering the formula as an array formula, highlight it in the formula bar and evaluate it using F9 to return the result, for example:

-12 bytes: replace each INDIRECT("1:"&B1+1) with OFFSET(A1,,,B1+1) to save 2 bytes per occurence, plus some tidying removing redundant brackets.
-8 bytes: remove redundant INDEX function.
-4 bytes: rework "remainder" handling.
-12 bytes: remove redundant INT(LEN(A1)/B1) by offsetting array generated by ROW(OFFSET(A1,,,B1+1)) by -1.

V (vim), 62 bytes
YpC<c-r>=strlen('<c-r>"')
<esc>jYp<c-x>"aDkk:s:\n:/
C<c-r>=<c-r>"
<esc>"bDkkqq@blha
<esc>q@a@q

Try it online!
takes input as 2 lines, returns the divisions on separate lines.
a is useful here to append a newline after the current character.

Python 2, 77 76 bytes
-1 byte thanks to musicman523.
def f(s,n):l=len(s);print[s[i:i+l/n]for i in range(0,l-n+1,l/n)]+[s[l-l%n:]]

Try it online!

This is one byte shorter as a function. Try it online!

Ruby, 53 bytes
->s,n{a=s.scan(/.{,#{s.size/n}}/);[a[0,n],a[n,n]*'']}

Try it online!

Haskell, 120 88 bytes (thanks to Ørjan Johansen!)
Does div count as the division operator?
I am curious how I could cut this down, I haven't learned all the tricks yet.
q=splitAt;x!s|n<-div(length s)x,let g""=[];g s|(f,r)<-q n s=f:g r,(a,b)<-q(n*x)s=(g a,b)

A quick rewrite with the most basic tricks: t=splitAt;x!s|n<-div(length s)x,let g""=[];g s|(f,r)<-t n s=f:g r,(a,b)<-t(n*x)s=(g a,b). So, (1) A repeatedly used identifier may be abbreviated, especially if it's long. (2) Guards and pattern guards are almost always shorter than let ... in, where and if then else. (3) Pattern matching is often better than equality testing. (OK, that let in a pattern guard isn't that basic, I recently learned it from someone else here.) And check out https://codegolf.stackexchange.com/questions/19255/tips-for-golfing-in-haskell .

Also, take a look at Tips for golfing in Haskell for some useful tricks.

@ØrjanJohansen Thanks! I forgot that semicolons were valid, and that let in the guard is pretty devious. But shorter code is more readable, right?

Mathematica, 58 bytes
{#~Partition~a,#2}&@@TakeDrop[#,(a=Floor[Length@#/#2])#2]&

Pure function taking a list of characters and a positive integer as input. For example, the last test case is called by
{#~Partition~a,#2}&@@TakeDrop[#,(a=Floor[Length@#/#2])#2]&[{"1","2","3","4","5","6","7"},4]

and returns:
{{{"1"}, {"2"}, {"3"}, {"4"}}, {"5", "6", "7"}}

Ohm, 3 bytes (non-competing?)
lvσ

Non competing because the built-in isn't implemented yet in TIO and i have no PC handy to test whether it works in the latest pull in the repo.
Built-in ¯\\_(ツ)_/¯. I used the wrong built-in... But hey there is still an other one laying around. Now I used the wrong built-in two times (or one built-in works wrong with remainders).
Do I get bonus points because v is (floor) division?

This doesn't split in the way required. e.g. the Hello, world! 5 testcase is wrong. Try it online!

Well I'm going to look for another built-in....

J, 26 bytes
(]$~[,(<.@%~#));]{.~0-(|#)

Apart from elminating spaces and intermediate steps, this hasn't been golfed. I expect that I've taken the long way somehow, what with my parentheses and argument references ([ and ]).
See Jupyter notebook for test cases, such as the following:
   5 chunk test2
┌──┬───┐
│He│ld!│
│ll│   │
│o,│   │
│ w│   │
│or│   │
└──┴───┘

Thanks.  Read too fast.  Comment removed

CJam, 16 bytes
{_,2$//_2$<@@>s}

Anonymous block expecting the arguments on the stack and leaves the result on the stack after.
Try it online!
Explanation
Expects arguments as number "string".
_,              e# Copy the string and get its length.
  2$            e# Copy the number.
    /           e# Integer divide the length by the number.
     /          e# Split the string into slices of that size.
      _         e# Copy the resulting array.
       2$       e# Copy the number.
         <      e# Slice the array, keeping only the first <number> elements.
          @@    e# Bring the number and original array to the top.
            >   e# Slice away the first <number> elements,
             s  e# and join the remaining elements into a string.

R, 79 63 bytes
-16 from Giuseppe fixing the indexing
function(s,n,k=nchar(s),l=k%/%n)substring(s,0:n*l+1,c(1:n*l,k))

Try it online!
Built around giving vector inputs to substring()

63 bytes -- simplified the indexing a bit.

@Giuseppe Haha, I must have tried every variant of adding and multiplying on the index, but missed that one. Good catch.

JavaScript, 49 bytes
d=(s,n)=>s.match(eval(`/.{1,${0|s.length/n}}/g`))

Try It Online

d=(s,n)=>s.match(eval(`/.{1,${0|s.length/n}}/g`))

var ret = d("######.######..#####..########..##.##..##.##.....##.....######.######.##.....##..#####.....##.....##.....##...####.....##......####...######", 5);
for (var r in ret)
    console.log(ret[r]);

Stax, 12 bytes
î╩╘30¥♂┴ÿ&╕¡

Run and debug it

Japt -P, 8 bytes
òUÊzV)sV

Try it
òUÊzV)sV     :Implicit input of string U & integer V
ò            :Partitions of U of length
 UÊ          :  Length of U
   zV        :  Floor divided by V
     )       :End partition
      sV     :Slice off the first V elements
             :Implicitly join and output

PowerShell v3+, 72, 80 bytes
Assumes $s contains the input string; $n contains the number of characters per "piece".  This also assumes that "StrictMode" is off.  Otherwise, an error would be returned because of indexing further into an array than actually exists (i.e. if array has 4 elements and i call the non-existent 5th element).  With StrictMode off, PS doesn't care and it'll ignore the error.
for($i = 0;$i -le $s.Length;$i+=$n+1){-join($s|% ToCharA*)[$i..($i+$n)]}

Using notation ($s|% ToCharA*) i was able to save 1 character compared to $s.ToCharArray() : )
Update:
Updated code to actually satisfy challenges requirements.
Again assumes $s contains the input string; however, this time $n contains the number of "pieces". The remainder is printed out last.  And i used PowerShell's division operator
0..($n-1)|%{$p=[math]::Floor($s.length/$n)}{$s|% Su*($_*$p) $p}{$s|% Su*($n*$p)}

Try it online!

I believe you've misunderstood the question, the input is the number of pieces (excluding remainder).

Oh, you're right.  I mis-read the question last night : )
I'll post my updated solution when i have a chance.

Python 2, 57 bytes
def f(s,n):k=len(s)/n;print zip(*[iter(s)]*k)[:n],s[k*n:]

Try it online!

I... think I'll wait for OP's judgement on that output format.

PHP, 152 bytes
Thanks @JörgHülsermann (brackets tip!)

$c=$s=explode('|',readline());
while($s[1]--)$s[0]=preg_replace('/^'.($l[]=substr($s[0],0,strlen($c[0])/$c[1])).'/','',$s[0]);
$l[r]=$s[0];
print_r($l);

Try it online!

Your PHP Way doesn't work cause it replaces not only at the beginning. preg_replace is an alternative or you can use [,$s,$d]=$argv;print_r(array_slice(str_split($s,$l=strlen($s)/$d^0),0,$d)+[$d=>substr($s,$l*$d)]);

Can you explain me with a example code why doesn't work my PHP code ?

Try it online! It replaces all A in the first run

You can drop the array_walk construct if you use brackets Try it online!

Nice tip ! I totally forgot

http://sandbox.onlinephpfunctions.com/code/24359933eecf5ff28247f2d23729dcaee411261e a shorter solution needs PHP 7.1

Your way can be golfed to this Try it online! or Try it online! use substr_replace and for using PHP 7.1 -4 Bytes for the short list syntax

Python 3, 94 bytes
i=input().split('|')
s,n=i[0],int(i[1])
c=len(s)//n
while n:print(s[:c]);s=s[c:];n-=1
print(s)

Try it online!

Assuming the input is in a variable is not a valid input method.

What mean this As usual, I/O is flexible. ? Anyway thanks, I edit my answer...

PPCG's standard methods are pretty flexible. Just not quite that much.

Perl 5 -pF, 43 bytes
$p=@F/($q=<>);say substr$_,0,$p,''while$q--

Try it online!

Apparently.  I misread the spec.

Forth (gforth), 64 bytes
: f >r i /mod rot r> 0 do over 2dup cr type + loop rot cr type ;

Try it online!
Ended up printing the strings newline-separated, since Forth doesn't have a native list format and newlines are cheaper than spaces
Code Explanation
: f               \ start a new word definition
  >r              \ stick the divisor on the return stack (to get it out of the way)
  i /mod          \ get the quotient and remainder of dividing length by divisor
  rot             \ move the string starting-address to the top of the stack
  r> 0            \ move the divisor off the return stack and setup loop parameters
  do              \ loop from 0 to divisor  - 1
    over          \ copy the calculated substring-length to the top of the stack
    2dup          \ duplicate both address and substring-length
    cr            \ output a newline
    type          \ print a string of substring-length characters from the given address
    +             \ add the substring length to the current address
  loop            \ end the loop definition
  rot             \ move the remainder to the top of the stack
  cr type         \ output a newline and print the remaining remainder characters in the  string
;                 \ end the word definition

Runic Enchantments, 32 bytes
:l͍i:},,r[\>i
/?)1l$,'$L
\]$ak@

Try it online!
Note that inputs are automatically coerced to the most appropriate value type (i.e. numbers will be cast to numerical values, which will not 'divide' correctly) and that inputs are separated by spaces. If you wish to include an input string that contains a space, it (and newlines) will need to be escaped (e.g. Hello\ World!)
Output is the groupings separated by ,, followed by a new line, then the remainder (if any). As such, , and newlines in the input are not recommended (but will definitely display correctly).
Explanation
The first line handles reading and parsing the inputs (reordered for legibility):
>              Entry point
 i:            Read string input, duplicate it
   l͍           Get its length
    i:         Get integer input, duplicate it
      ,,       Divide length by input, divide input string by grouping size (collect the bonus)
        r      Reverse the stack
         [     Pop the top N values to a new virtual stack (this value is the numerical input value)
          \    Enter output loop

          L    Top of the loop, sends IP to the left
         $     Print top of the stack (first substring)
      $,'      Push a , and print it
   )1l         Check if the length of the stack is >1
  ?            If true, skip next instruction (go top top of loop)
 /             If false, bounce to the last line

 \             Reflect IP to the right
  ]            Pop the virutal stack back to the top of the original stack
   $           Print the last substring
    ak         Push a newline
      @        Dump rest of the stack and terminate