Skip to content

Instantly share code, notes, and snippets.

@kik

kik/ASCII-gen.rb Secret

Created February 16, 2014 14:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kik/21d3c6f7d6f16c2a9e6e to your computer and use it in GitHub Desktop.
Save kik/21d3c6f7d6f16c2a9e6e to your computer and use it in GitHub Desktop.
Time Limit Exceeded 2k14
x = $<.to_a.join('').gsub("\n", '')
print "char d[] = \""
i = 0
while i < 48 * 246
ch = x[i]
c = 0
while x[i] == ch
i += 1
c += 1
end
while c > 255
#print "255,0,"
printf "%c%c", 255, 0
c -= 255
end
#print "#{c},"
if c == 10
print '\n'
elsif c == 13
print '\r'
elsif c == 34
print '\"'
else
printf "%c", c
end
end
print "\";"
s = <<'E'
c;j;
main()
{
for(;j<11808;j++){
while(!d[c]--)c++;
putchar(c&1?49:64);
if(-~j%246==0)puts("");
}
return 0;
}
E
print s.gsub(/^ */, '').gsub("\n", '')
#include "stdio.h"
#include "errno.h"
#include "linux/acct.h"
#include "linux/if_eql.h"
#define struct /**/
#define __kernel_time_t /**/
/* r */
#undef _LINUX_UTIME_H
#undef HZ
#undef SIOCDEVPRIVATE
#undef utimbuf
#undef actime
#define HZ /**/
#define SIOCDEVPRIVATE "%lld", &n
#define utimbuf long long r AHZ
#define actime long long n, m = scanf EQL_ENSLAVE
#define modtime return n
#include "linux/utime.h"
/* go1 */
#undef _LINUX_UTIME_H
#undef HZ
#undef SIOCDEVPRIVATE
#undef utimbuf
#undef actime
#undef modtime
#define HZ /**/
#define SIOCDEVPRIVATE "%lld\n", n * -~n / 2
#define utimbuf go1 AHZ
#define actime long long n = r AHZ
#define modtime printf EQL_ENSLAVE
#include "linux/utime.h"
/* go */
#undef _LINUX_UTIME_H
#undef HZ
#undef SIOCDEVPRIVATE
#undef utimbuf
#undef actime
#undef modtime
#define HZ n
#define SIOCDEVPRIVATE /**/
#define utimbuf go AHZ
#define actime loop: --n, go1 EQL_ENSLAVE
#define modtime if AHZ goto loop
#include "linux/utime.h"
/* main */
#undef _LINUX_UTIME_H
#undef HZ
#undef SIOCDEVPRIVATE
#undef utimbuf
#undef actime
#undef modtime
#define HZ /**/
#define SIOCDEVPRIVATE r AHZ
#define utimbuf main AHZ
#define actime go EQL_ENSLAVE
#define modtime return 0
#include "linux/utime.h"
#undef _LINUX_UTIME_H
// ;
a;main(){a=!puts("Threads 2k14");}
void go(unsigned long long z)
{
if (z % 3 == 0 || z % 11 == 0 || z % 13 == 0 || z % 17 == 0 || z % 23 == 0) return;
unsigned long long w = z - 1;
unsigned long long s = 2;
unsigned long long t = 1;
// 2^(z-1) mod z
while (w) {
if (w & 1) {
t = (__uint128_t)t * s % z;
}
s = (__uint128_t)s * s % z;
w >>= 1;
}
if (t != 1) return;
// 3^(z-1) mod z
w = z - 1;
s = 3;
t = 1;
while (w) {
if (w & 1) {
t = (__uint128_t)t * s % z;
}
s = (__uint128_t)s * s % z;
w >>= 1;
}
if (t != 1) return;
printf("%llu\n", z);
}
void go1(int v)
{
//if (v % 3 == 0) return;
unsigned long long w = 0, z = v;
int j;
for (j = 0; j < 7; j++) {
w *= 10;
w += z % 10;
z /= 10;
}
for (j = 0; j < 10; j++) {
z = w * 100000000 + v + j * 10000000;
//printf("%lld %lld %lld %d\n", v, w, z, z < 1000000000000000);
go(z);
}
go(w * 10000000 + v);
}
void go2(int v)
{
//if (v % 3 == 0) return;
unsigned long long w = 0, z = v;
int j;
for (j = 0; j < 6; j++) {
w *= 10;
w += z % 10;
z /= 10;
}
for (j = 0; j < 10; j++) {
z = w * 10000000 + v + j * 1000000;
//printf("%lld %lld %lld %d\n", v, w, z, z < 1000000000000000);
go(z);
}
go(w * 1000000 + v);
}
void gox(int v)
{
go1(v);
if (v < 1000000) go2(v);
}
int main()
{
int i;
int v = 0;
for (i = 0; i < 1000000; i++, v += 10) {
gox(v + 1);
gox(v + 3);
gox(v + 7);
gox(v + 9);
}
return 0;
}
#define S(x)*p=#x;x
S(main(a){for(scanf("%d",&a);a;printf("#define S(x)*p=#x;x\nS(%s)\n",p))a--;})
_____, ______, _______, ________;
____________ = (('/')+('*'));
_____________ = (('-') + ('!'));
_________()
{
_______=(('_') - ('_'));
read((('_') - ('_')), &_______, (!(('_') - ('_')))) <= (('_') - ('_')) && (_______=-(!(('_') - ('_'))));
}
_()
{
_________(); _______ != (('*') - (' ')) && _();
}
__()
{
_______ == (('<') + ('%')) && (_____++, _________(), __());
}
___()
{
_______ == (('=') + ('%')) && (______++, _________(), ___());
}
____()
{
_____ = ______ = (('_') - ('_'));
__(); ___();
________ &= ((_____ & (!(('_') - ('_')))) && (______ == (!(('_') - ('_'))))) || (!(_____ & (!(('_') - ('_')))) && !(!_____ && ______));
_______ != (('*') - (' ')) && ____();
}
__________()
{
________ = (!(('_') - ('_')));
____();
puts(________ ? &____________ : &_____________);
___________();
}
___________()
{
_________();
_______ < (('_') - ('_')) ? (('_') - ('_')) : __________();
}
main()
{
_();
___________();
}
X = <<'EOF'
a[123456];is[123456];ks[123456];lt[123456];gt[123456];n,i,j,k,v;
main()
{
long long sum=0;
scanf("%d",&n);
for(;i<n;i++)scanf("%d",&a[i]);
for(;j<n;j++){
for(v=a[j];v;v-=v&-v)is[j] += lt[v];
for(v=a[j]+1;v<123456;v+=v&-v)lt[v]++;
}
for(j=n-1;j>=0;j--){
for(v=a[j];v<123456;v+=v&-v)ks[j] += gt[v];
for(v=a[j]-1;v;v-=v&-v)gt[v]++;
}
for(j=0;j<n;j++)sum+=(long long)is[j]*ks[j];
printf("%lld\n",sum);
return 0;
}
EOF
CHRS = []
128.times {|i|
if (i != 0 && i != 9 && i != 10 && i != 11 && i != 12 && i != 13 && i != 32 && i != 34)
CHRS << i
end
}
print "*X=\""
CHRS.each {|ch|
n = 413
n += 42 if ch == 40
n.times {|j|
printf "%c", ch
}
}
print "\";"
print X.gsub(/^\s*/, '').gsub("\n", '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment