Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I asked random.org for 128 random integers between 0 and 232 - 1. Since the random number generator was so eager to give the first 64 numbers first, they're obviously more random than the other 64.

Write a full program or function that returns a truthy result when one of the following 64 integers is input:

[1386551069, 1721125688, 871749537, 3410748801, 2935589455, 1885865030, 776296760, 614705581, 3841106923, 434616334, 1891651756, 1128215653, 256582433, 310780133, 3971028567, 2349690078, 489992769, 493183796, 3073937100, 3968540100, 777207799, 515453341, 487926468, 2597442171, 950819523, 1881247391, 3676486536, 3852572850, 3498953201, 2544525180, 297297258, 3783570310, 2485456860, 2866433205, 2638825384, 2405115019, 2734986756, 3237895121, 1560255677, 4228599165, 3106247743, 742719206, 2409129909, 3008020402, 328113612, 1081997633, 1583987616, 1029888552, 1375524867, 3913611859, 3488464791, 732377595, 431649729, 2105108903, 1454214821, 997975981, 1764756211, 2921737100, 754705833, 1823274447, 450215579, 976175934, 1991260870, 710069849]

And a falsey result for the other 64 numbers:

[28051484, 408224582, 1157838297, 3470985950, 1310525292, 2739928315, 3565721638, 3568607641, 3857889210, 682782262, 2845913801, 2625196544, 1036650602, 3890793110, 4276552453, 2017874229, 3935199786, 1136100076, 2406566087, 496970764, 2945538435, 2830207175, 4028712507, 2557754740, 572724662, 2854602512, 736902285, 3612716287, 2528051536, 3801506272, 164986382, 1757334153, 979200654, 1377646057, 1003603763, 4217274922, 3804763169, 2502416106, 698611315, 3586620445, 2343814657, 3220493083, 3505829324, 4268209107, 1798630324, 1932820146, 2356679271, 1883645842, 2495921085, 2912113431, 1519642783, 924263219, 3506109843, 2916121049, 4060307069, 1470129930, 4014068841, 1755190161, 311339709, 473039620, 2530217749, 1297591604, 3269125607, 2834128510]

Any input other than one of these 128 numbers is undefined behavior.

If your solution is found programmatically, please also share the code used to generate it!

This is , so the shortest solution in bytes wins.

share|improve this question
14  
Since the random number generator gave the first 64 numbers first, they must be more random ಠ___ಠ – Luis Mendo Mar 5 at 16:30
    
You can distinguish the two sets modulo 834 – CalculatorFeline Mar 5 at 17:33
1  
Those numbers are not random. – CalculatorFeline Mar 5 at 18:37
    
"Maybe, not enough information."& 33 bytes, answers the question. – CalculatorFeline Mar 5 at 19:10
2  
@CatsAreFluffy Actually, as long as the input doesn't contain 0 or 1 and no two elements differ by 1, you can separate them by a modulo chain. e.g. separating [4 20 79] from [8 18 100] can be done by [99 79 20 17 7 4] (see if you can spot the pattern). Sure, the initial half of your answer might use a much smaller modulo than the input, but the back half consists of shifting one element at a time. – Sp3000 Mar 5 at 20:22

CJam, 53 52 47 bytes

l~"X    0'ò"2/Dfb+:%"gÇâì6Ô¡÷Ç8nèS¡a"312b2b=

There's unprintables, but the two strings can be obtained by

[88 9 48 5 39 5 29 1 242]:c
[8 103 199 226 236 54 212 15 161 247 199 56 110 232 83 161 97]:c

respectively. This also shows that the code points are below 256.

This is a modulo chain answer, where we apply the following modulos to the input integer, in order:

[1153 629 512 378 242 136]

Since this list contains integers greater than 255, the list is encoded using two chars each. The decoding is done by 2/Dfb, which splits the string into chunks of length two and converts each from a base 13 number (e.g. 88*13 + 9 = 1153). However, there are two exceptions to the decoding:

  • The last number (136) is not included (see below),
  • The second-last number is represented by a single char, since the number (242) is less than 256 and splitting an odd-length array into chunks of size 2 will leave a size 1 array at the end. Thanks to @MartinBüttner for this tip!

Once the modulos have reduced the input integer to a relatively small number, we perform a lookup from a table. This table is encoded via the second string, which is converted to a base 312 number then decoded to base 2, which we index. Since CJam's array indexing wraps, we can leave out the final modulo as mentioned earlier.

Try it online | Test suite

