(x=scan())%in%(2*4^(n=0:x)-2^n-1)
This article is originally published at https://xianblog.wordpress.com
One challenge on code golf is to find the shortest possible code to identify whether or not an integer belongs to the binary cyclops numbers which binary expansion is 0, 101, 11011, 1110111, 111101111, &tc. The n-th such number being
this leads to the above solution in R (26 bits). The same length as the C solution [which I do not get]
f(n){n=~n==(n^=-~n)*~n/2;}
And with shorter versions in many esoteric languages I had never heard of, like the 8 bits Brachylog code
ḃDDḍ×ᵐ≠
or the 7 bits Jelly
B¬ŒḂ⁼SƊ
As a side remark, since this was not the purpose of the game, the R code is most inefficient in creating a set of size (x+1), with most terms being Inf.
Thanks for visiting r-craft.org
This article is originally published at https://xianblog.wordpress.com
Please visit source website for post related comments.