127 bytes right now.
[cpp]#include <fstream>
int main(){int a,b,c;std::ifstream("sitin.txt")>>a>>b>>c;std::ofstream o("sitout.txt");o<<a*b<<' '<<c-a*b;}[/cpp]
[ruby]o='sit%s.txt'
f=op(o%'in')
c=f.gs.sp.m(&:toi).ij &:*
p=I f.gs
op(o%'out',?w).w [[p,c].mi,[0,p-c].mx].j' '[/ruby]
106 bytes.
The language is goruby, by the way.
[QUOTE=raBBish;26711343]Here's the fixed version, 112 bytes though...
[lua]n="*n"f=io.input"sitin.txt"a,b,c=f:read(n,n,n)io.output"sitout.txt":write(math.min(a*b,c)," ",math.max(0,c-a*b))[/lua][/QUOTE]
No word on correctness but transplanting your printing logic and removing the extra type annotation takes me down to 132:
[code]main=do{f<-readFile"sitin.txt";let{[r,c,p]=map(read)$words f;} in writeFile"sitout.txt"$concat[show$min(r*c)p," ",show$max 0$p-r*c]}[/code]
Haskell's strong golfing point isn't IO but plain fun application, really...
[editline]15th December 2010[/editline]
[QUOTE=itsbth;26711580][ruby]o='sit%s.txt'
f=op(o%'in')
c=f.gs.sp.m(&:toi).ij &:*
p=I f.gs
op(o%'out',?w).w [[p,c].mi,[0,p-c].mx].j' '[/ruby]
106 bytes.
The language is goruby, by the way.[/QUOTE]
Oh goddamnit now I'm going to find a compiler that'll do the exact same thing for identifiers. Perhaps a quick trip to Pharo...
[editline]15th December 2010[/editline]
But wait - there's the time limit! I'll bet you goruby's regexing is going to get nasty.
A sodabox! I feel chuffed.
[QUOTE=HubmaN;26711680][editline]15th December 2010[/editline]
But wait - there's the time limit! I'll bet you goruby's regexing is going to get nasty.[/QUOTE]
[code]itsbth@itsbth-desktop-ubuntu10:~$ time ./ruby/ruby-1.9.2-p0/goruby fpgolf1.rb
real 0m0.017s
user 0m0.010s
sys 0m0.000s[/code]
Apparently not.
Daaaaamn.
And if you think code golf is awesome (I'm a changed man since this thread) then check this awesome site out: [url]http://codegolf.com/competition/browse[/url] . Not updated any more though.
Also in python you can surround ints with `` to turn them into strings as long as they aren't longs.
of course ruby could do that regex fast enough, it isn't PHP or something!!
this really should be for the full compiled program tbh(more variation available)
-snip for typo-
[editline]15th December 2010[/editline]
Let-lifting takes me to 127 bytes. (I've also gone right off do-notation, but there's probably no bytecount loss there.)
[code]main=readFile"sitin.txt">>= \f->(\[r,c,p]->writeFile"sitout.txt"$concat[show$min(r*c)p," ",show$max 0$p-r*c])$map(read)$words f[/code]
135 bytes PHP - not great but at least it has the right output.
[php]<?list($i,$j)=file("sitin.txt");$b=split(" ",$i);$c=$b[0]*$b[1];$d=$j>$c?$c:$j;fputs(fopen("sitout.txt","w"),($d<0?0:$d)." ".($j-$d));[/php]
Down to 108 now.
[lua]n='*n'a,b,c=io.open'sitin.txt':read(n,n,n)io.output'sitout.txt':write(math.min(a*b,c)," ",math.max(0,c-a*b))[/lua]
Also, is this allowed? :3:
[lua]n='*n'a,b,c=io.open(arg[1]):read(n,n,n)io.output(arg[2]):write(math.min(a*b,c)," ",math.max(0,c-a*b))[/lua]
[img_thumb]http://localhostr.com/files/YxGyk0q/luagofl.png[/img_thumb]
With that I'd get it down to 101 bytes.
The rules say nothing about mechanisms of loading the input or output file. By using Lua, you're already 'manually' loading it through a script. Typing it as arguments would just add another layer to the overall loading process. So I think it should be allowed.
Oh, damn, I'd have to import a library for that.
[editline]15th December 2010[/editline]
It *is* rather vague, actually.
[editline]15th December 2010[/editline]
Do-notation version, by the way - just to be sure.
[code]main=do{f<-readFile"sitin.txt";(\[r,c,p]->writeFile"sitout.txt"$concat[show$min(r*c)p," ",show$max 0$p-r*c])$map(read)$words f}[/code]
125 bytes with arguments
[cpp]#include <fstream>
int main(int y,char*z[]){int a,b,c;std::ifstream(z[1])>>a>>b>>c;std::ofstream o(z[2]);o<<a*b<<' '<<c-a*b;}[/cpp]
[code]a=(`cat sitin.txt`);let c=${a[1]}*${a[0]};e=0;d=${a[2]};((d>c))&&let e=$d-$c&&d=$c;echo $d $e>sitout.txt[/code]
Bash, 105 bytes, supports 0 standing
Disregard:
[quote]If specifying input/output as arguments is allowed, 90 bytes:
[code]a=(`cat $1`);let c=${a[1]}*${a[0]};e=0;d=${a[2]};((d>c))&&let e=$d-$c&&d=$c;echo $d $e>$2
bash (script name) sitin.txt sitout.txt[/code]
Or if use of stdin/stdout is allowed, 84 bytes:
[code]a=(`cat`);let c=${a[1]}*${a[0]};e=0;d=${a[2]};((d>c))&&let e=$d-$c&&d=$c;echo $d $e
bash (script name) < sitin.txt > sitout.txt[/code]
[/quote]
Here's my final version, including the max/min stuff at 145 bytes.
[cpp]#include <fstream>
int main(int y,char**z){int a,b,c,d;std::ifstream(*++z)>>a>>b>>c;d=a*b;std::ofstream o(*++z);o<<(c>d?d:c)<<' '<<(c>d?c-d:0);}[/cpp]
Not gonna get it, because this is 285 bytes, but here it is:
[code]
import math
a = open("sitin.txt", "r")
b = open("sitout.txt", "w")
c = a.readlines()
a.close()
d = c[0].find(" ")
e = (int(c[0][d+1:])*int(c[0][:d]))
f = int(c[1])
i = e-f
if f > e:
g = e
h = abs(i)
else:
g = i
h = 0
b.write("%d %d" % (g,h))
b.close()
[/code]
I'm not going to be supplying any arguments or input.
One char, c++
[cpp]
s
[/cpp]
Compiled with
g++ main.cpp -o main -include fstream -Ds="int main(){int a,b,c; std::ifstream(\"sitin.txt\")>>a>>b>>c;std::ofstream out(\"sitout.txt\");out<<a*b<<' '<<c-a*b;}"
:v:
[QUOTE=Darkimmortal;26712366]135 bytes PHP - not great but at least it has the right output.
[php]<?list($i,$j)=file("sitin.txt");$b=split(" ",$i);$c=$b[0]*$b[1];$d=$j>$c?$c:$j;fputs(fopen("sitout.txt","w"),($d<0?0:$d)." ".($j-$d));[/php][/QUOTE]
[php]<?list($x,$y)=file('sitin.txt');list($a,$b)=split(" ",$x);fputs(fopen('sitout.txt','w'),min($a*$b,$y)." ".max($a*$b-$y,0));[/php]
123 bytes
[QUOTE=haushippo;26719935][php]<?list($x,$y)=file('sitin.txt');list($a,$b)=split(" ",$x);fputs(fopen('sitout.txt','w'),min($a*$b,$y)." ".max($a*$b-$y,0));[/php]
123 bytes[/QUOTE]
Shouldn't it be $y-$a*$b at the end?
[QUOTE=Darkimmortal;26712943][code]a=(`cat sitin.txt`);let c=${a[1]}*${a[0]};e=0;d=${a[2]};((d>c))&&let e=$d-$c&&d=$c;echo $d $e>sitout.txt[/code]
Bash, 105 bytes, supports 0 standing[/QUOTE]
You got me scared for a second there.
[ruby]o='sit%s.txt'
f=op(o%'in')
c=f.gs.sp.m(&:toi).ij &:*
p=I f.gs
c=[c,p].mi
op(o%'out',?w).w [c,p-c].j' '[/ruby]
103 bytes.
[editline]16th December 2010[/editline]
[ruby]o='sit%s.txt'
f=op(o%'in')
c=f.gs.sp.m(&:toi).ij &:*
p=I f.gs
op(o%'out',?w).w [c=[c,p].mi,p-c].j' '[/ruby]
101 bytes.
[editline]16th December 2010[/editline]
[ruby]f=op((o='sit%s.txt')%'in')
op(o%'out',?w).w [c=[(f.gs.sp.m(&:toi).ij &:*),(p=I f.gs)].mi,p-c].j' '[/ruby]
99 bytes!
[QUOTE=itsbth;26725418]You got me scared for a second there.
-code-
99 bytes![/QUOTE]
[lua]n='*n'a,b,c=read(readfrom'sitin.txt',n,n,n)write(writeto'sitout.txt',min(a*b,c),' ',max(0,c-a*b))[/lua]
97 bytes. Lua 4 for the win! :byodood:
[QUOTE=Jookia;26709134][cpp]#include<stdio.h>
main(){int a,b,c,d;FILE*f=fopen("sitin.txt","r"),*g=fopen("sitout.txt","w");fscanf(f,"%d %d\n%d",&a,&b,&c);d=a*b;fprintf(g,"%d %d\n",d,c<=d?0:c%d);}[/cpp]
166. I really don't think I can get it any smaller.[/QUOTE]
[QUOTE=Overv;26712982]Here's my final version, including the max/min stuff at 145 bytes.
[cpp]#include <fstream>
int main(int y,char**z){int a,b,c,d;std::ifstream(*++z)>>a>>b>>c;d=a*b;std::ofstream o(*++z);o<<(c>d?d:c)<<' '<<(c>d?c-d:0);}[/cpp][/QUOTE]
pah, both that valid C solution up there and your invalid C++ solution are bigger than my valid C++ solution (138):
[cpp]#include<fstream>
int main(){int r,s,p;std::ifstream("sitin.txt")>>r>>s>>p;r*=s;std::ofstream("sitout.txt")<<(r>p?p:r)<<" "<<(r>p?0:p-r);}[/cpp]
[QUOTE=raBBish;26731284][lua]n='*n'a,b,c=read(readfrom'sitin.txt',n,n,n)write(writeto'sitout.txt',min(a*b,c),' ',max(0,c-a*b))[/lua]
97 bytes. Lua 4 for the win! :byodood:[/QUOTE]
Why you little!
Well, at least you keep the competition interesting.
[QUOTE=itsbth;26731933]Why you little!
Well, at least you keep the competition interesting.[/QUOTE]
I'm surprised Lua is doing this good, it's one of the more verbose languages I know. Although now I've pretty much ran out of ways to shorten the code even more... Lua4 was one of my last straws, as it doesn't have libraries like Lua5 does.
-snip-
-snap-
[QUOTE=TomyLobo;26731826]C++ solution (138):
[cpp]#include<fstream>
int main(){int r,s,p;std::ifstream("sitin.txt")>>r>>s>>p;r*=s;std::ofstream("sitout.txt")<<(r>p?p:r)<<" "<<(r>p?0:p-r);}[/cpp][/QUOTE]
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]
EDIT: another solution with the same length (136):
[cpp]#include<fstream>
#define x(y)std::fstream("sit"#y".txt")
int main(){int r,s,p;x(in)>>r>>s>>p;r*=s;x(out)<<(r>p?p:r)<<" "<<(r>p?0:p-r);}[/cpp]
EDIT2: yesss, down another 2 bytes (134):
[cpp]#include<fstream>
#define x(y)s;std::fstream("sit"#y".txt")
int main(){int r,p,x(in)>>r>>s>>p;r*=x(out)<<(r>p?p:r)<<" "<<(r>p?0:p-r);}[/cpp]
[ruby]f=op((o='sit%s.txt')%'in')
op(o%'out',?w).w [c=[f.gs.sp.m(&:toi).ij(:*),(p=I f.gs)].mi,' ',p-c][/ruby]
96 bytes. Now I'm really starting to run out of options.
[QUOTE=itsbth;26732440][ruby]f=op((o='sit%s.txt')%'in')
op(o%'out',?w).w [c=[f.gs.sp.m(&:toi).ij(:*),(p=I f.gs)].mi,' ',p-c][/ruby]
96 bytes. Now I'm really starting to run out of options.[/QUOTE]
:arghfist::crying:
[editline]16th December 2010[/editline]
I'm going to change my language, I can't figure out how to make mine any shorter. I also found a way to make yours smaller, itsbth, but I can't test it without the compiler and I don't want to ruin my chances even more. :saddowns:
Sorry, you need to Log In to post a reply to this thread.