share|improve this answer
    
How do you people come up with the magic moduli? – CalculatorFeline Mar 5 at 17:56
    
@CatsAreFluffy Just a simple DFS with a limit on the number of modulos. My current implementation is quite slow, so if I feel like the program's stuck for a while I try a different initial starting point. – Sp3000 Mar 5 at 18:02
    
What's a DFS? (Wikipedia doesn't help.) – CalculatorFeline Mar 5 at 18:13
    
@CatsAreFluffy Depth-first search – Sp3000 Mar 5 at 18:14
    
Ah. I just used a greedy algorithm. – CalculatorFeline Mar 5 at 18:18

Retina, 117 bytes

([023]3|[067]0|[1289]1|5[5689]|67|96|88|77|65|05)$|^(8|4[358]|7[147]|51|37|30)|865|349|2.{5}5|761|74[348]|728|811|990

A regex golf answer, outputting a positive integer for truthy and zero for falsy.

Try it online! | Test suite - truthy | Test suite - falsy | Regex101

share|improve this answer

JavaScript (ES6) 233

An anonymous function returning 0 as falsy and nonzero as truthy

x=>~"lnhp2wm8x6m9vbjmrqqew9v192jc3ynu4krpg9t3hhx930gu8u9n1w51ol509djycdyh077fd1fnrzv6008ipkh0704161jayscm0l6p4ymj9acbv5ozhjzxo3j1t20j9beam30yptco033c9s3a8jwnre63r29sfbvc5371ulvyrwyqx3kfokbu66mpy9eh" // newline added for readability
.search((x.toString(36)).slice(-3))

Checking the last 3 digits in the number representation in base 36.

The check string is built so:

a=[1386551069, 1721125688, ... ]
H=x=>(x.toString(36)).slice(-3)
Q=a.map(x=>H(x)).join('')

Test

f=x=>~"lnhp2wm8x6m9vbjmrqqew9v192jc3ynu4krpg9t3hhx930gu8u9n1w51ol509djycdyh077fd1fnrzv6008ipkh0704161jayscm0l6p4ymj9acbv5ozhjzxo3j1t20j9beam30yptco033c9s3a8jwnre63r29sfbvc5371ulvyrwyqx3kfokbu66mpy9eh"
.search((x.toString(36)).slice(-3))

a=[1386551069, 1721125688, 871749537, 3410748801, 2935589455, 1885865030, 776296760, 614705581, 3841106923, 434616334, 1891651756, 1128215653, 256582433, 310780133, 3971028567, 2349690078, 489992769, 493183796, 3073937100, 3968540100, 777207799, 515453341, 487926468, 2597442171, 950819523, 1881247391, 3676486536, 3852572850, 3498953201, 2544525180, 297297258, 3783570310, 2485456860, 2866433205, 2638825384, 2405115019, 2734986756, 3237895121, 1560255677, 4228599165, 3106247743, 742719206, 2409129909, 3008020402, 328113612, 1081997633, 1583987616, 1029888552, 1375524867, 3913611859, 3488464791, 732377595, 431649729, 2105108903, 1454214821, 997975981, 1764756211, 2921737100, 754705833, 1823274447, 450215579, 976175934, 1991260870, 710069849]
b=[28051484, 408224582, 1157838297, 3470985950, 1310525292, 2739928315, 3565721638, 3568607641, 3857889210, 682782262, 2845913801, 2625196544, 1036650602, 3890793110, 4276552453, 2017874229, 3935199786, 1136100076, 2406566087, 496970764, 2945538435, 2830207175, 4028712507, 2557754740, 572724662, 2854602512, 736902285, 3612716287, 2528051536, 3801506272, 164986382, 1757334153, 979200654, 1377646057, 1003603763, 4217274922, 3804763169, 2502416106, 698611315, 3586620445, 2343814657, 3220493083, 3505829324, 4268209107, 1798630324, 1932820146, 2356679271, 1883645842, 2495921085, 2912113431, 1519642783, 924263219, 3506109843, 2916121049, 4060307069, 1470129930, 4014068841, 1755190161, 311339709, 473039620, 2530217749, 1297591604, 3269125607, 2834128510]

A.textContent=a.map(x=>f(x))
B.textContent=b.map(x=>f(x))
<table>
  <tr><th>first 64 - truthy</th></tr><tr><td id=A></td></tr>
  <tr><th>other 64 - falsy</th></tr><tr><td id=B></td></tr>
</table>  

share|improve this answer

Mathematica, 218 217 bytes

