C ++ Template-Metaprogramming, 160 154 116 byte
Hanya untuk cekikikan.
Terima kasih kepada mantan bart untuk bermain golf!
template<int w,int x,int y,int...s>class A:A<w+(x==y),x,s...>{};A<0,'t','t','t','t','g','g','l','o','y','o','i',0>a;
Penggunaan: Karakter pertama di instanciation template adalah karakter untuk dicari.
Complile dengan dentang -std = c ++ 11 -c -> hasilnya ada di awal pesan kesalahan.
Occurences.cpp:1:66: error: too few template arguments for class template 'A'
template<int w,char x,char y,char...s>class A{static const int a=A<w+((x==y)?1:0),x,s...>::a;};
^
Occurences.cpp:1:66: note: in instantiation of template class 'A<3, 't', '\x00'>' requested here
template<int w,char x,char y,char...s>class A{static const int a=A<w+((x==y)?1:0),x,s...>::a;};
Complile dengan gcc -std = c ++ 11 -c -> hasilnya ada di bagian bawah pesan kesalahan.
Occurences.cpp: In instantiation of ‘const int A<3, 't', '\000'>::a’:
Occurences.cpp:1:64: recursively required from ‘const int A<1, 't', 't', 't', 'g', 'g', 'l', 'o', 'y', 'o', 'i', '\000'>::a’
Occurences.cpp:1:64: required from ‘const int A<0, 't', 't', 't', 't', 'g', 'g', 'l', 'o', 'y', 'o', 'i', '\000'>::a’
Occurences.cpp:2:62: required from here
Occurences.cpp:1:64: error: wrong number of template arguments (2, should be at least 3)
Cari A < 3 , 't', '\ 000'> dan A < 3 , 't', '\ x00'>
Versi 154 byte
template<int w,char x,char y,char...s>class A{static const int a=A<w+(x==y),x,s...>::a;};
int a=A<0,'t','t','t','t','g','g','l','o','y','o','i','\0'>::a;
Versi 160 byte:
template<int w,char x,char y,char...s>class A{static const int a=A<w+((x==y)?1:0),x,s...>::a;};
int a=A<0,'t','t','t','t','g','g','l','o','y','o','i','\0'>::a;