text:
Highest or Lowest Occurrences?
Challenge:
Inputs:

A string containing printable ASCII (excluding spaces, tabs and new-lines)
A boolean †

Output:
The parts of the String are divided into four groups:

Lowercase letters
Uppercase letters
Digits
Other

Based on the boolean, we either output the highest occurrence of one (or multiple) of these four groups, or the lowest, replacing everything else with spaces.
For example:
Input: "Just_A_Test!"
It contains:
- 3 uppercase letters: JAT
- 6 lowercase letters: ustest
- 0 digits
- 3 other: __!
These would be the outputs for true or false:
true:   " ust    est "

// digits have the lowest occurrence (none), so everything is replaced with a space
false:  "            "

(Note: You are allowed to ignore trailing spaces, so the outputs can also be " ust    est" and "" respectively.)
Challenge rules:

The input will never be empty or contain spaces, and will only consist of printable ASCII in the range 33-126 or '!' through '~'.
You are allowed to take the input and/or outputs as character-array or list if you want to.
† Any two consistent and distinct values for the boolean are allowed: true/false; 1/0; 'H'/'L'; "highest"/"lowest"; etc. Note that these distinct values should be used (somewhat) as a boolean! So it's not allowed to input two complete programs, one that gives the correct result for true and the other for false, and then having your actual code only be <run input with parameter>. Relevant new default loophole I've added, although it can still use a lot of finetuning regarding the definitions..
If the occurrence of two or more groups is the same, we output all those occurrences.
The necessary trailing spaces are optional, and a single trailing new-line is optional as well. Necessary leading spaces are mandatory. And any other leading spaces or new-lines aren't allowed.

General rules:

This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
Default Loopholes are forbidden.
If possible, please add a link with a test for your code.
Also, please add an explanation if necessary.

Test cases:
Inputs:                              Output:

"Just_A_Test!", true                 " ust    est "     (or " ust    est")
"Just_A_Test!", false                "            "     (or "")
"Aa1!Bb2@Cc3#Dd4$", either           "Aa1!Bb2@Cc3#Dd4$"
"H@$h!n9_!$_fun?", true              " @$ !  _!$_   ?"
"H@$h!n9_!$_fun?", false             "H     9        "  (or "H     9")
"A", true                            "A"
"A", false                           " "                (or "")
"H.ngm.n", true                      "  ngm n"
"H.ngm.n", false                     "       "          (or "")
"H.ngm4n", false                     "H.   4 "          (or "H.   4")

Is it acceptable to output the most/fewest as separate entries? For example, for the "hashing is fun" test case, can "H           " and "     9      " (with appropriate spaces) be output instead of "H       9"?

@AdmBorkBork I don't get what you mean; both the H and 9 are part of the "fewest".

Can the boolean input value be "max"/"min", which is then used as Math[b] to refer to Math.max or Math.min?

@JustinMariner You know.. I changed my mind sorry about that. I guess it's for JS? I think a lot of programming languages can utilize something like this, so too many of the existing answers should be changed. So sorry, you'll have to keep the b?"max":"min" in your answer.. It's a fine line I guess, maybe I should just use a truthy/falsey value next time..

Husk, 27 26 24 22 bytes
-2 bytes thanks to Zgarb
-2 bytes thanks to Leo
Takes ' ' as False and 'a' as True (In Husk, whitespace in Fasly and all other characters are Truthy)
Fż▲→ġ#¬Ö#≡⁰Ṫḟë½D±o¬□m;

Try it online!
How does it work?
Fż▲→ġ#¬Ö#≡⁰Ṫḟë½D±o¬□m;   Function, takes a character c and a string S as arguments
                    m;   Wrap each character in S into it's own string
             ë           List of four functions returning booleans:
              ½D±o¬      Lower case?,Upper case?,Digit?,Not alphanumeric?
           Ṫḟ            Outer product with find†
       Ö#≡⁰              Sort on how many characters have the same Truthyness as c
    ġ#¬                  Group strings with equal numbers of spaces
   →                     Take the last group
Fż▲                      Squash it all into one list

† ḟ is a function that takes a predicate p and a list L and returns the first element of L that satisfies p. If no element satisfies p a default argument is returned. In this case ' '. By applying ḟ to a one character string, we are essentially saying if p c then c else ' '.
Ṫ Is function that takes a function f and two lists L1,L2. It returns a table of f applied over all pairs of L1 and L2. In this case f is ḟ, L1 is our list of 4 functions, and L2 is the list of one character strings.
After Ṫḟ we have a list of strings where each string is the result of replacing characters which don't satisfy one of the rules with a ' '.
NB: In newer versions of Husk, ġ#¬Ö#≡⁰ can be replaced by k#≡⁰ for a 3 byte saving!

Out of curiosity: why ' ' and 'a'? Maybe I understand it better when the explanation is added, because I can't read Husk. ;)

Nice! Here's 24 bytes using Ṫ.

@Zgarb Thanks! I didn't really understand what Mmm was doing myself :)

Unfortunately this doesn't really help with golfing, but S\?' might be simpler as?IK' `

I tend to avoid using I, sometimes it makes the interpreter take forever. It also seems wasteful.

Wait, I've found a shorter approach thanks to the fact that 'ḟ' returns a space when no element of a string satisfies its condition

@Leo Holy cow, this answer is getting short! Thanks

Jelly, 31 bytes
ØṖḟØBṭØBUs26¤f€³Lİ⁴¡$ÐṀFf
¹⁶Ç?€

Try it online!
The boolean values are 2 and 1 (or any other positive even/odd pair), which represent True and False respectively. I will try to add an explanation after further golfing.
Thanks to caird coinheringaahing for saving 2 bytes, and to Lynn for saving 4 bytes! Thanks to one of Erik's tricks, which inspired me to save 4 bytes!
How it works
Note that this is the explanation for the 35-byte version. The new one does roughly the same (but tweaked a bit by Lynn), so I won't change it.
ØBUs26f€³µ³ḟØBW,µẎLİ⁴¡$ÐṀF - Niladic helper link.
ØB                         - String of base digits: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
                             abcdefghijklmnopqrstuvwxyz'.
  U                        - Reverse.
   s26                     - Chop into sublists of length 26, preserving shorter
                             trailing substrings.
      f€³                  - For each, keep the common characters with the input.
            ØB             - Base digits.
          ³ḟ               - Get the signs in the input. Filter the characters of the
                             input that aren't alphanumeric.
              W,µẎ         - Concatenate (wrap, two element list, tighten).
                       ÐṀ  - Keep the elements with maximal link value.
                  L        - Length.
                    ⁴¡     - Do N times, where N is the second input.
                   İ       - Inverse. Computes 1 ÷ Length. 2 maps to the length itself,
                             because 1 ÷ (1 ÷ Length) = length; 1 yields
                             (1 ÷ Length), swapping the maximal numbers with minimal ones.
                         F - Flatten.

¹⁶e¢$?€ - Main link.
      € - For each character.
   e¢?  - If it is contained by the last link (called niladically), then:
¹       - Identity, the character itself, else:
 ⁶      - A space.

40 bytes

@cairdcoinheringaahing Thanks! :) I wanted to golf that part ever since I posted the answer, but I couldn't figure out why it didn't work... I had an extraneous µ D:

31 bytes: generate the classes as ØṖḟØBṭØBUs26¤, and then test membership with f and Ç instead of e¢$.

Python 2, 166 158 bytes
t=lambda c:('@'<c<'[','`'<c<'{','/'<c<':',1-c.isalnum())
def f(s,b):x=map(sum,zip(*map(t,s)));print''.join([' ',c][x[t(c).index(1)]==sorted(x)[-b]]for c in s)

Try it online!

158 bytes

@Mr.Xcoder Thanks; Just got that as well  :)

R, 193 186 179 158 bytes
-7 bytes thanks to NofP and his suggestion of cbind
-6 bytes using outer, -1 byte switching [^a-zA-Z0-9] with [[:punct:]]
-21 bytes thanks to MickyT for pointing out a list of characters is allowed
function(S,B){y=outer(c("[a-z]","[A-Z]","\\d","[[:punct:]]"),S,Vectorize(grepl))
S[!colSums(y[(s=rowSums(y))=="if"(B,max,min)(s),,drop=F])]=" "
cat(S,sep='')}

