На топкодере регулярно проходит shortest code competition по задачам срмов (обычно простым). Иногда довольно интересно посмотреть, как можно сжать код, казалось бы простой задачи, до совершенно непонятного, но в то же время работающего. Предлагаю проводить такие соревнования и здесь, на Codeforces.
Я начну с задачи C из Codeforces Beta Round #24. Правила простые: каждый следующий код должен быть короче предыдущего. Побеждает тот, кого никто не смог перебить. Длина кода - количество символов в нем, не считая пустых (пробелов, табов, переводов строки и т.д.). Само собой, код должен быть АС хотя бы на одном из доступных компиляторов. Насколько я знаю, на топкодере дефайны в С++ не используют в таких соревнованиях, поэтому предлагаю и здесь их не использовать.
Учитывая возможности некоторых языков, предлагаю проводить отдельный зачет по разным языкам, т.к. вряд ли C++ или Pascal смогут соревноваться с Haskell или Python.
214:
#include <iostream>
__int64 n,k,x,y,a[' '],b[' '],d;
int main()
{
std::cin>>n>>k>>x>>y;
for(k%=2*n;d<n;d++) std::cin>>a[d]>>b[d],d<k?x=2*a[d]-x,y=2*b[d]-y:0;
for (d=0,k-=n;k>0;--k,++d) x=2*a[d]-x,y=2*b[d]-y;
std::cout<<x<<" "<<y;
}
I like the idea of having winners per language, especially difficult to compete with Java :-D
But seriously, you can use code formatting... Is there a tool counting length? You know, I'm wondering if
b[' ']
is 5 characters or 8...edit: Ok, I found that you cannot use code formatting — in the comment above, 3 spaces were replaced with 1, hm HTML...
Snippet
156
#include <iostream>
main() {
__int64 n,k,a[' '],d;
for(std::cin>>n>>k>>*a>>a[1],n*=2;d<k%n*2;) std::cin>>a[2+d],a[d%2]=2*a[2+d%n]-a[d++%2];
std::cout<<*a<<" "<<a[1];
}
О, есть еще чит с import оказывается
155
#import <iostream>
main() {
__int64 n,k,a[' '],d;
for(std::cin>>n>>k>>*a>>a[1],n*=2;d<k%n*2;) std::cin>>a[2+d],a[d%2]=2*a[2+d%n]-a[d++%2];
std::cout<<*a<<" "<<a[1];
}
151
#import <iostream>
main() {
__int64 n,k,a[' '],d;
for(std::cin>>n>>k,n*=2;d<2+k%n*2;) std::cin>>a[d],a[d%2]=2*a[d>n+1?d-n:d]-a[d++%2];
std::cout<<*a<<" "<<a[1];
}
#import <iostream>
main() {
__int64 n,k,a[' '],d;
for(std::cin>>n>>k,n*=2;d<2+k%n*2;a[d%2]=2*a[d>n+1?d-n:d]-a[d++%2]) std::cin>>a[d];
std::cout<<*a<<" "<<a[1];
}
:)
These shortest code competitions really rub me the wrong way, to an extent I can hardly convey. I have spent well over twenty years honing my skill at writing code that would win no prizes for either length or brevity, by merely for clarity. Code clarity reigns supreme in my book. Not cleverness, brevity, or obfuscation. A shortest code competition to me is like a competition to see who can make love in the shortest time. Well, if that's what you are into, enjoy. But my priorities are completely different.
Well this is just for having fun no need to be so serious :O
And he even revived a 4-year old blog post to say that. Talk about serious business.
O_o
4 years old
I didn't look at the posting time and thought it was a new thing, purely because of how many such things there have been in CF recently (achievements, stats, Polygon updates...)
I didn't realize too. And I was wondering why such old contest :-D
Programmers are doing "strange" things to have some fun :-D
This is what I discovered recently — JSFuck.
disclaimer: no I'm not a fun of such things, but comparing with code above, this is "advanced level"...
The point of these competitions are exploiting the language and just playing around with code. It's your opinion but i feel that being clever and knowing the language will definitely make you a better programmer. Code clarity is no big deal. If you find this obfuscated, look at languages like Brainfuck or Intercal.
>I doubt that C++ or Pascal can compete with Haskell or Python
or Perl
"There was this bug running on my keyboard, I tried to hit it but the little bitch always dodged... and look, I wrote a Perl script!"
If we consider CF problems, then there should be general limitations concerning bizzare languages.
UPD: number of downvotes: 7, number of replies: 0. How impressive.
UPD2: oh, it's 4 years old. Maybe that's why (but I probably shouldn't try to find logic in CF downvotes).
What do you mean "general limitations"?
Dunno exactly, maybe making separate categories for some languages. Or restricting the set of usable languages. But a code for a non-DS-heavy problem in Java can't compete with a code in Perl, purely to the languages' syntax verbosity.