Fold[Mod,#,{834,551,418,266,228,216,215,209,205,199,198,195,178,171,166,162,154,151,146,144,139,137,122,120,117,114,110,106,101,98,95,88,84,67,63,61,60,57,55,51,45,44,43,41,40,35,34,30,27,26,25,23,20,14,13,11,10,9}]<1

For whatever reason, a set of moduli exists that allows us to distinguish two sets just by whether or not, after applying the moduli, the result is zero or not. The long list of moduli was generated by this program:

Block[{data1, data2, n, mods}, 
 data1 = {1386551069, 1721125688, 871749537, 3410748801, 2935589455, 
   1885865030, 776296760, 614705581, 3841106923, 434616334, 
   1891651756, 1128215653, 256582433, 310780133, 3971028567, 
   2349690078, 489992769, 493183796, 3073937100, 3968540100, 
   777207799, 515453341, 487926468, 2597442171, 950819523, 1881247391,
    3676486536, 3852572850, 3498953201, 2544525180, 297297258, 
   3783570310, 2485456860, 2866433205, 2638825384, 2405115019, 
   2734986756, 3237895121, 1560255677, 4228599165, 3106247743, 
   742719206, 2409129909, 3008020402, 328113612, 1081997633, 
   1583987616, 1029888552, 1375524867, 3913611859, 3488464791, 
   732377595, 431649729, 2105108903, 1454214821, 997975981, 
   1764756211, 2921737100, 754705833, 1823274447, 450215579, 
   976175934, 1991260870, 710069849};
 data2 = {28051484, 408224582, 1157838297, 3470985950, 1310525292, 
   2739928315, 3565721638, 3568607641, 3857889210, 682782262, 
   2845913801, 2625196544, 1036650602, 3890793110, 4276552453, 
   2017874229, 3935199786, 1136100076, 2406566087, 496970764, 
   2945538435, 2830207175, 4028712507, 2557754740, 572724662, 
   2854602512, 736902285, 3612716287, 2528051536, 3801506272, 
   164986382, 1757334153, 979200654, 1377646057, 1003603763, 
   4217274922, 3804763169, 2502416106, 698611315, 3586620445, 
   2343814657, 3220493083, 3505829324, 4268209107, 1798630324, 
   1932820146, 2356679271, 1883645842, 2495921085, 2912113431, 
   1519642783, 924263219, 3506109843, 2916121049, 4060307069, 
   1470129930, 4014068841, 1755190161, 311339709, 473039620, 
   2530217749, 1297591604, 3269125607, 2834128510};
 n = 1;
 mods = {};
 While[Intersection[Mod[data1, n], Mod[data2, n]] != {}, n++];
 FixedPoint[
  (mods = Append[mods, n]; data1 = Mod[data1, n]; 
    data2 = Mod[data2, n]; n = 1;
    While[Intersection[Mod[data1, n], Mod[data2, n]] != {}, n++]; 
    n) &
  , n];
 {mods, {Fold[Mod, data1, mods], Fold[Mod, data2, mods]}}
 ]

First output is the moduli, second and third outputs are the two lists, having applied the moduli. The two long lists are the sets.

share|improve this answer
1  
You can probably compress a part of the list into a string. – njpipeorgan Mar 6 at 1:25

PowerShell, v3+ 194 bytes

$args[0]%834%653-in(40..45+4,8,12,51,60,64,69,76,84,86,93,97,103,117+137..149+160,162,178+195..209+215..227+255,263+300..329+354,361,386,398,417,443,444+469..506+516,519,535,565,581,586,606,618)

A little bit of a different approach, so I figured I would post it. It's not going to win shortest, but it may give someone else ideas to shorten their code.

We're still taking the input integer $args[0] and applying modulo operations to it, so nothing different there. In the above, we're using the -in operator (hence v3+ requirement) so this will output True for values that are in the truthy test case.

However, I'm attempting to find resultant arrays where we can leverage the .. range function to shorten the byte count, yet still have distinct arrays between the truthy and falsey values. We can do this since behavior other than the truthy/falsey input is undefined, so if the range catches values outside of the truthy/falsey input, it doesn't matter the output.

It's a pretty manual process so far, as the goal is to try and find the modulo where one of truthy or falsey arrays has large gap(s) between numbers and the other array has large amounts of numbers in that gap. I've mostly been going by intuition and gut feel so far, but I may eventually write a brute-forcer to solve this. The above is the shortest I've (mostly manually) found so far.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.