Verify all test cases
Takes 1/T as truthy (max) and 0/F as falsey (min), and takes S as a list of single characters.
Try it online!
In my original version (with NofP's suggestions), the matrix y is constructed by evaluating grepl(regex, S) for each regex, then concatenating them together as columns of a matrix. This results in multiple calls to grepl, but as S is fixed, it seemed that something else needed to be done. As I noted:

There are potentially shorter approaches; mapply, for example:
y=mapply(grepl,c("[a-z]","[A-Z]","\\d","[^a-zA-Z0-9]"),list(S))
unfortunately, this will not simplify as a matrix in the 1-character example of "A".

I used outer rather than mapply, which always returns an array (a matrix in this case), and was forced to Vectorize grepl, which is really just an mapply wrapper around it.
I also discovered the predefined character group [:punct:] which matches punctuation (non-space, non-alphanumeric) characters.

If you replace the matrix with a cbind, you could reduce to 186 bytes:
y=cbind(g("[a-z]",S),g("[A-Z]",S),g("\d",S),g("[^a-zA-Z0-9]",S))

@NofP oh, very nice. Also, you can surround code with backticks (`) to have it display like this. :)

The rules state that you can use a character array or list as input , so you could probably remove the S=el(strsplit(G,""))

@MickyT ah, I overlooked that, thank you.

Husk, 31 29 28 bytes
SMS?' `ṁ§foSM≠?▲▼⁰M#Kë½D±o¬□

Uses 0 for minimal and 1 for maximal character counts.
Try it online!
Explanation
Lists of functions are cool.
SMS?' `ṁ§foSM≠?▲▼⁰M#Kë½D±o¬□  Inputs are bit B and string S.
                     ë        Make a list L of the four functions
                      ½       is-lowercase-letter,
                       D      is-uppercase-letter,
                        ±     is-digit, and
                         o¬□  not is-alphanumeric.
                  M#          For each of them, take number of matches in S,
              ?▲▼⁰            take maximum or minimum depending on B,
          oSM≠                and mark those entries that are not equal to it.
        §f          K         Remove from L the functions that correspond to marked entries, call the result L2.
                              These functions test whether a character should be replaced by a space.
SM                            Do this for each character C in S:
      `ṁ                      Apply each function in L2 to C and sum the results.
  S?'                         If the result is positive, return space, otherwise return C.

Python 2, 140 bytes
g=lambda x:x.isalnum()-~(x>'Z')*x.isalpha()
def f(s,m):k=map(g,s).count;print''.join([' ',c][k(g(c))==sorted(map(k,range(4)))[m]]for c in s)

Try it online!
Jonathan Frech saved a byte. Thanks!
Highest is m=-1, lowest is m=0.

I think you can save a byte by replacing +x.isalpha()*-~(x>'Z') with -~(x>'Z')*x.isalpha().

Python 2, 190 183 174 173 bytes
Thanks to Jonathan Frech for shortening it
from re import*
def f(i,c):
 q='[a-z]','[A-Z]','\d','[\W_]';l=[len(set(finditer(p,i)))for p in q]
 for j,k in enumerate(l):
	if k-eval(c):i=compile(q[j]).sub(' ',i)
 print i

This takes the strings 'max(l)' and 'min(l)' as true and false. (I don't think this breaks the rules...?)
This is longer than the other two python answers but different so I thought I'd post it. I'm not a great golfer so I'm guessing this could be improved further but all the things I tried didn't work.
Try it online!

Hello, and welcome to the site! When I try to run this, I get errors, and I'm not entirely sure why. One reason could be that sum(1for m... should be sum(1 for m..., but I think there are other problems too. Could you provide a link to an online interpreter (such as tio) to demonstrate how you're calling this, and to show it isn't erroring?

@DJMcMayhem I just added a link, thanks for providing the link I wasn't sure how to do it. I am not getting an error when I run it there.

Ah, I couldn't tell that you were inputting max(l) and min(l) as strings, that's why I was getting errors. Thanks for clearing that up! Although now, this is on the edge of violating rule #3,  Note that these distinct values should be used (somewhat) as a boolean, but it's definitely a little bit of a gray area.

BTW, here's a TIO pro-tip: If you put your function calls in the footer field, they won't be counted towards your byte count, so you can easily see how long your answer is: Try it online!

@DJMcMayhem Ah thanks. I agree it's kind of a gray area. I could take 'max' and 'min' as true false then do eval(c+'(l)') which adds 6 Bytes and seems more acceptable but until OP disallows my answer I'm assuming it's okay.

183 bytes; in my opinion your boolean values are acceptable, as they are two consistent and distinct values.

174 bytes.

Assuming that finditer(...) produces unique objects, one could save a byte by using len(set(... instead of len(list(....

@JonathanFrech Yeah finditer produces unique objects so set works over list. Thanks for all the edits!

@JonathanFrech list(findall(... would have also shortened it by one byte but findall just returns the matches as strings so set(findall(... doesn't count duplicates of characters in the input string.

Java (OpenJDK 8), 448 439 432 362 361 354 352 348 343 320 bytes
s->b->{int w[]=new int[4],m=0,n=-1>>>1,l;s.chars().forEach(c->{if(c>96&c<123)w[0]++;else if(c>64&c<91)w[1]++;else if(c>47&c<58)w[2]++;else++w[3];});for(int W:w){m=W>m?W:m;n=W<n?W:n;}l=m-n;m=b?m:n;return l<1?s:s.replaceAll("["+(w[0]!=m?"a-z":"")+(w[1]!=m?"A-Z":"")+(w[2]!=m?"\\d]":"]")+(w[3]!=m?"|[^a-zA-Z0-9]":"")," ");}

Try it online!

366 bytes

You can remove the + in \\|+$ for an additional -1 byte.

You can save three more bytes by changing the last part to String r=(w[0]!=m?"[a-z]|":"")+(w[1]!=m?"[A-Z]|":"")+(w[2]!=m?"[0-9]|":"")+(w[3]!=m?"[^a-zA-Z0-9]|":"");return r.isEmpty()?s:s.replaceAll(r.replaceAll(".$","")," ");}.

Oh, and n=s.length() can be n=-1>>>1 for an additional -4.

Oh, one more small thing to golf: [0-9] -> \\d

Suggest {0,0,0,0} instead of new int[4] and int z=c>96&c<123?w[0]++:c>64&c<91?w[1]++:c>47&c<58?w[2]++:++w[3]; instead of if(c>96&c<123)w[0]++;else if(c>64&c<91)w[1]++;else if(c>47&c<58)w[2]++;else++w[3];

Jelly, 35 bytes
ØWṖs26µẎØṖḟW⁸;
¢ċ@€S¥€N⁹¡Mị¢Ẏ⁸f€ȯ€⁶

Try it online!

Ruby, 118 116 bytes
Takes 0 (lowest) or -1 (highest) for its second argument.
-2 bytes thanks to Lynn.
->s,t{s.gsub(/./){|c|[/\d/,/[a-z]/,/[A-Z]/,/[^\da-z]/i].group_by{|x|s.scan(x).size}.sort[t][1].any?{|x|x=~c}?c:" "}}

Try it online!
Ungolfed
->s,t{
  s.gsub(/./) {|c|
    [ /\d/,
      /[a-z]/,
      /[A-Z]/,
      /[^\da-z]/i
    ]
    .group_by {|x| s.scan(x).size }
    .sort[t][1]
    .any? {|x| x =~ c } ? c : " "
  }
}

Very cool answer! You can use -1 as the “highest” value and replace minmax[t] by sort[t].

PHP, 161 158 bytes
for([,$s,$z]=$argv;~$c=$s[$i++];)foreach([punct,upper,lower,digit]as$f)(ctype_.$f)($c)?$$i=$f:$g[$f]++;while(~$c=$s[$k++])echo$g[$$k]-($z?min:max)($g)?" ":$c;

Run with -nr or try it online.

first loop: for each position, remember the group of the character
and count the occurences of groups that the current character is not in.
(that negation saved 3 bytes)
depending on second parameter, pick min non-count for truthy, max non-count for falsy.
second loop: if (group of current character) non-count differs
from min/max non-count then print space, else print character.

@KevinCruijssen Make sure you have the latest PHP version (7.1.0) selected.

JavaScript (ES6), 151 149 bytes

g=
(s,f,a=[/\d/,/[A-Z]/,/[a-z]/,/[_\W]/],b=a.map(r=>s.split(r).length))=>s.replace(/./g,c=>b[a.findIndex(r=>r.test(c))]-Math[f?"max":"min"](...b)?' ':c)
<input id=s oninput=o.textContent=g(s.value,f.checked)><input id=f type=checkbox onclick=o.textContent=g(s.value,f.checked)><pre id=o>

Sadly the rules probably don't allow me to pass Math.max or Math.min as the flag. Edit: Saved 2 bytes thanks to @JustinMariner.

Jelly, 37 bytes
ØWṖs26µẎØṖḟW⁸;
¢f@³L$ÐṂFe@Ð€³¬¹⁴?a³o⁶

Try it online!
-6 bytes "borrowing" from Erik's post :D

Lol preserving the spaces is essentially half the program :D

Could you add an explanation, or are you still working on golfing it first?

@KevinCruijssen Golfing first :D

Bash, 229 227 212 bytes
LANG=C;g="A-Z a-z 0-9 !A-Za-z0-9";declare -A H
f()(((i=$2?99:-1));r=$1;for h in $g;{ t=${r//[$h]};t=${#t};(($2?t<i:t>i))&&i=$t&&H=([$h]=1);((t-i))||H[$h]=1;};for h in $g;{((${H[$h]}))||r=${r//[$h]/ };};echo "$r")

Try it Online

I'm not sure how the spaces around brackets and square-blocks work in Bash, but it still seems to work without the space at f(){((.

yes, space is mandatory generally except for (, also 2 bytes could be saved using ( instead of {, degrading performance because creating a subshell

Java (OpenJDK 8), 307 + 34 306 + 27 295 bytes
My "interesting" take on the challenge.
Thanks to Kevin Cruijssen for cutting down the import bytes removing the import entirely!
s->b->{String t=s.replaceAll("\\d","2").replaceAll("[a-z]","0").replaceAll("[A-Z]","1").replaceAll("\\D","3"),v="";int a[]={0,0,0,0},i=0,z=0,y=-1>>>1;t.chars().forEach(j->{a[j%4]++;});for(int x:a){z=x>z?x:z;y=x<y?x:y;}for(;i<s.length();i++)v+=a[t.charAt(i)%4]!=(b?z:y)?" ":s.charAt(i);return v;}

Try it online!
Explanation:
String t=s.replaceAll("\\d","2")
          .replaceAll("[a-z]","0")
          .replaceAll("[A-Z]","1")
          .replaceAll("\\D","3")

First replaces each group with an integer between 0 and 3 using some simple regex and stores this in a new String.
int a[]={0,0,0,0},m,i=0,z=0,y=-1>>>1;
Initialises an array of integers as well as a couple of other integers to use later. Sets the y variable to the max int size using unsigned right bit shift.
t.chars().forEach(j->{a[j%4]++;});
For each character in the modified string, this uses its ASCII value modulo 4 to calculate the index of the aforementioned array to increment.
for(int x:a){
    z=x>z?x:z;
    y=x<y?x:y;
}

This then loops through the counts of each group stored in the array and calculates the minimum (y) and the maximum (z).
for(;i<s.length();i++)
    v+=a[t.charAt(i)%4]!=(b?z:y)?" ":s.charAt(i);

Loops through every character in the String again, checking if the group of that characters group is equal to the min/max (using the modulo trick mentioned earlier). If it isn't equal, then a space is added to the new String in the characters place, otherwise the original character is added.
return v;
Finally return the new String!

Nice answer, +1 from me! Two small things to golf: import java.util.stream.IntStream; can be import java.util.stream.*; and ,i can be ,i=0 after which you can remove i=0 from the for-loop. Oh, and (s,b)-> can be s->b->.

@KevinCruijssen Thanks! I didn't realise you could chain lambdas

It's called currying. :) You can do it like this java.util.function.Function<String, java.util.function.Function<Boolean, String>> g = s->b->{...};.

Oh, and another thing to golf: IntStream z=IntStream.of(a);m=(b?z.max():z.min()).getAsInt(); can be l=s.length(),x=0,y=l and for(int x:a){z=x>z?x:z;y=x<y?x:y;} and (b?z:y), so you no longer need the import. Putting it all together becomes: s->b->{String t=s.replaceAll("\\d","2").replaceAll("[a-z]","0").replaceAll("[A-Z]","1").replaceAll("\\D","3"),v="";int a[]={0,0,0,0},i=0,l=s.length(),z=0,y=l;t.chars().forEach(j->{a[j%4]++;});for(int x:a){z=x>z?x:z;y=x<y?x:y;}for(;i<l;i++)v+=a[t.charAt(i)%4]!=(b?z:y)?" ":s.charAt(i);return v;} (294 bytes).

Ignore the previous comment (I deleted it), y can remain y=-1>>>1 and the loop can be for(String p:s.split(""))v+=a[t.charAt(i++)%4]!=(b?z:y)?" ":p;.

@KevinCruijssen Oooooh nice thinking! I might wait a bit before changing it just in case you come up with anything else ;)

Hehe. :) Well, I'm not at work anymore, so I probably won't look at codegolf until tomorrow. I usually look at codegolf a bit when I have to wait a bit for something at work, but I barely look at it at home.

JavaScript (ES6), 139 bytes
s=>b=>s.map(c=>++a[g(c)]&&c,a=[0,0,0,0],g=c=>c>-1?0:/[a-z]/i.test(c)?c<"a"?2:1:3).map(c=>a.map(v=>v-Math[b?"max":"min"](...a))[g(c)]?" ":c)

Input and output is an array of characters. Takes actual boolean values for input.
A different approach from @Neil's answer; almost avoiding regular expressions. Instead, I used a series of checks to determine the category of each character:

Digits return true for c>-1 because non-digits fail mathematical comparisons
Uppercase letters match the regex /[a-z]/i and have codepoints less than "a"
Lowercase letters match that regex but have codepoints not less than "a"
Symbols pass none of those tests

Test Cases

f=
s=>b=>s.map(c=>++a[g(c)]&&c,a=[0,0,0,0],g=c=>c>-1?0:/[a-z]/i.test(c)?c<"a"?2:1:3).map(c=>a.map(v=>v-Math[b?"max":"min"](...a))[g(c)]?" ":c)

;[["Just_A_Test!", true],["Just_A_Test!", false],["Aa1!Bb2@Cc3#Dd4$", true],["Aa1!Bb2@Cc3#Dd4$", false],["H@$h!n9_!$_fun?", true],["H@$h!n9_!$_fun?", false],["A", true],["A", false],["H.ngm.n", true],["H.ngm.n", false],["H.ngm4n", false]]
.forEach(([S,B])=>console.log(`"${S}", ${B} -> "${f(S.split``)(B).join``}"`))
.as-console-wrapper{max-height:100%!important}


text:
Solve the equation `a*x == b` with Int32 arithmetics
In this thread we use 32-bit signed integers (assuming the usual two's complement). For simplicity I shall call this type Int32. The range is from -2147483648 through 2147483647. Any two values can be successfully multiplied (the result is an Int32 as well) since we use multiplication without overflow checking (we only keep the 32 least significant bits of the product).
For example, we have:
2147483647 * 2 == -2

and so on.
If your language does not have native support for 32-bit signed integers (with two's complement), you must emulate it.
Your task is to solve the equation:
a * x == b

where a and b are given as input, and it is assumed that a is an odd number (i.e. least significant bit is 1). You output an Int32 value.

The input to your program shall be two Int32 values a and b, and a will be odd
The output must be one Int32 value such that (if we call the output x) a*x == b
You do not have to handle invalid input; in particular, if the argument a is an even number, it does not matter what your code does
Code golf

Test cases:

Input                  Output

1,42                   42
3,126                  42
5,5                    1

-3,126                 -42
3,-126                 -42
-3,-126                42

2147483647,-2          2
2147483647,2           -2
2147483647,666         -666

3,0                    0
3,1                    -1431655765
3,2                    1431655766

-387907419,1342899768  1641848792
348444091,1076207126   -1334551070
10,14                  irrelevant (illegal input)

In the last case [a,b]==[10,14], even if there is a solution x = -1717986917 (not unique, x = 429496731 also works), you do not have to handle that case (10 is not odd).

@PeterTaylor, is this an exact duplicate? The other thread takes in the "denominator" (which they call a) and the modulus (which they call b) and asks you to find "1/a" modulo b, stating the result in the interval 0...(b-1). My question says input is a "denominator" (which I also call a) and a "numerator" b, and the modulus is always 2**32, and I want the result "b/a" modulo 2**32, representative in the interval (-2**31)...(2**31-1). I can see the threads are very related, but answers to one challenge cannot be used for the other.

(continued) My question is actually much less general because I ask for only one magical modulus. And there are also different requirements when a is not invertible modulo the relevant modulus. Addition: The other thread also links Compute modular inverse which is very similar. I admit I do not know just how similar to challenges must be to be considered duplicates, here on Code Golf.

The basic rule of thumb is: could answers be copied across with only minor changes? Things like hard-coding a parameter or adding a loop over a parameter are considered sufficiently minor. The difference of range between 0...(b-1) and (-2**31)...(2**31-1) is completely trivial, because when working with 32-bit integers that just drops out.

An answer such as the earliest one below, by HyperNeutrino, could never be copied to the other thread because the other thread requires arbitrary modulus, and HyperNeutrino's answer only works with modulus 2**32. However, in the opposite direction, most answer from the other thread can be copied to here, though you need to insert a new multiplication by my b modulo 2**32, but I suppose they would not "compete" well in here because they are designed to also be well-behaved in the case where the inverse is impossible.

Python 3, 39 bytes
lambda a,b,h=2**31:(a**~-h*b+h)%(2*h)-h

This is a theoretical solution that will take a long time unless a = 1. It uses the Euler-Fermat theorem to determine the modular inverse of a.
Alternate version, 47 bytes
lambda a,b,h=2**31:(pow(a,h-1,2*h)*b+h)%(2*h)-h

This does exactly the same, but in a more efficient manner.
Try it online!

Java (OpenJDK 8), 44 bytes
a->b->{for(int i=0;;i++)if(a*i==b)return i;}

Try it online!
-12 bytes by using a currying lambda thanks to Kevin Cruijssen

Dang, you beat me to it.. Btw, since you're using OpenJDK 8, you can change int f(int f,int p) to f->p->. Try it here.

I wonder if most answers are going to simply use brute force like that.

@JeppeStigNielsen Probably, yes. 2^32 isn't much to bruteforce in most languages actually. Java is probably one of the most inefficient ones for it. Also, too bad it's multiplication, because if it was addition it would be similar to a deleted Sandbox question of mine.

@KevinCruijssen Oh cool, thanks!

Wolfram Language (Mathematica), 36 bytes
Mod[#2PowerMod[#,-1,m=2^32],m,-m/2]&

Try it online!

source: Stack Exchange

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

sort: votes


text:
ASCII rhombic grid
Write the shortest code measured by byte count to generate an ASCII grid composed of rhombi, given the following parameters:

m - number of complete rhombi in one row
n -  number of rows
s - side of the smallest rhombus
r - level of nesting - how many rhombi are there inside the "base ones" (which are fonud between the intersections of the grid)

Examples
1. Input: 5 3 1 0
Output:

/\/\/\/\/\
\/\/\/\/\/
/\/\/\/\/\
\/\/\/\/\/
/\/\/\/\/\
\/\/\/\/\/

A 5x3 grid of rhombi with side 1, no nesting

2. Input: 3 2 2 0
Output:

 /\  /\  /\
/  \/  \/  \
\  /\  /\  /
 \/  \/  \/
 /\  /\  /\
/  \/  \/  \
\  /\  /\  /
 \/  \/  \/

A 3x2 grid of rhombi with side 2, no nesting

3. Input: 5 2 1 2
Output:

///\\\///\\\///\\\///\\\///\\\
///\\\///\\\///\\\///\\\///\\\
///\\\///\\\///\\\///\\\///\\\
\\\///\\\///\\\///\\\///\\\///
\\\///\\\///\\\///\\\///\\\///
\\\///\\\///\\\///\\\///\\\///
///\\\///\\\///\\\///\\\///\\\
///\\\///\\\///\\\///\\\///\\\
///\\\///\\\///\\\///\\\///\\\
\\\///\\\///\\\///\\\///\\\///
\\\///\\\///\\\///\\\///\\\///
\\\///\\\///\\\///\\\///\\\///

A 5x2 grid of rhombi with side 1 (the smallest rhombus), level of nesting is 2

4. Input: 4 2 2 1
Output:

 //\\  //\\  //\\  //\\
///\\\///\\\///\\\///\\\
//  \\//  \\//  \\//  \\
\\  //\\  //\\  //\\  //
\\\///\\\///\\\///\\\///
 \\//  \\//  \\//  \\//
 //\\  //\\  //\\  //\\
///\\\///\\\///\\\///\\\
//  \\//  \\//  \\//  \\
\\  //\\  //\\  //\\  //
\\\///\\\///\\\///\\\///
 \\//  \\//  \\//  \\//

A 4x2 grid of rhombi with side 2 with level of nesting 1

5. Input: 4 2 3 3
Output:

  ////\\\\    ////\\\\    ////\\\\    ////\\\\
 /////\\\\\  /////\\\\\  /////\\\\\  /////\\\\\
//////\\\\\\//////\\\\\\//////\\\\\\//////\\\\\\
//////\\\\\\//////\\\\\\//////\\\\\\//////\\\\\\
/////  \\\\\/////  \\\\\/////  \\\\\/////  \\\\\
////    \\\\////    \\\\////    \\\\////    \\\\
\\\\    ////\\\\    ////\\\\    ////\\\\    ////
\\\\\  /////\\\\\  /////\\\\\  /////\\\\\  /////
\\\\\\//////\\\\\\//////\\\\\\//////\\\\\\//////
\\\\\\//////\\\\\\//////\\\\\\//////\\\\\\//////
 \\\\\/////  \\\\\/////  \\\\\/////  \\\\\/////
  \\\\////    \\\\////    \\\\////    \\\\////
  ////\\\\    ////\\\\    ////\\\\    ////\\\\
 /////\\\\\  /////\\\\\  /////\\\\\  /////\\\\\
//////\\\\\\//////\\\\\\//////\\\\\\//////\\\\\\
//////\\\\\\//////\\\\\\//////\\\\\\//////\\\\\\
/////  \\\\\/////  \\\\\/////  \\\\\/////  \\\\\
////    \\\\////    \\\\////    \\\\////    \\\\
\\\\    ////\\\\    ////\\\\    ////\\\\    ////
\\\\\  /////\\\\\  /////\\\\\  /////\\\\\  /////
\\\\\\//////\\\\\\//////\\\\\\//////\\\\\\//////
\\\\\\//////\\\\\\//////\\\\\\//////\\\\\\//////
 \\\\\/////  \\\\\/////  \\\\\/////  \\\\\/////
  \\\\////    \\\\////    \\\\////    \\\\////

A 4x2 grid of rhombi with side 3, level of nesting 3

Be sure to display the partially visible rhombi at the edges and corners where necessary.

@AdmBorkBork By "nesting" I mean the number of rhombi inscribed in the base ones, found between the intersections of the grid.

Related

@Luis Mendo - yes, it's clearly related to my task.

@Stewie Griffin: https://codegolf.stackexchange.com/questions/146747/ascii-rhombic-grid#comment359169_146747 — 3rd test case

Oh, how I miss my pillow!

SOGL V0.12, 20 bytes
ā.I∫e+H╚╬8}:±№╬8╬¡∙*

Try it Here!
Takes the input in the reversed order of what they are in the examples - r, s, n, m.
Explanation:
ā                     push an empty array - canvas
 .I∫      }           for each in range(input) (1-indexed)
    e+                  add the second input
      H                 decrement
       ╚                create a diagonal of that size
        ╬8              insert into the canvas
           :          create a duplicate of the canvas
            ±№        reverse it vertically and horizotally
              ╬8      insert that into the canvas
                ╬¡    quad-palindromize
                  ∙   multiply vertically by the next input
                   *  multiply horizontally by the next input

This is just amazing, how do you even compress such a program in 20 bytes.

This is just brilliant... +1 from me for beating Charcoal by a staggering 28 bytes :O

That''s really impressive!

@Mr.Xcoder 19 bytes now. But then I'm up against builtins like ∙*...

@Neil * is basically vercorized repetition, and ∙ - non-vectorized repetition. Those two built-ins together should be <=4 bytes in many golfing languages

Vectorised string repeating is reasonably short in Charcoal; if I could build up a string representation of the diamond it would only cost me 6 bytes to repeat it. Unfortunately it takes me 50 bytes to do that. On the other hand, drawing the diamond only takes me 17 bytes, just 1 more than SOGL... but it then takes 20 bytes to multiply the canvas.

@neil I had a feeling it was like that. I'm guessing that Charcoal can't get the canvas as a single string?

Charcoal, 48 39 37 bytes
ＵＯ⊕Ｉε\Ｆ⊖ＩζＣ¹¦¹‖ＭL≔⊗⁺ＩζＩεδＦ⊖ＮＣδ⁰Ｆ⊖ＮＣ⁰δ

Try it online! Link is to verbose version of code. Explanation:
ＵＯ⊕Ｉε\

Draw a square of size r + 1. This is a quarter of a nested diamond of size 1.
Ｆ⊖ＩζＣ¹¦¹

Copy the square 1 square right and down s - 1 times to get it to the right size.
‖ＭL

Reflect it to become a full nested diamond.
≔⊗⁺ＩζＩεδ

Compute the size of this nested diamond.
Ｆ⊖ＮＣδ⁰

Copy the diamond to the right m - 1 times.
Ｆ⊖ＮＣ⁰δ

Copy the diamond downwards n - 1 times.

Python 2, 160 159 158 bytes
-1 byte thanks to Jonathan Frech

m,n,s,r=input()
l=~-s*' '+'/'*(r-~r)+~-s*' '
for x in range(n*2):print'\n'.join(m*(l[i:i+s+r]+l.replace(*'/\\')[i:i+s+r][::-1])for i in range(r+s))[::1-x%2*2]

Try it online!
This uses the fact that the bottom of the rhombus is the top inverted ([::-1]), iterating over range(n*2) and using ~x%2*2-1 to control if it is the top or the bottom.
For the top (and the bottom) the right side is just the left side inverted and replacing / with \ -> l.replace(*'/\\')..[::-1]
To generate the pattern / nesting ~-s*' '+'/'*(1+r*2)+~-s*' ' is used to make a string like   ///   that will be iterated and chopped :
   '|  //|/  '
  ' | ///|  '
 '  |/// | '
'  /|//  |'

I think (1+r*2) can be (r-~r).

Julia 0.6, 190 bytes
g(n,m,s,r)=(s+=r+1;f(i,j,u=mod(i-j+r,2s),v=mod(j+i+r,2s))=(" \\/")[abs(u-r)<abs(v-r)?1+(u<=2r):1+2(v<=2r)];
for i=1:2(s-1)m println((f(i+(i-1)÷(s-1),s+j+(j-1)÷(s-1))for j=1:2(s-1)n)...)end)

This is a functional solution which computes for every index pair i,j what the symbol should be displayed.
Try it online!
Illustration
Start with a grid
f(i,j,u=mod(i,2s),v=mod(j,2s))=(" -|*")[1+(u==0)+2(v==0)]
for i=1:2(s-1)m println((f(i-1,j)for j=1:2(s-1)n)...)end

---------*---------*----
         |         |
         |         |
         |         |
         |         |
         |         |
         |         |
         |         |
         |         |
         |         |
---------*---------*----
         |         |
         |         |
         |         |
         |         |
         |         |

r > 0 means thicker lines
f(i,j,u=mod(i+r,2s),v=mod(j+r,2s))=(" -|*")[1+(u<=2r)+2(v<=2r)]
for i=1:2(s-1)m println((f(i,j)for j=1:2(s-1)n)...)end

**-----*****-----*****--
**-----*****-----*****--
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||
**-----*****-----*****--
**-----*****-----*****--
**-----*****-----*****--
**-----*****-----*****--
**-----*****-----*****--
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||

Handle the corners by checking which line on the original grid is closest
f(i,j,u=mod(i+r,2s),v=mod(j+r,2s))=(" -|")[abs(u-r)<abs(v-r)?1+(u<=2r):1+2(v<=2r)]
for i=1:2(s-1)m println((f(i,j)for j=1:2(s-1)n)...)end

|-------|||-------|||---
||-----|||||-----|||||--
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||
||-----|||||-----|||||--
|-------|||-------|||---
---------|---------|----
|-------|||-------|||---
||-----|||||-----|||||--
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||
||     |||||     |||||

A fairy tells us to remove every s-1 line
f(i,j,u=mod(i+r,2s),v=mod(j+r,2s))=(" -|")[abs(u-r)<abs(v-r)?1+(u<=2r):1+2(v<=2r)]
for i=1:2(s-1)m println((f(i+(i-1)÷(s-1),s+j+(j-1)÷(s-1))for j=1:2(s-1)n)...)end

---||------||------||---
--||||----||||----||||--
  ||||    ||||    ||||
  ||||    ||||    ||||
  ||||    ||||    ||||
  ||||    ||||    ||||
--||||----||||----||||--
---||------||------||---
---||------||------||---
--||||----||||----||||--
  ||||    ||||    ||||
  ||||    ||||    ||||
  ||||    ||||    ||||
  ||||    ||||    ||||
--||||----||||----||||--
---||------||------||---

Traverse diagonally and done
f(i,j,u=mod(i-j+r,2s),v=mod(j+i+r,2s))=(" \\/")[abs(u-r)<abs(v-r)?1+(u<=2r):1+2(v<=2r)]
for i=1:2(s-1)m println((f(i+(i-1)÷(s-1),s+j+(j-1)÷(s-1))for j=1:2(s-1)n)...)end

 ///\\\  ///\\\  ///\\\
////\\\\////\\\\////\\\\
////\\\\////\\\\////\\\\
///  \\\///  \\\///  \\\
\\\  ///\\\  ///\\\  ///
\\\\////\\\\////\\\\////
\\\\////\\\\////\\\\////
 \\\///  \\\///  \\\///
 ///\\\  ///\\\  ///\\\
////\\\\////\\\\////\\\\
////\\\\////\\\\////\\\\
///  \\\///  \\\///  \\\
\\\  ///\\\  ///\\\  ///
\\\\////\\\\////\\\\////
\\\\////\\\\////\\\\////
 \\\///  \\\///  \\\///

JavaScript (ES6), 154 bytes

f=
(m,n,s,r)=>[...Array((s+=r)*n*2)].map((_,i)=>[...Array(s*m*2)].map((_,j)=>i/s&1^j/s&1?`\\ `[g(j%s)]:`/ `[g(s-1-j%s)],g=j=>i%s-j>r|j-i%s>r).join``).join`
`

m: <input type=number min=0 id=m>

n: <input type=number min=0 id=n>

s: <input type=number min=0 id=s>

r: <input type=number min=0 id=r>

Directly calculates the character at each cell of the output.

CJam, 44
q~:R+,_ff{-zR>}{_W%:~\+"\ /"f=}%_W%Wf%+*f*N*

Try it online
Explanation:
q~           read and evaluate the input
:R+          save the last number in variable R, then add the last 2 numbers (s+r)
,_           make an array [0 1 … s+r-1] and duplicate it
ff{…}        make a matrix, calculating for each (x,y) pair from the 2 arrays:
  -z         abs(x-y)
  R>         compared with R (1 if greater, 0 if not)
{…}%         transform each row of the matrix:
  _W%        duplicate and reverse it
  :~         bitwise-NOT each element (0 → -1, 1 → -2)
  \+         prepend to the original row
  "\ /"f=    replace numbers with characters from this string (by index):
              0 → '\'; 1, -2 → ' '; -1 → '/'
              this generates the "/\" part
_W%          duplicate the matrix and reverse the rows
Wf%+         reverse each row, then append (by rows) to the original matrix
              this adds the "\/" part
*            repeat the matrix (by rows) n times
f*           repeat each row m times
N*           join the rows with newlines

C# (.NET Core), 167 bytes
(c,r,s,n)=>{int w=s+n,i=0,j;var g="";for(;i<r*2*w;i++,g+="\n")for(j=0;j<c*2*w;){int y=i%w,q=(j/w+i/w+1)%2,p=~-w*q+j++%w*(1-2*q);g+=p>y+n|p<y-n?' ':"\\/"[q];}return g;}

Try it online!
I'm surprised by the size I managed; I was initially expecting a longer solution. In saying this, I'm sure there are other tricks I've missed.
DeGolfed
(c,r,s,n)=>{
    int w=s+n, // rhombus quadrant width, and height
        i=0, // string row
        j; // string column

    var g="";

    // go through every character row and column
    for(; i < r*2*w; i++, g += "\n")
        for(j = 0; j < c*2*w;)
        {
            int y = i % w, // vertical position in the quadrant
                q = ( j / w + i / w + 1) % 2, // Get the rhombus quadrant as a 0 or 1
                p = ~-w * q + j++ % w * (1-2*q); // horizontal position in quadrant. the value is either ascending or descending depending on the quadrant

            // select which character to use at this [i,j] position
            g += p > y + n | p < y - n ? ' ' : "\\/"[q];
        }

    return g;
}

163 bytes

Perl 5, 159 + 3 (-anl) bytes
($m,$n,$s,$r)=@F;$s=$"x($s+$r-1);$_="$s/\\$s"x$m;$n*=2;{$t=$_;map$t=~s, ?(\S) ?,$1x$&=~y///c,ge,1..$r;print$t;redo if s, /,/ ,g&&s,\\ , \\,g||y,/\\,\\/,&&--$n}

Try It Online

Python 2, 201 189 bytes
def f(m,n,s,r):Z=range(s+r);R=[r-~min(i,s+~i+r,min(s-1,r))for i in Z];L=[m*(' '*(s+~i)+'/'*R[i]+'  '*(i-r)+'\\'*R[i]+' '*(s+~i))for i in Z];print'\n'.join((L+[l[s+r:]+l[:s+r]for l in L])*n)

Try it online!
Uses the fact that the bottom is the same as the top, but shifted:
Top:       /\/\/\
Bottom:     /\/\/\

Saved 22 bytes thanks to Jonathan Frech

s-i-1 can be s+~i, saving two bytes. r+1+min(... can be r-~min(..., saving another one. L=[(...)*m for can be L=[m*(...)for, saving one more byte.

L+=[...];print'\n'.join(L*n) can be print'\n'.join((L+[...])*n) to save another byte, resulting in 196 bytes.

195 bytes, if one also replaces s+r-i-1 with s+~i+r.

190 bytes.

Alternative 192 bytes version or 191 bytes version using exec and string formatting.

189 bytes by using an imperative function.

@JonathanFrech Thanks a lot :)

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


text:
Concatenative counting
Your challenge is to write N snippets of code such that, when you concatenate the first K ≥ 1 together, they produce the number K. The higher N, the better. Here's the catch: you may not use any character more than once across your snippets.
Rules

You may use the same character multiple times in one (and only one) snippet.
These snippets must be concatenated in the order they are presented, without skipping any.
You must write at least two snippets.
All snippets must be in the same language.
Remember: snippets do not have to be full programs or functions, nor do they have to function on their own. -1 is a valid snippet in Java, e.g.
All resulting concatenations must output the respective K value.
The winner is the person with the highest N value. Tie-breaker is shortest overall program length in bytes.

Example
Suppose your snippets were AD, xc, 123, and ;l. Then:

AD should produce 1
ADxc should produce 2
ADxc123 should produce 3
and ADxc123;l should produce 4.

This program would have a score of 4.

Since they have to be snippets, in a stack-based language, the numbers can just be pushed on the stack, right?

To add to totallyhuman's question, in a stack-based language is top-of-stack the only value that matters? That is, could the first two snippets in dc be 1 and  2?

@totallyhuman I would say no--in a stack based environment, if you had multiple values on the stack, you "produced" more than one value, instead of the requested one integer.

@brhfl See above.

@ConorO'Brien Could just the top of the stack be considered output? 'Cause otherwise, it's practically impossible in a stack-based language with no implicit IO...

@totallyhuman ... You kidding me? I suggest you rethink your approach, I have my own version in a stack based language without implicit output.

@totallyhuman maybe a snippet should pull the old value of and push another value on the stack...

Python 3, 1 112 056 snippets, 4 383 854 bytes
This is very similar to @WheatWizard's Python 2 answer. I started working on this shortly before it was posted, but sorting out Python's quirks regarding non-ASCII characters and long lines took some time. I discovered that Python reads lines 8191 bytes at a time, and when those 8191 bytes contain only a part of a multi-byte character, Python throws a SyntaxError.
The first snippet uses an encoding from Fewest (distinct) characters for Turing Completeness.
exec('%c'%(111+1)+'%c'%(111+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+11)+'%c'%(111+1+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+11)+'%c'%(11+11+11+1+1+1+1+1+1+1)+'%c'%(111)+'%c'%(111+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+11)+'%c'%(11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+1+1)+'%c'%(111+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1)+'%c'%(11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+1)+'%c'%(11+11+11+11+1+1+1+1+1)+'%c'%(11+11+11+11+1+1+1+1+1+1)+'%c'%(11+11+11+11+11)+'%c'%(11+11+11+11+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1++++++++++1))

This monstrosity simply build the following string and executes it.
print(len(open(__file__).read())-1260)

The following snippets are all exactly one character long. The next three characters are \n, \r, and #. All remaining Unicode characters (except surrogates) follow in a specific order, so they align with the 8191-byte boundary.
The following script generates the appropriate programs for input k between 1 and 1112056.
j = 4
s = "exec('%c'%(111+1)+'%c'%(111+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+11)+'%c'%(111+1+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+11)+'%c'%(11+11+11+1+1+1+1+1+1+1)+'%c'%(111)+'%c'%(111+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+11)+'%c'%(11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+1+1)+'%c'%(111+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1+1)+'%c'%(11+11+11+11+11+11+11+11+1+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+11+11+11+11+11+1)+'%c'%(11+11+11+1+1+1+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1+1)+'%c'%(11+11+11+11+1)+'%c'%(11+11+11+11+1+1+1+1+1)+'%c'%(11+11+11+11+1+1+1+1+1+1)+'%c'%(11+11+11+11+11)+'%c'%(11+11+11+11+1+1+1+1)+'%c'%(11+11+11+1+1+1+1+1+1+1++++++++++1))"
l = 1
c = \
        [
                None,
                [n for n in range(0x80) if chr(n) not in "\n\r#%'()+1cex"],
                [*range(0x80, 0x800)],
                [*range(0x800, 0xd800), *range(0xe000, 0x10000)],
                [*range(0x10000, 0x110000)]
        ]

k = int(input())
assert k in range(1, 1112057)
s += '\n\r#'[:k - 1]
k -= 4

while j:
                while k > 0 and c[j] and l + j < 8191:
                        s += chr(c[j].pop())
                        l += j
                        k -= 1
                if k < 1:
                        print(end = s)
                        break
                elif c[j] == []:
                        j -= 1
                else:
                        s += chr(c[8191 - l].pop())
                        print(end = s)
                        k -= 1
                        s = ''
                        l = 0

Do you ever lose?

I'm confused as to how you have scored more than 256.  Are different unicode characters different characters?  If so why not use combining diacritics to obtain an infinite score?

@WheatWizard What is a character?

It seems that by that definition you can use combining diacritics to get a higher score.

@WheatWizard No, a letter plus a combining diacritic is two Unicode characters.

Why though?  Are emoji modifiers their own characters?

@WheatWizard I have no idea what those are, but if they have their own code points and aren't surrogates, they characters. Whenever in doubt, just run wc -m.

Perl 5, 50,091 151 snippets
First snippet:
use utf8; print length A

2nd through 26th snippets: B through Z
27th through 46nd snippets: a through z, excluding the characters in "length"
47th through 56th snippets: 0 through 9
57th snippet: _
The remaining snippets are the 50,105 individual Unicode characters which Perl regards as "word" characters, excluding the 14 distinct word characters in the initial snippet, in any order.
Well, it was a nice thought, but it turns out that after a certain length Perl gives you an "identifier too long" error.  This is the longest combined program I was able to get Perl to digest:
use utf8; print length A012345679BCDEFGHIJKLMNOPQRSTUVWXYZ_abcdjkmoqsvwxyzĀāĂăĄąĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıĲĳĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňŉŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţ

The perldiag manual page says "Future versions of Perl are likely to eliminate these arbitrary limitations" but my Perl 5.18 has not done so.
Explanation:
In non-strict mode, Perl 5 interprets unquoted strings of word characters as "barewords," essentially quoting them for you automatically.  They're usually best avoided, but they sure help here!

Your a-z snippets will most likely use characters from your first snippet.

Yes indeed, thanks.  Fixed.

I suggest that you make a "showcase"-like answer, because almost all (exo)langs - jelly, pyth, etc - have this behavior

I don't know what "showcase-like answer" means.

What @Rod wants you to do is to incorporate similar approaches from other languages in your answer. There's really no strong reason to do this, however, as we tend to prefer a single submission per answer

the strong reason is, if he don't do this, someone else will, and since he came with this idea first, seems fair to be his answer

Unfortunately I don't really know any esolangs.

@Sean Plenty can be found on esolangs.org, and because this approach does not require a thorough understanding to work, you can learn what you need from the site. In addition, many non-esolangs exhibit this behavior; for example, TI-BASIC's first snippet would be length("length(.

Your trick with Julia allows for 126427 snippets - to you want to take my answer?

JavaScript (ES6, V8 6.x), 52 50298 119526 119638 119683 128781 snippets, 88 149147 575179 575631 576121 612789 bytes
Farther below is a Stack Snippet that generates the full program, evaluates it, and creates a download link for the file. That snippet will continue to generate better answers as later versions of Unicode are supported by newer versions of JavaScript, which add new valid identifiers to the language.
Using ASCII only

console.log(new Proxy({},{get:(n,{length:e})=>e>>(e/e)}).nn$$00112233445566778899AABBCCDDEEFFGGHHIIJJKKLLMMNNOOQQRRSSTTUUVVWWXXYYZZ__aabbccddffiijjkkmmppqqssuuvvzz)

Explanation
This uses the metaprogramming technique of Proxy to enable a get handler trap on the object and access the property name as a string, returning the identifier's length / 2 as its value.
With the first snippet starting as new Proxy({},{get:(n,{length:e})=>e>>(e/e)}).nn, each additional snippet added increments the string length of the identifier by 2 by making sure to .repeat() the respective code point twice for 2 byte utf-16 characters, and once for 4 byte utf-16 characters.
Identifiers in JavaScript
In the ECMAScript Specification, an IdentifierName is defined with the following grammar:

IdentifierName::
  IdentifierStart
  IdentifierName IdentifierPart

IdentifierStart::
  UnicodeIDStart
  $
  _
  \UnicodeEscapeSequence

IdentifierPart::
  UnicodeIDContinue
  $
  _
  \UnicodeEscapeSequence
  <ZWNJ>
  <ZWJ>

UnicodeIDStart::
  any Unicode code point with the Unicode property “ID_Start”

UnicodeIDContinue::
  any Unicode code point with the Unicode property “ID_Continue”

Generating the answer
Initially using the "ID_Continue" Unicode property, I wrote a Node.js script that generates the full answer. Now it's just a client-side script that uses a naive eval() to test for valid characters, iterating through all the unicode code points instead:

// first snippet
let answer = 'new Proxy({},{get:(n,{length:e})=>e>>(e/e)}).nn'

const used = Array.from(
  answer,
  c => c.codePointAt(0)
).sort(
  (a, b) => a - b
)

// create a O(1) lookup table for used characters in first snippet
const usedSet = Array.from(
  { length: Math.max(...used) + 1 }
)

for (const codePoint of used) {
  usedSet[codePoint] = true
}

// equal to 1 for first snippet
let snippets = eval(answer)
let identifier = ''

for (let codePoint = 0, length = 0x110000; codePoint < length; codePoint++) {
  const character = String.fromCodePoint(codePoint)

  // if unused
  if (usedSet[codePoint] === undefined) {
    // if valid `IdentifierPart`
    try {
      eval(`{let _${character}$}`)
    } catch (error) {
      // console.log(character)
      continue
    }

    // repeat so that `snippet.length === 2`
    identifier += character.repeat(2 / character.length)
    snippets++
  }
}

// number of snippets generated
console.log(`snippets: ${snippets}`)

const program = `console.log(${answer + identifier})`

// output of program to validate with
eval(program)

// download link to check number of bytes used
dl.href = URL.createObjectURL(new Blob([program], { type: 'text/javascript' }))
Click to Download

Running stat -f%z answer.js yields a byte count of 612802, but we subtract 13 bytes for the console.log( and ) wrapping the actual submission.
Encoding
The source is stored as utf-8, which is reflected in the enormous byte count of the answer. This is done because Node.js can only run source files encoded in utf-8.
JavaScript internally stores strings with utf-16 encoding, so the string "character length" returned in JavaScript is actually just half the number of bytes of the string encoded in utf-16.

Why not use, say, x instead of $, freeing it up as an extra identifier character?

@Neil I noticed that a little while ago. I'm currently working on an answer that should be a score of ~119519. Right now I've got it down to just a matter of traversing the encoding properly.

I tried a copy of Spidermonkey JS shell that I happened to have lying around. It only supported 50466 different identifier characters. (Since you use 12 in your initial snippet, that scores you 50455.)

Well, without doing a major overhaul, it looks like the score will have to be 50297. Writing the answer now. To be clear, there are in fact 128,096 supported identifiers in ES6+ using Unicode 10.0.0 specification, but of those, only the number you mentioned have a string length of 1. Otherwise it's a lot more difficult to get a string character count, and that's what I was hung up on.

(Stupid site using keyup handlers to perform actions.) I then tried Node JS 8 and again I was only able to get 50466 different identifier characters.

Huh, I wonder what the other 156 characters are...

If I include those with a string length of 2 I get 119694 different identifier-safe characters?

@Neil would you mind sharing the script or snippet you used to produce that value? My suspicion is that your script might erroneously be including ; and whitespace characters, now that I think about it.

@Neil I updated my script to not just check ID_Continue, and now I'm getting 119638 characters that work in Node v8.2.1. I'll update my answer, but I think I need to use another service besides gist.

for(j=i=0;i<17<<16;i++)try{j+=20%eval("new Proxy({},{get:(n,e)=>e.length}).$$$"+String.fromCodePoint(i))===0}catch(e){};j (evaluated in Firefox's console)

@Neil I get 119683 snippets on Chrome, but 119638 on Node v8.2.1. The implementation was the discrepancy, not my algorithm.

Why not use if (!answer.includes(character))? Or if you think that's too slow, make usedSet = new Set(answer); (new Set tries to iterate its argument, so if you pass a string, it adds all distinct characters individually).

@Neil I recently answered a code review question where I discovered that using a sparse array as a set is ~10-20x faster than using Set() for non-negative integers.

So, this has 576121 snippets?

@ConorO'Brien, no, clearly in the title it says "119683 snippets".

@PatrickRoberts Sorry, my mistake, while reading this I assumed all the text until the ending one was just crossed out text. My eyes must have skipped over that part.

Python 2, score 32
for r in range(32):locals()[''.join(map(chr,range(65,66+r)[:26]+range(117,92+r)))]=r+1
print A

With subsequent snippets B, C, D, … Y, Z, u, v, w, x, y, z.
In a twist of dramatic irony, Python 3 supports Unicode identifiers, which would let us get very silly with this trick — but it can’t print without  parentheses. I could cram digits into the identifier, too, but I don’t think this approach is very fun to squeeze more out of.
Try it online!
Python 2, score 18, less cheat-y
print 0x10-1&0x1
print 0x10-1&0x12
print 0x10-1&0x123
print 0x10-1&0x1234
print 0x10-1&0x12345
print 0x10-1&0x123456
print 0x10-1&0x1234567
print 0x10-1&0x12345678
print 0x10-1&0x123456789
print 0x10-1&0x123456789A
print 0x10-1&0x123456789Ab
print 0x10-1&0x123456789Abc
print 0x10-1&0x123456789Abcd
print 0x10-1&0x123456789AbcdE
print 0x10-1&0x123456789AbcdEf
print 0x10-1&0x123456789AbcdEf^((()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==()))
print 0x10-1&0x123456789AbcdEf^((()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==()))|[[[]]>[]][[]>[]]
print 0x10-1&0x123456789AbcdEf^((()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==())+(()==()))|[[[]]>[]][[]>[]]<<False**False

Try it online!

Python 2, score 6 10
+3 thanks to pizzapants184
+1 thanks to WheatWizard

4/4
*2
-~0
+1
|5
^3
&776%6
and 8
if[]else[9][9>9]
.__xor__((""=="").__xor__((""=="")<<(""=="")))

Try it online!

if you change print int(True) to just 4/4, you can add and 7 for 7, given that you don't have to print the number, just 'produce' it

score 9, 47 bytes

Adding &2 will increase your score by one because & has higher precedence than ^, but you need to make the number 2 somehow. (You can use [[]==[]][[]<[]]<<[[]==[]][[]<[]])

@pizzapants184 Your solution seems to reuse the space, is that allowed?

@pizzapants184 Regardless this works for 10.

@WheatWizard score 9, 48 bytes (fixed: no repeated space)

@pizzapants184 ord was conflicting  with and, but I fixed that

TI-Basic (83 series, OS version 1.15 or higher), score: 17 18 19 24
(Tiebreaker: 53 bytes.)
You can get a very large score by abusing string length as usual: begin with length("A length("length( (as @Scrooble points out) and keep adding single-token snippets to the end. TI-Basic has over 700 of those, so that actually works pretty well. But here's another approach:
int(log(11
2
3
4
5
6
7
8
9
0
Xmax
Ymax
nMax
abs(Xmin
Ymin
ππ
eee
³
²
₁₀^(₁₀^(X
+e^(⁻e^(Y))))
/√(sub(Z!
°
randrandrand

Note that TI-Basic is tokenized, so (for example) the e^( command does not use any of the characters e, ^, (.
Relies on an undocumented feature of the sub( command: in addition to finding substrings, it can also be used to divide a number by 100.
This works if it's running on a fresh calculator, which lets us assume that X, Y, Z are all zero, that the window variables are set to their standard values, that the calculator is in radian mode, and that rand's first three outputs will be about 0.943, 0.908, 0.146.

PowerShell, 25 bytes, Score 5
' '.count*2+!""-(-1)|%{5}

Snippet 1: ' '.count outputs 1. It does this by taking the .count of an string, which is one because there is only one string. Try it online!
Snippet 2: *2 outputs 2 because we take the 1 from the previous snippet and multiply it by two Try it online!
Snippet 3: +!"" outputs 3 by adding the Boolean-not of an empty string. This implicitly casts the empty string to $true, which is again implicitly cast to 1, so we're adding one Try it online!
Snippet 4: -(-1) outputs 4 by simply subtracting negative one Try it online!
Snippet 5: |%{5} outputs 5 by taking the previous number into a loop and each iteration of that loop (only one, because there's only one input number) outputs 5 Try it online!
Thanks to Jan for an alternate means of coming up with 4 and a crafty way of coming up with 5.

How about ' '.count*2+!""-(-1)|%{5} for a score of 5?

@Jan Oh, right, haha, you don't actually need to use $_ inside |%{ }. Thanks!

C, 10 snippets, 45 bytes
sizeof(char)              // sizeof(char) = 1
<<9/9                     // Multiply by two.
|1                        // 2 or 1 = 3
,4                        // Discard previous expression, return 4.
+!!8                      // Add one.
^3                        // 5 xor 3 = 6
&66                       // 3 and 66 = 2, 5 xor 2 = 7 (& has higher precedence)
??'0xF                    // Trigraph for '^'. 7 xor 15 = 8
-~-2                      // ~-2 = 1, 7 xor 14 = 9
*57%5                     // 1*57%5 = 2, 7 xor 13 = 10

Try it online!

MATL, Score 8 15, 64 123 bytes

rg             % 1 Random number, make boolean (1)
Q              % 2 Increment
Yq             % 3 Nth prime
a,E]           % 4 any (convert to boolean 1. Do twice: Multiply by 2
T+             % 5 Add True
F~_-           % 6 Subtract negative (not(false)) = 6-(-1)
:sI/           % 7 Range 1:6, sum (21), divide by 3
A8*            % 8 All elements (True). Multiply by 8
d9             % 9 Clear stack, push 9
x10            % 10 Clear stack, push 10
WBPf           % 11 Raise 2^10. Convert to binary [1 0 ... 0], flip [0 0 ... 1]. Find
23ZP           % 12 Push 23, and calculate the distance between 11 and 23
yyyyyyyyyyyyyyyyyyyyyyyyhhhhhhhhhhhhhhhhhhhhhhhhz  % 13. Duplicate and count elements
tttttttttttttvvvvvvvvvvvn  % 14 Duplicate and count elements
OOOOOOOOOOOOOON&           % 15 Add bunch of zeros, output size of stack

Got to 12 with help from Luis Mendo! Using 11,23ZP was his idea, along with changing 3 with I for snippet 7.
Got to 15 with more help from Luis. OO...N& was his idea.

More to come. I don't know the MATL functions by heart, so I had to go back and forth and back and forth in the documentation... :)
Try it online!

Ooh, 5Yy is nice! I already use Y in 3 to get the second prime :(

I think you can get another one with OOOOOOON&. If you add others, this should probably be the last, because of &

Thanks again Luis! Also, why did I need soooo many yyyyyyyy...? I had to double the number, 24 y to get it duplicated 12 times...?

@Stewie I think it is because half the elements you are duplicating are the empty array generated by d. I'm on mobile now, but try X# to debug-print the stack

V, score 10
é1
<C-a>
r3
DÉ4
ñóä/5ñ
ddá6
xÁ7
C8<esc>
R9<C-c>
ø.<cr>ÎA0

Try it online!

Lenguage, 1 112 064 snippets
The nth snippet consists of 23n-1 repetitions of the nth non-surrogate Unicode character, up to and including the 1 112 064th and last non-surrogate character of the current Unicode standard.
Output is in unary (using the null byte as digit) for simplicity. Decimal is possible, but it will make the programs even longer. With unary, we can test the first programs.
For n = 1, we get 4 repetitions of U+0000. This is equivalent to the brainfuck program ., which prints one null byte.
For n = 2, we get 32 repetitions of U+0001, for a total of 36 characters. This is equivalent to the brainfuck program .., which prints two null bytes.
For n = 3, we get 256 repetitions of U+0002, for a total of 292 characters. This is equivalent to the brainfuck program ..., which prints three null bytes.
And so forth, up to n = 1 112 064.

Can you demonstrate or argue the equivalent in decimal? I'm not sure about the consensus on unary output but I believe it's for languages lacking concept of decimal—at least, last I checked

I believe it's for languages lacking concept of decimal Yes, and since Lenguage doesn't have decimal I/O, I assumed it was fine. Anyway, encoding the brainfuck program '+'*(48 + d) +'.>' for each decimal digit of n would achieve the same score. It's just a lot harder to describe.

I see. Same thing just longer.

Jelly, 253 bytes, score 250
L}“L

Subsequent 1-char snippets:
¡¢£¤¥¦©¬®µ½¿€ÆÇÐÑ×ØŒÞßæçðıȷñ÷øœþ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|~¶°¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ƁƇƊƑƓƘⱮƝƤƬƲȤɓƈɗƒɠɦƙɱɲƥʠɼʂƭʋȥẠḄḌẸḤỊḲḶṂṆỌṚṢṬỤṾẈỴẒȦḂĊḊĖḞĠḢİĿṀṄȮṖṘṠṪẆẊẎŻạḅḍẹḥịḳḷṃṇọṛṣṭụṿẉỵẓȧḃċḋėḟġḣŀṁṅȯṗṙṡṫẇẋẏż

Note: ¶ may also be replaced by \n, they're the same byte in Jelly's codepage.
After you append all those snippets, you can then append the 2-char snippet ”‘.
+1 thanks to Dennis.
Try it online!

BASIC (ZX Spectrum), score 244 (new score 247) [is this cheating?]
Snippet 1:
2356 PRINT PEEK (PEEK 23635+256*PEEK 23636+2)+256*PEEK (PEEK 23635+256*PEEK 23636+3)-56-66

Snippet 2: :
Snippet 3: REM
Snippets 4-244: Single-character snippets, using all characters not in snippets 1, 2 and 3.
Explanation
Characters
On Spectrum, PRINT is a single character (code 245). The snippet 1 uses 11 different characters: 2, 3, 5, 6, +, -, *, (, ), PRINT and PEEK What you see as spaces are a part of characters PRINT and PEEK, so the space itself hasn't been used. I decided to give the line number 2356 because these are the only digits present in the code.
Characters 13 and 14 are not allowed. That means there are 243 characters left for snippets 2-244, starting with : and REM to avoid the code that would produce error or do anything else.
How it works
This is why I'm not sure whether this answer is by the book.
23635 is the memory location for 16-bit system variable PROG, stored as LH. (The value is usually 23755. But apart from wrong result if it happens not to be the case, using this number directly, even though it would shorten the code, would cost me extra digit characters.) The value of PROG is the memory location where the program itself is stored. The first two bytes are the line number stored as HL, the following two bytes are the length of the line stored as LH. That's how the program looks up its own line's length, so something appropriate needs to be subtracted
Saving characters
Considering how numbers are stored, the line could have ended with -114 so that snippet 1 would produce 1. But I didn't want to use extra digits, so I instead took away two 2-digit numbers, which then had to add up to 122; 56 and 66 did nicely.
The code is a bit ugly with all nesting and calculating value of PROG (PEEK 23635+256*PEEK 23636) twice. But if I stored it and then used the stored value, it would cost extra characters / snippets - the line could start like
2356 LET p=PEEK 23635+256*PEEK 23636: PRINT PEEK (s+2)...

which would use 4 additional characters: LET, p, = and :.
Maybe I'll engineer this so that all numbers are calculated from numbers that use only 1 digit and gain 3 snippets.
EDIT:
Here is the new snippet 1 (that's how a long single line gets wrap-displayed on the Spectrum, so if you want to test the code , that will help you see that you typed it correctly):
1111 PRINT +PEEK (PEEK (11111+11
111+1111+(1+1+1)*(111-11)+1+1)+(
111+111+11+11+11+1)*PEEK (11111+
11111+1111+(1+1+1)*(111+1-11))+1
+1)+(111+111+11+11+11+1)*PEEK (P
EEK (11111+11111+1111+(1+1+1)*(1
11-11)+1+1)+(111+111+11+11+11+1)
*PEEK (11111+11111+1111+(1+1+1)*
(111+1-11))+1+1+1)-111-111-111-1
11-111-111

I could gain another snippet by avoiding the + and just make do with -. I'm not going to try it, this was enough of an ordeal.

dc, score 13, 58 bytes
I3%                   #I is the default input radix, 10, mod 3 yields 1
1+                    #Add one
2^2^2^Z               #2^8=256, Z pushes the number of digits to the stack
6*v                   #Square root of 18 = ~4.24, at precision 0 we get 4
c5                    #Start getting lazy, clear the stack and push 5
_F-E-                 #Subtract negative 15, then subtract 14
ss7                   #Lazy, 'drop' the value by storing it, push 7
SS8                   #Lazy, 'drop' the value by storing it, push 8
d::9                  #Lazy, 'drop' the value by storing it, push 9
;;kA                  #Recall element 9 from nonexistant array ; which is zero, set precision, push A (10)
iB                    #Set input radix to 10, push B (11)
oD                    #Set output radix to 11, push D (13, or 12 in base 11)
 4CCCCCCr/4C/CC/4/    #We have division and the digits 4 and C left, this might not be the optimal way to get us to 13 but it does the job

Try it online! (Note, the TIO version adds an f after each snippet to print the entire stack, showing that each snippet only leaves a single value on the stack; also I forgot the leading space on the last snippet which doesn't matter functionally when they're broken apart by line breaks but does count to my character usage)
Each additional snippet concatenation leaves the desired value and only the desired value on the stack. After hitting 12, I had kind of run out of ways to eat the stack. I tried to use math operations early on since they gobble up the stack and as we get into larger numbers it gets trickier to manage that way. When all is said and done, I have only the digit 0 left to play with and very little in the way of stack-popping, so I think 13 is pretty close to maxed out. I'm sure there are many similar (and likely shorter) ways of accomplishing this in dc, this just kind of fell into place. Note that cygwin handles A-F mixed in with 0-9 differently from most versions of dc, 44C4r/CC 4// works for the final snippet in cygwin.

Klein 011, 9 snippets
Snippet 1
!@1!aaaaaaaaaaaaaaaaaaaaa/a

Try it online!
Snippet 2
2((2|bbb0b2bbbb4bbbbbbbb

Try it online!
Snippet 3

c\*3ccccccccccccccccccccc\ccccccccc3c6cccc9
c\

Try it online!
Snippet 4
ddddddddddddddddddddddd>$d:d:++-$:+:+++$:?:-$-+++

Try it online!
Snippet 5
ee

Try it online!
Snippet 6
fff

Try it online!
Snippet 7
ggggg

Try it online!
Snippet 8
hh

Try it online!
Snippet 9
iiiii

Try it online!
Explanation
This was a really fun challenge for Klein.  Klein's unique topology allows for a lot of interesting stuff to be done.  As you might notice answers 5-9 are just adding filler (letters do nothing in Klein so I used them as filler) to the code to stretch out the bounding box.  This causes the ip to take a different path through earlier parts of the code because of Klein's unique topology.
I'm going to make a full explanation later, but for now here is a easier to understand version of the program with all of the letters replaced with .s.
!@1!...................../.2((2|...0.2....4........
.\*3.....................\.........3.6....9
.\.......................>$.:.:++-$:+:+++$:?:-$-+++.................

Try it online!

><>, Score: Infinity 1,112,064-6 = 1,112,058
Snippet 1 (6 bytes)
"l4-n;

This snippet outputs the amount of characters after the ; plus one. This can be extended to infinite very large amount of snippets of one character each. A quick google tells me there are 1,112,064 possible Unicode characters, minus the 6 I’ve already used.
Try
It
Online

Python 2, 110 snippets
Here is the complete snippet:
print((((len(open(__file__).read())-44.))))

#	 !"$%&'*+,/012356789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^`bcghjkmqsuvwxyz{|}~

Try it online!
The first snippet is
print((((len(open(__file__).read())-44.))))

And then the next 109 snippets are the next 109 bytes.
This is pretty "cheaty" as Lynn puts it.  The first snippet opens the file and subtracts 44 from its length, then each other snippet adds 1 to the length of the file without changing the logic of the program as a whole. thus increasing the result of the output by 1.

R, score: 79
Credit to Sean's Perl answer for the inspiration; this abuses some quirks of the R interpreter.
First snippet:
nchar(scan(,""))
a

subsequent snippets are the characters in:
bdefgijklmopqtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`~!@$%^&*_+|\[]{}:?><;

Try it online!
The scan function reads data from the file "" which defaults to stdin().
The docs for stdin() indicate that:

When R is reading a script from a file, the file is the ‘console’: this is traditional usage to allow in-line data (see ‘An Introduction to R’ for an example).

Hence, the subsequent data become the file. This can be trivially expanded, and can work with multiple different encodings.

Pyke, 256 bytes, score 254
Please note that these are hex codes of the actual bytes, separated by spaces, since there the null byte (\x00) is included.
Starting snippet:
6C 22 00

Subsequent 1-char snippets:
01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF

Try it here!

Java 8, 7 snippets (19 bytes)
1
*2
-~0
>4?4:4
|5
^3
7%7

Just a start, will continue working on it.
Try it here.
Explanation:
Execution precedence is perhaps made clearer when I add parenthesis:
((1*2)-~0)>4?4:4|(5^(37%7))

a*b: Multiply a with b
~a: -a-1
a>b?x:y: if(a>b){ x }else{ y }
a|b: Bitwise-OR a with b
a^b: Bitwise-XOR a with b
a%b: a modulo-b

TeX, score 61 (possibly 190)
First snippet:
\def\len#1{\expandafter\glen\string#1=}
\def\glen#1{\tlen}
\def\tlen#1{\if#1=\let\tlen\end\number\count1\else\advance\count1by1\fi\tlen}
\count1=-1
\catcode33=11
\catcode34=11
\catcode36=11
\catcode37=11
\catcode'46=11
\catcode40=11
\catcode41=11
\catcode42=11
\catcode43=11
\catcode44=11
\catcode45=11
\catcode46=11
\catcode47=11
\catcode56=11
\catcode57=11
\catcode'72=11
\catcode'73=11
\catcode60=11
\catcode62=11
\catcode63=11
\catcode64=11
\catcode'133=11
\catcode'135=11
\catcode'136=11
\catcode'137=11
\catcode'140=11
\catcode124=11
\catcode126=11
\len\t

Other 60 snippets: in any order, each containing one character out of
!"$%&()*+,-./:;<>?@[]^_`|~89ABCDEFGHIJKLMNOPQRSTUVWXYZhjkqwz

Explanation: \len, which is invoked at the end, converts a control sequence into a string, each character (including \) is one character token of that string; then \glen gobbles token \, then \tlen counts remaining tokens. It therefore outputs the length of that control sequence (not including \).
Characters from other snippets extend the control sequence which is initially just \t. A multi-character control sequence has to be made up of letters only, but they all count as letters because they have all been assigned category code 11 (using ASCII codes so that the characters themselves don't appear in the first snippet).
I decided to use octal codes for some characters which cost me one symbol, ' but saved me two digits, 8 and 9, so I gained one snippet. Possibly could have gained a couple more if I didn't need \expandafter.
Output
Possible alteration: wrap \number\count1 into \message{} so the output doesn't go into .dvi output but instead to console output and .log. It doesn't cost any extra letters.
190
Unfortunately TeX works with ASCII and not Unicode (or does it now?), but my solution could possibly be extended to include 129 more single-character snippets containing the characters with codes 127-255. Maybe even some characters before 32. Character 32 (space) didn't work, otherwise I'd put it into a snippet as well - didn't need it in the first snippet. Of course, each of these additional characters would have to be \catcoded into a letter in the first snippet.

Pyth, 124 snippets
l"x00x01x03x04x05x06x07x08
x0bx0c
x0ex0fx10x11x12x13x14x15x16x17x18x19x1ax1bx1cx1dx1ex1f !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijkmnopqrstuvwxyz{|}~x7f

Try it online!
Unprintable characters where escaped using three printable characters (x..). The first snippet is three bytes long, every snippet after that grows in length by one.

Beatnik, 22 bytes, score 20
K A
E
I
L
N
O
R
S
T
U
a
e
i
l
n
o
r
s
t
u

Assuming the word "snippet" allows you to push the value on the stack.

Octave, Score 86
nnz n

Followed by:
!$&()*+./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmopqrstuvwxy{|}~

This exploits the fact that Octave treats everything after a function name as a string input. So nnz n returns the number of non-zero elements in the string 'n'. We get to 86 by adding the other printable ASCII-characters. ',"%# doesn't work.

Julia 0.6, 111217
The following script creates the full program:
A = "macro length(a);length(string(a))end;@length a"
B0 = join(([Char(x) for x in Iterators.flatten((0x000001:0x00d7ff, 0x00e000:0x10ffff)) if Base.isvalid(Char(x)) && Char(x) ∉ A && Base.isidentifier("a$(Char(x))") ]));
B = normalize_string(B0, stripmark=true, decompose=true);
B = join(unique(b for b in B))
while (n = search(B, '·')) > 0
    B = B[1:prevind(B,n)]*B[nextind(B,n):end]
end
while (n = search(B, '`')) > 0
    B = B[1:prevind(B,n)]*B[nextind(B,n):end]
end

open("concount.jl", "w") do f
    write(f, A)
    write(f, B)
end

Explanation
The macro
 macro length(a);length(string(a))
 end
 @length a

followed by all distinct unicode characters allowed in identifiers, computed with isidentifier. Some diacritial marks mess up counting so I removed them.

APL (Dyalog), score  12
+1 score thanks to @dzaima
First to third snippets:
(~⍴⍬)
+≢'a'
,⍕1

Then each of 234567890.
Try it online!

Pip, 57 bytes, score = 16
!u
2
RT9
#m
5
(EX3Y8)
7
y
A'<tab>
t
11
+o
-v
PI@`\...`@`..$`
"F"FB:4*4
Ok=k6

Note that <tab> represents a literal tab character (ASCII 9). Try it online!
Each snippet is a full program that outputs the desired number. Most of them work on the principle that the last expression in a Pip program is autoprinted: for example, in snippet 5, the previous code is evaluated, but the only part that matters is the 5. Exceptions to this are:

Snippet 3 works fine in isolation as RT9 (square root of 9), but coming after snippet 2 it actually parses as 2RT9 (2nd root of 9)--which, of course, amounts to the same thing.
Snippet 6 gets the 8th character (0-indexed) of e^3, which happens to be 6. But it also yanks the number 8 into the y variable. Snippet 8 then outputs the value of y.
Snippet 12 takes the 11 from the previous snippet and adds o (preinitialized to 1). Snippet 13 takes that result and subtracts v (preinitialized to -1).
Snippet 16 outputs 1 without a newline (Ok=k, where k=k evaluates to the default truthy value of 1), and then autoprints 6.

Other interesting stuff:

Snippet 14 uses regex operations to extract 14 from the value of pi.
Snippet 15 converts the string "F" from hexadecimal.

Zsh, score >50 000 (1 112 046?), 16 + Σ(UTF-8 codepoint lengths) bytes
exec echo   $((${#:-$(<$0)}-33))
#

Zsh handles multibyte encodings by default. The base snippet has 18 unique characters, 34 total. Every other codepoint (save for the null byte) can be added onto this. As I write this, my script testing these is on codepoint ~50 000, total file size 150K, going at about 30 snippets/second. Run my full test script yourself here. You may want to adjust it to start at some later codepoints.
Try the first 2000 snippets online!
More snippets are possible by using this technique.

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


text:
Convert RGB color to websafe
Web safe colors are in intervals of 51, they include 0, 3, 6, 9, c, and, f as digits in hex (such as #993333), or 0, 51, 102, 153, 204, 255 in decimal. Your task today is convert a given color to a web safe one. You may read more about web safe colors on Wikipedia.
Input
You will take in 3 integers between 0, 255 inclusive representing red, green, and blue values.
Output
Output the converted 3 integers, as an array or similar structure.
Rules

answers must be rounded to the nearest value, not floor or ceiling. (25 -> 0 and 26 -> 51)
As this is code golf, lowest bytes wins.

Test Cases
Input            Output
(0, 25, 76)      (0, 0, 51)
(1, 26, 77)      (0, 51, 102)
(127, 178, 229)  (102, 153, 204)
(128, 179, 230)  (153, 204, 255)
(0, 254, 255)    (0, 255, 255)
(9, 143, 53)     (0, 153, 51)

I'm sure these answers will be pretty short; this is an easier question meant for those more novice at code golf, however feel free to answer regardless of your skill/experience.

Do you want output as the hex form, or RGB form? And which form is the input?

Could you please clarify your explanation and add some input/output examples? For future reference, the Sandbox is a very good place to receive feedback on challenges before posting them on the main site

Also, how do we round? Just floor? Half up?

I had made some edit. Hopes you don't mind.

Japt, 4 bytes
mr51

Try it online!
Input and output is a 3-item array.
Just maps each item rounded to the nearest multiple of 51.

Python 2, 33 bytes
lambda c:[(n+25)/51*51for n in c]

Try it online!

Taxi, 1015 bytes
Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Tom's Trims.Pickup a passenger going to Tom's Trims.Pickup a passenger going to Tom's Trims.[a]Go to Tom's Trims:n.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to Divide and Conquer.51 is waiting at Starchild Numerology.51 is waiting at Starchild Numerology.Go to Starchild Numerology:n 1 l 1 l 1 l 2 l.Pickup a passenger going to Divide and Conquer.Pickup a passenger going to Multiplication Station.Go to Divide and Conquer:w 1 r 3 r 1 r 2 r 1 r.Pickup a passenger going to Rounders Pub.Go to Rounders Pub:e 1 r 1 r 1 l.Pickup a passenger going to Multiplication Station.Go to Multiplication Station:n 1 r 1 r 1 l 1 r.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 r 1 l.Pickup a passenger going to Post Office.' ' is waiting at Writer's Depot.Go to Writer's Depot:n 1 l 1 l 2 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.Switch to plan "a".

Try it online!
Un-golfed:
Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to Tom's Trims.
Pickup a passenger going to Tom's Trims.
Pickup a passenger going to Tom's Trims.
[a]
Go to Tom's Trims: north.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: south 1st left 1st right.
Pickup a passenger going to Divide and Conquer.
51 is waiting at Starchild Numerology.
51 is waiting at Starchild Numerology.
Go to Starchild Numerology: north 1st left 1st left 1st left 2nd left.
Pickup a passenger going to Divide and Conquer.
Pickup a passenger going to Multiplication Station.
Go to Divide and Conquer: west 1st right 3rd right 1st right 2nd right 1st right.
Pickup a passenger going to Rounders Pub.
Go to Rounders Pub: east 1st right 1st right 1st left.
Pickup a passenger going to Multiplication Station.
Go to Multiplication Station: north 1st right 1st right 1st left 1st right.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: south 1st right 1st left.
Pickup a passenger going to Post Office.
' ' is waiting at Writer's Depot.
Go to Writer's Depot: north 1st left 1st left 2nd left.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st right 2nd right 1st left.
Switch to plan "a".

You can't detect if someone is waiting at Post Office so you start by picking up the three passengers and moving them. Divide each by 51, round, multiply by 51, and output.

Javascript (ES6), 28 27 bytes
-1 byte thanks to @Arnauld
a=>a.map(n=>51*(0|.5+n/51))

Takes input as an array ([red, green, blue]) and returns the output in the same format.

f=a=>a.map(n=>51*(0|.5+n/51))

<input id=r type=number value=0 /><input id=g type=number value=0 /><input id=b type=number value=0 />

(n*5+130>>8)*51 would also work. But it's (now) 1 byte longer and I can't figure out a way to golf it some more.

MATLAB/Octave, 18 13 bytes
@(x)51*(x/51)

Try it online!
Takes an array of type uint8 with three values (R,G,B), and returns a uint8 array of web-safe (R,G,B). MATLAB/Octave use uint8 types to represent colours in images, so it's not really cheating to expect the same.

Excel VBA, 26 Bytes
Anonymous VBE immediate window function that takes input as integers from range [A1:C1] and outputs the corresponding safeview values to range [A2:C2].
[A2:C2]="=51*INT(.5+A1/51)

Sample Output

Jelly, 9 8 bytes
Byte saved thanks to Dennis
51Ɠ÷+.Ḟ×

Try it online!

I forgot to specify earlier that it must be rounded to the nearest, not floor or ceiling. I updated the question description and I'm sorry I didn't mention this earlier.

Perl 5, 23 18 + 1 (-n) = 19 bytes
say 51*int$_/51+.5

Try it online!
-4 bytes thanks to @Dennis

Python 2, 37 36 33 bytes
lambda c:[(n+25)/51*51for n in c]

Try it online!
Python 3, 36 35 34 bytes
lambda c:[(n+25)//51*51for n in c]

Try it online!

For both Python 2 and Python 3 there's a round builtin that can save you 1 byte.

@EriktheOutgolfer Thanks, for some reason my round-version was longer...

You can save more bytes by changing your math a bit Try it online!

Mathematica, 24 bytes
Nearest[51Range[0,5],#]&

Try it online!
-2 bytes from @MishaLavrov

Nearest[51Range[0,5],#]& saves two bytes. Also, I think adding Tr/@ at the beginning would be neater, returning output like {153, 204, 255} instead of {{153}, {204}, {255}}.

@MishaLavrov "output as an array or similar structure". why waste 4 bytes? this is code-golf

I guess that's fair.

@NoOneIsHere No,because it doesn't work. You should have checked this yourself in TIO link

Retina, 53 bytes

 25;
\d+
$*
;

1{51}
a
1

a
51,
51,
$*
(?<= )1*
$.&

Try it online!
Every number in the input has a leading space

C++, 67 bytes
-3 bytes thanks to Zacharý and ceilingcat
#define R(t)t=(t+25)/51*51;
void s(int&r,int&g,int&b){R(r)R(g)R(b)}

Return by parameters
Code to test ( include required : iostream, vector and tuple ) :
std::vector<std::pair<tuple3int, tuple3int>> testList{
    { { 0,25,76 },{ 0,0,51 } },
    { { 1,26,77 },{ 0,51,102 } },
    { { 127,178,229 },{ 102,153,204 } },
    { { 128,179,230 },{ 153,204,255 } },
    { { 0,254,255 },{ 0,255,255 } },
    { { 9,143,53 },{ 0,153,51 } }
};

for (auto& a : testList) {
    s(std::get<0>(a.first), std::get<1>(a.first), std::get<2>(a.first));
    if (a.first != a.second)
        std::cout << "Error\n";
}

I also think it might be possibe to change t=((t+25)/51)*51 to t=(t+25)/51*51, in addition to removing the space between R(t) and t as @ceilingcat said.

PHP, 42 bytes
while($k++<3)echo($argv[$k]/51+.5|0)*51,_;

Run with -nr or try it online.

Batch, 50 bytes
@for %%i in (%*)do @cmd/cset/a(%%i+25)/51*51&echo(

Takes input as command-line parameters.

Kotlin, 111 bytes
fun w(r:Int,g:Int,b:Int):Array<Int>(){return arrayOf(Math.rint(r/51)*51,Math.rint(g/51)*51,Math.rint(b/51)*51)}

Welcome to PPCG! As it seems, the code provided is 117 bytes long. We usually need the fully golfed code (i.e. all unnecessary whitespace removed). In case you haven't heard, there is an online environment to execute various programming languages, called Try it online! You may find it beneficial to add this to your answer.

@ConorO'Brien Looks like the whitespace chars were not counted; they're 6 bytes in total here. However, I'd highly recommend adding a notice such as "spaced added for clarity; not counted" if that's the case indeed.

Edited. 2 whitespace characters are necessary for the keywords

This looks like it's only 111 bytes long. The 6 bytes I was referring to were the unnecessary ones.

q/kdb+, 11 bytes
Solution:
51 xbar 25+

Example:
/ apply across test cases and then cut into chunks of 3
q)3 cut 51 xbar 25+0 25 76 1 26 77 127 178 229 128 179 230 0 254 255 9 143 53
0   0   51
0   51  102
102 153 204
153 204 255
0   255 255
0   153 51

Explanation:
Nice and easy using xbar built-in. Q is interpreted right-to-left:
51 xbar 25+ / the solution
        25+ / vectorised add (add 25 to each item on the right)
51 xbar     / round down to nearest multiple of 51

C# (.NET Core), 28 bytes
a=>a.Select(n=>(n+25)/51*51)

Try it online!
Same solution as others. I didnt count headers (system and linq). You can if you want. :)

Funky, 33 bytes
l=>l::map(z=>math.round(z/51)*51)

Try it online!