• Facepunch Code Golf Competition
    111 replies, posted
Bash, 91 bytes: :smugdog: [code]set `cat sitin.txt`;z=$3;e=0;((z>$1*$2))&&let e=z-$1*$2&&let z=$1*$2;echo $z $e>sitout.txt[/code]
Although it's not a viable entry (piet has no file IO), here's a piet program for this: [img]http://thefwcentral.com/upload/content/images/golfWb74b4f1.gif[/img] 169bytes gif image. Can't see it? Here's a magnified version: [img]http://thefwcentral.com/upload/content/images/golfW_big018edd1.png[/img] Works fine when there are and are not enough seats.
I hold the smallest C program. Woo!
Got my bash version down to 84 bytes now :3: [code]set `cat sitin.txt`;z=$3;e=0;((z>(x=$1*$2)))&&let e=z-$x,z=$x;echo $z $e>sitout.txt[/code]
[QUOTE=bootv2;26736163]so piet is actually programming with colors as input for the compiler?[/QUOTE] Yup! It's really esoteric, as it's not just colour order but layout as well- the interpreter actually "walks" around the image! It uses the hue and shade change between blocks to choose an operation, sometimes using the block area for data. For example, the dark red at the bottom is a branching condition for if there are enough seats. Here's a trace of it running with input 10, 10, 95: [img]http://thefwcentral.com/upload/content/images/golfW_trace12a71336.png[/img] It's really a neat language, if impractical.
Believe it or not, 151 bytes of C. [cpp]#include<stdio.h> main(){int a,b,c,d;fscanf(fopen("sitin.txt","r"),"%d %d\n%d",&a,&b,&c);d=a*b;fprintf(fopen("sitout.txt","w"),"%d %d\n",d,c>d?c-d:0);}[/cpp]
I can see a way to shave off 18 bytes.
Fine, GCC yells at me now. :( [cpp]main(){int a,b,c;fscanf(fopen("sitin.txt","r"),"%d %d\n%d",&a,&b,&c);a*=b;fprintf(fopen("sitout.txt","w"),"%d %d\n",a,c>a?c-a:0);}[/cpp] AS SMALL AS IT WILL GO.
ok everyone! I have you beat! 15 bytes, pure python: [code] import sitlib [/code] Of course, you need to download the library [url=http://sowhat.99k.org/sitlib.php]sitlib[/url]
[QUOTE=Jookia;26742252]Fine, GCC yells at me now. :( [cpp]main(){int a,b,c;fscanf(fopen("sitin.txt","r"),"%d %d\n%d",&a,&b,&c);a*=b;fprintf(fopen("sitout.txt","w"),"%d %d\n",a,c>a?c-a:0);}[/cpp] AS SMALL AS IT WILL GO.[/QUOTE] that doesn't even work, it breaks if everyone can be seated... you also add a newline after the output here's a C program that DOES fulfil all of the specifications and is smaller than any working C program posted so far (136): [cpp]#define x(y,m)fopen("sit"#y".txt",#m),"%d %d" main(){int r,p,s;fscanf(x(in,r)"\n%d",&r,&s,&p);r*=s;fprintf(x(out,w),r>p?p:r,r>p?0:p-r);}[/cpp] I tried using mode "r+", to save another 4 bytes, but for some reason that segfaults somewhere. cba to find out where :P
It works perfectly fine for me and doesn't break. This could be due to OS differences or architecture differences. After all, I'm not exactly writing proper code. I gave that up a page ago. Also, my program above is 130 bytes. What're you talking about? Well, after removing that unused newline, it's 128 bytes. [cpp]main(){int a,b,c;fscanf(fopen("sitin.txt","r"),"%d %d\n%d",&a,&b,&c);a*=b;fprintf(fopen("sitout.txt","w"),"%d %d",a,c>a?c-a:0);}[/cpp]
[QUOTE=TomyLobo;26732086]saved another 2, tehehe (136): [cpp]#include<fstream> int main(){int r,s,p;std::fstream("sitin.txt")>>r>>s>>p;r*=s;std::fstream("sitout.txt")<<(r>p?p:r)<<" "<<(r>p?0:p-r);}[/cpp][/QUOTE] Damn, this only works if sitout.txt exists... Puts me back up to 143 when using macros :/ [cpp]#include<fstream> #define x(y,z)s;std::y##fstream("sit"#y#z".txt") int main(){int r,p,x(i,n)>>r>>s>>p;r*=x(o,ut)<<(r>p?p:r)<<" "<<(r>p?0:p-r);}[/cpp] i still have that 138 solution without the macro though, but i think this one is more awesome :) [editline]17th December 2010[/editline] [QUOTE=Jookia;26749560]It works perfectly fine for me and doesn't break. This could be due to OS differences or architecture differences. After all, I'm not exactly writing proper code. I gave that up a page ago. Also, my program above is 130 bytes. What're you talking about? Well, after removing that unused newline, it's 128 bytes. [cpp]main(){int a,b,c;fscanf(fopen("sitin.txt","r"),"%d %d\n%d",&a,&b,&c);a*=b;fprintf(fopen("sitout.txt","w"),"%d %d",a,c>a?c-a:0);}[/cpp][/QUOTE] i said working program. that thing still doesnt work if, for instance, you give it 7 12\n80. In that case, your program outputs 84 instead of 80 standing people
Oh, I read the OP wrong. I thought it was the number of available seats as the first output integer. [editline]17th December 2010[/editline] [cpp]main(){int a,b,c;fscanf(fopen("sitin.txt","r"),"%d %d\n%d",&a,&b,&c);a*=b;fprintf(fopen("sitout.txt","w"),"%d %d",c>a?a:c,c>a?c-a:0);}[/cpp] 134 bytes. Smallest C program yet.
almost beats your invalid solution by 1 byte (C, 129): [cpp]main(a,b,c){fscanf(fopen("sitin.txt","r"),"%d %d\n%d",&a,&b,&c);a*=b;fprintf(fopen("sitout.txt","w"),"%d %d",c>a?a:c,c>a?c-a:0);}[/cpp] EDIT: sorry i first posted something based on Jookia's old program, heh
Well, you got me.
:)
[cpp]#define F(a)fopen("sit"#a".txt","r+"),"%d %d" main(a,b,c){fscanf(F(in)"\n%d",&a,&b,&c);a*=b;fprintf(F(out),c>a?a:c,c>a?c-a:0);}[/cpp] 127 bytes.
[QUOTE=Jookia;26749829][cpp]#define F(a)fopen("sit"#a".txt","r+"),"%d %d" main(a,b,c){fscanf(F(in)"\n%d",&a,&b,&c);a*=b;fprintf(F(out),c>a?a:c,c>a?c-a:0);}[/cpp] 127 bytes.[/QUOTE] i've thought about r+ before, but that crashes if sitout.txt doesn't exist when running it
Good thing that the challenge doesn't define if sitout.txt exists or not.
[QUOTE=Jookia;26750019]Good thing that the challenge doesn't define if sitout.txt exists or not.[/QUOTE] exactly, so you have to account for both cases
[cpp]#define F(x)fopen("sit"#x".txt","a+"),"%d %d" main(a,b,c){fscanf(F(in)"\n%d",&a,&b,&c);a*=b;fprintf(F(out),c>a?a:c,c>a?c-a:0);}[/cpp] Fixed.
[QUOTE=Jookia;26750049][cpp]#define F(x)fopen("sit"#x".txt","a+"),"%d %d" main(a,b,c){fscanf(F(in)"\n%d",&a,&b,&c);a*=b;fprintf(F(out),c>a?a:c,c>a?c-a:0);}[/cpp] Fixed.[/QUOTE] echo garbage > sitout.txt a.exe type sitout.txt ---- garbage 80 0 ---- [editline]17th December 2010[/editline] here's my current "test suite" btw: [code]@echo off del a.exe %1 %2 echo 7 12 > sitin.txt echo 100 >> sitin.txt del sitout.txt a.exe type sitout.txt echo. echo ---- echo 7 12 > sitin.txt echo 80 >> sitin.txt del sitout.txt a.exe type sitout.txt echo. echo ---- echo garbage > sitout.txt a.exe type sitout.txt echo. echo ----[/code] call it as "<whatever>.bat gcc <whatever>.c" expected output is: 84 16 ---- 80 0 ---- 80 0 ---- [editline]17th December 2010[/editline] I'll just assume to have read rights to sitin.txt and write rights to sitout.txt, because otherwise this task would be impossible [editline]17th December 2010[/editline] siemens, any word on that?
[QUOTE=TomyLobo;26750108]I'll just assume to have read rights to sitin.txt and write rights to sitout.txt, because otherwise this task would be impossible [editline]17th December 2010[/editline] siemens, any word on that?[/QUOTE] You'll have rwx to both.
[QUOTE=Siemens;26750223]You'll have rwx to both.[/QUOTE] I meant on the other thing about sitout.txt the access right thing was just a joke :P EDIT: mentioned wrong txt file
Here's a 127 byte python program: [code]f=open("sitin.txt") a,b,c=[int(x) for x in f.read().split()] g=open("sitout.txt","w") m=min(c,a*b) g.write(str(m)+" "+str(c-m))[/code]
Here's my shot at Python, 111 bytes. [lua]a,b,c=map(int,open('sitin.txt').read().split());open('sitout.txt','w').write('%i %i'%(min(a*b,c),max(0,c-a*b)))[/lua]
[QUOTE=raBBish;26753281] [lua]a,b,c=map(int,open('sitin.txt').read().split());open('sitout.txt','w').write('%i %i'%(min(a*b,c),max(0,c-a*b)))[/lua][/QUOTE] Of course, how did I not think of using file objects directly instead of assigning them to variables :downs: Brings my version down to 119 bytes: [code]a,b,c=[int(x) for x in open("sitin.txt").read().split()] m=min(c,a*b) open("sitout.txt","w").write(str(m)+" "+str(c-m))[/code]
[QUOTE=itsbth;26732440]96 bytes. Now I'm really starting to run out of options.[/QUOTE] You can remove 5 bytes by removing the string formatting nonsense with sit*.txt and just use 'sitin.txt' and 'sitout.txt'. [editline]17th December 2010[/editline] I'M NOT GIVING UP YET [lua]n='*n'a,b,c=read(readfrom'sitin.txt',n,n,n)m=min(a*b,c)write(writeto'sitout.txt',m,' ',c-m)[/lua] 91 bytes! [editline]17th December 2010[/editline] By modifying Lua4 and creating short aliases for functions, which would give the same effect as [url=http://rbjl.net/34-do-you-know-the-official-ruby-interpreter-goruby]goruby[/url], I'd get my code down to 72 bytes. [editline]17th December 2010[/editline] Lua5 version, a bit larger though at 97 bytes. [lua]n='*n'a,b,c=io.open'sitin.txt':read(n,n,n)m=math.min(a*b,c)io.output'sitout.txt':write(m,' ',c-m)[/lua]
Made a PowerShell script for fun, although it's not particularly short... [code]$a,$b,$c=(gc sitin.txt|foreach{[int[]]$_.split()});if($c-lt($m=$d=$a*$b)){$m=$c};sc sitout.txt(''+$m+' '+($c-$m))[/code] 113 bytes. [editline]17th December 2010[/editline] Whoops, double post :v:
[lua]AssignFile(f,'sitin.txt');Reset(f);Read(f,a,b,c);Writeln(Format('%d %d', [a*b,c-a*b]));Close(f);[/lua] 95 bytes in delphi. [editline]17th December 2010[/editline] Dangit, output to file, not console. There goes that.
Sorry, you need to Log In to post a reply to this thread.