05AB1E, n=13, 189 bytes
'Ì6×ÐI" ÿB`0¢ "D"₁h44₁44÷÷÷ÝÐÃм₁hhhÐÃ44u4÷÷÷₁h44₁44÷÷÷ǝ÷ƶê4₁÷÷ 1 Èÿ°À4ô¤¬ xÒÍÍ<_Zÿ11*Ò88w8*н¡Ë18*Ë xh`H°` ₂6₂6₂6$--«üuÆ-«üuÆ-«üuÆΘ ÒæP<<<<<<<<<<n(Zd XXšXXÜýвXšXš¥Æ≠≠ ÿÿð¨и0Ì<0ǝÀ0ÿäÀ`∍`Ā"#Iè
Try it online! or validate codepoint divisibility.
n=1: 1 simply returns 1, since all integers are divisible by 1.
n=2: È is the built-in for that, and its codepoint is even.
n=3 TIO:
3B # convert input to base 3
` # get the last digit
0¢ # count occurences of 0 in that digit
n=4 TIO:
° # 10**input
À # rotate left
4ô # split in chunks of 4 digits
¤ # get the last chunk
¬ # get the first digit of that chunk
n=5 TIO:
x # double the input
Ò # prime factorization
ÍÍ< # subtract 5 from each prime
_ # equal to 0?
Z # maximum
n=6 works identically to n=3.
n=7 TIO:
11* # multiply the input by 11
Ò # prime factorization
88w8*н # first digit of 88*8, namely 7
¡ # split the prime factorization on 7
Ë # are all sublists equal?
18* # multiply by 18
Ë # are all digits equal?
n=8 TIO:
x # double the input
h # convert to hex
` # get the last digit
H # convert from hex
° # 10**x
` # get the last digit
n=9 TIO:
₂ # push 26
6 # push 6
$ # push 1 and input
- # subtract: 1 - input
- # subtract: 6 - (1 - input) = 5 + input
« # concatenate: "26" + (5 + input)
üu # for each pair of digit, uppercase the second one
# (used to convert to a list of digits, but drops the first digit)
Æ # reduce by subtraction: 6 - sum(digits(5 + input))
# the above sequence is repeated twice, yielding 6 - sum(digits(sum(digits(sum(digits(5 + input))))))
Θ # is it equal to 1?
Note that this algorithm doesn’t work for arbitrary large numbers (but it still works up to 10^10000000000, which is good enough).
n=10 TIO:
Ò # prime factorization of the input
æ # power set
P # product of each subset
<<<<<<<<<< # subtract 10 from each
n # square each
( # negate each
Z # maximum
d # is it >= 0?
Divisibility by 10 is usually the easiest, but unfortunately there’s no compliant way to get the last digit.
n=11 TIO:
X # push 1
Xš # prepend 1: [1, 1]
XXÜ # 1, with trailing 1s trimmed off (aka empty string)
ý # join: 11
в # convert input to base 11
Xš # prepend 1
Xš # prepend 1
¥ # deltas
Æ # reduce by subtraction
≠≠ # is it equal to 1?
n=12 TIO:
ÌÌÌÌÌÌÌÌÌÌÌÌ # add 24 to the input
ð # space character
¨ # drop the last character (empty string)
и # make a list of input empty strings
0Ì<0ǝ # replace the first element with 1
À # rotate left
0ÌÌÌÌÌÌä # split in 12 parts of approximately equal length
# (if the input isn’t divisible by 12, the first sublists will be longer)
À # rotate left
` # dump all to the stack
∍ # cycle the before-last sublist to match the length of the last sublist
` # get the last element
Ā # truthify
n=13 ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]): TIO
₁h44₁44÷÷÷ # hex(256) / (44 / (256 / 44)) = 12
Ý # range [0..12]
ÐÃ # duplicate (well, triplicate then pop the third copy)
м # remove (leaves a list of 13 empty strings)
₁hhhÐÃ44u4÷÷÷ # 13
₁h44₁44÷÷÷ # 12
ǝ # set the element at index 12 to 13
÷ # integer division
# dividing by the empty string yields the numerator,
# so the result is 12x the input, followed by input / 13
ƶ # multiply each element by its index
# the last element is now equal to input iff 13 divides input
ê # sorted uniquify
4₁÷÷ # divide by 0 (sets all elements to 0)
6Sandbox. It was pointed out that Lenguage is able to get an infinitely high score, so I would appreciate people avoiding trying to play that "loophole" - it's not original, nor especially funny, in my opinion. – caird coinheringaahing – 2019-12-01T22:43:45.033
4
>>> ''.join(chr(i) for i in range(32,127,2))' "$&(*,.02468:<>@BDFHJLNPRTVXZ\\^bdfhjlnprtvxz|~'so I can't evenprint-- why don't I like [restricted-source`](https://codegolf.stackexchange.com/questions/tagged/restricted-source)? ) – Alexey Burdin – 2019-12-01T23:38:59.9533In what form can the output be -- two distinct values for yes/no? Truthy/falsy? Does this have to be consistent between programs? – Doorknob – 2019-12-02T03:22:45.833
1@Doorknob Two distinct values for yes/no. They must be consistent when run with the same
xandnbut can be different values for differentn– caird coinheringaahing – 2019-12-02T07:38:19.933Should the 2nd program work independently of the 1st, or may we assume it will only be run after the first? For example, if program 1 loads a library, may we use that library in program 2 without loading it again? – Robin Ryder – 2019-12-02T07:53:24.633
@RobinRyder No, the two programs must be (aside from
n) independent – caird coinheringaahing – 2019-12-02T07:55:34.0333I would suggest allowing us to simply list the various 2nd programs for different values of
n, since that it is where the crux of the challenge lies. Otherwise, the 1st program will probably often look likeif n==1 cat(program for n=1) else if n==2 cat(program for n=2) else if n==3...– Robin Ryder – 2019-12-02T08:50:21.503Can we assume an upper bound on
x? Would 2^32 be fine? – Grimmy – 2019-12-02T17:49:22.467@Grimmy Any reasonable upper bound is fine, given language constraints – caird coinheringaahing – 2019-12-02T17:50:15.447
It's not a language constraint, 05AB1E has big integer arithmetic, but I still can't get n=9 if I need to handle arbitrarily large integers (see bottom of my answer). – Grimmy – 2019-12-02T17:51:45.300
1@Grimmy In that case, yeah, restricting the input size (to a reasonable value) is perfectly acceptable – caird coinheringaahing – 2019-12-02T17:53:01.057
1Do all the programs have to use the same type of input method? That is, can program A input a number, B uses an array of digits, and C uses a string? – Embodiment of Ignorance – 2019-12-03T05:17:50.003
@EmbodimentofIgnorance No, you may mix and match accepted methods – caird coinheringaahing – 2019-12-03T08:25:23.800