
-----------------------------------
copthesaint
Wed Jan 19, 2011 10:34 pm

23 Line Pong
-----------------------------------
Lol I dont want to know how complex it would be to minipulate the values for a 3 dimensional array doing this... lol
You weren't around for this, but things very quickly get out of hand... http://compsci.ca/blog/your-computer-science-isu-in-20-lines/

View.Set ("Graphics,Offscreenonly,nobuttonbar") 
fcn cnd (exps : boolean, var x : int, y : int) : boolean 
    if exps then 
        x := y 
    end if 
    result false 
end cnd 
var pFTString : array 0..1 of string := init ("","Paused") 
var pB,pI,pT,pFTI, pX, pY, pX2, pY2, bX, bY, bXV,bYV,pW,pW2, pF, pWid, pLen, pFLocX1, pFLocX2,pFLocX3, pFLocY3,pFLocY1,pFLocY2: int := -5 
var chars : array char of boolean 
loop 
    Input.KeyDown (chars) 
    exit when /*Initalization Conditions*/cnd ((pI = -5), pF, Font.New ("Arial:24")) or cnd ((pI = -5), pFTI, 0) or cnd ((pI = -5), pB, -1) or cnd ((pI = -5), pFLocY1, maxy - 40)or cnd ((pI = -5), pFLocY3, (maxy div 4) * 3) or cnd ((pI = -5), pFLocX3, maxx div 2) or cnd ((pI = -5), pFLocY2, maxy - 40) or cnd ((pI = -5), pFLocX1, 10)or cnd ((pI = -5), pFLocX2, maxx-30)or cnd ((pI = -5), pWid, 15)or cnd ((pI = -5), pLen, 40)or cnd ((pI = -5), pW, 0) or cnd ((pI = -5), pW2, 0) or cnd ((pI = -5), pI, 0) or cnd ((pI = 0), pX, 10)or cnd ((pI = 0), bXV, ((Rand.Int (0,1)*2) -1)*100* Rand.Int (3,6)) or cnd ((pI = 0), bYV, ((Rand.Int (0,1)*2) -1)*100* Rand.Int (3,5)) or cnd ((pI = 0), pY, (maxy div 2)*1000) or cnd ((pI = 0), pX2, (maxx - 10)*1000) or cnd ((pI = 0), pY2, (maxy div 2)*1000)or cnd ((pI = 0),bX, (maxx div 2)*1000) or cnd ((pI = 0),bY, (maxy div 2)*1000) or cnd ((pI = 2), pT, Time.ElapsedCPU) or cnd ((pI = 2), pI, 0) or cnd ((pT + 3000  (maxx - 5)*1000)and (pI = -1),pW, pW + 1) or cnd ((bX > (maxx - 5)*1000)and (pI = -1),pI, 2) or cnd ((pI = -1),bX, bX + bXV) or cnd ((pI = -1),bY, bY + bYV) or cnd ((bY < 5000) and (bYV < 0),bYV, bYV * -1) or cnd ((bY > (maxy - 5)*1000)and (bYV > 0),bYV, bYV * -1) or cnd ( (bX >= pX and bX = pY -40000 and bY = pY2 -40000 and bY  0),bXV, round (bXV * -1.045)) /*User Controls*/or cnd (chars ('w') and (pY < (maxy - 40)*1000),pY, pY + 1000) or cnd (chars ('s')and (pY > 40000),pY, pY - 1000) or cnd (chars (KEY_UP_ARROW)and(pY2 < (maxy - 40)*1000),pY2, pY2 + 1000) or cnd (chars (KEY_DOWN_ARROW) and (pY2 > 40000),pY2, pY2 - 1000) or cnd (chars ('p') and pB = -1 ,pB, 1)or cnd (pB = 1 and chars ('p') = false ,pI, pI * -1)  or cnd (pB = 1 and chars ('p') = false ,pB, -1) or cnd ((pI = 1) or (pI = -1), pFTI, (pI + 1) div 2) 
    drawfillbox (-1,-1,maxx+1,maxy+1, black) 
    drawfilloval (round (bX / 1000),round(bY / 1000),5,5,white) 
    drawfillbox (round (pX / 1000),round (pY / 1000)-pLen,round(pX / 1000)+pWid,round(pY / 1000)+pLen,white) 
    drawfillbox (round (pX2 / 1000),round (pY2 / 1000)-pLen,round(pX2 / 1000)-pWid,round(pY2 / 1000)+pLen,white) 
    Font.Draw (pFTString (pFTI),pFLocX3 - (Font.Width (pFTString (pFTI),pF) div 2),pFLocY3, pF,white) 
    Font.Draw (intstr (pW),pFLocX1,pFLocY1, pF,white) 
    Font.Draw (intstr (pW2),pFLocX2,pFLocY2, pF,white) 
    View.Update 
end loop 
%Line 23 here


So no this isn't original, but it is funny having a 23 line pong program... 
If you press p you will pause the game
'w' and 's' are the keys for player one, up arrow and down arrow are keys for player two.

-----------------------------------
Insectoid
Wed Jan 19, 2011 11:22 pm

RE:23 Line Pong
-----------------------------------
This is likely just because I'm running it through Wine, but it's incredibly slow (4-5 spf -not fps, spf)on my computer. I'm far too lazy to figure out the conditional atm.

I find a lot of programs can be simplified if you just look up patterns in the code. Many conditionals, loops, etc. can be collapsed into very few lines, or by reading possible outputs of functions you can generate truth tables and write them mathematically in far fewer lines. 

I've had fun going through assignments and collapsing them into very few lines or single complex statements that might not appear to work at first but do with explanation. 

Good job on this- If I have access to a Windows machine with Turing anytime in the near future I'll try it out for real.

-----------------------------------
TheGuardian001
Thu Jan 20, 2011 1:35 am

Re: 23 Line Pong
-----------------------------------
It's seems to run quite well on a Windows machine.
That's one hell of a conditional though.

-----------------------------------
Zren
Thu Jan 20, 2011 10:17 am

RE:23 Line Pong
-----------------------------------
That one line is why normal people judge length in characters . . . >.<
Haven't played long enough by myslef but is there a win condition?

-----------------------------------
Tony
Thu Jan 20, 2011 10:36 am

RE:23 Line Pong
-----------------------------------
No, there is no win condition. The loop will never exit.

-----------------------------------
2goto1
Thu Jan 20, 2011 11:29 am

Re: RE:23 Line Pong
-----------------------------------
That one line is why normal people judge length in characters . . . >.<

Good point. The motivation for "least number of lines / characters" has always been one of algorithmic efficiency, above all else

-----------------------------------
Tony
Thu Jan 20, 2011 11:52 am

RE:23 Line Pong
-----------------------------------
/sarcasm, right?

-----------------------------------
Sur_real
Thu Jan 20, 2011 1:36 pm

Re: RE:23 Line Pong
-----------------------------------
That one line is why normal people judge length in characters . . . >.<
Haven't played long enough by myslef but is there a win condition?

I agree...
on a similar note then you should check you fishtastic's Turing TD http://compsci.ca/v3/viewtopic.php?t=20247

-----------------------------------
mirhagk
Thu Jan 20, 2011 2:19 pm

RE:23 Line Pong
-----------------------------------
I know something more impressive. I didn't find this, but this kid in my compsci class did, so I insta-conscripted him to me ecoo team found it.

There's this coconut problem

http://ecoo.org/cs/ECOO_08_Board/brd2008p2.html

There solution is that big, but it's decently complex.

his solution (works for every answer they have) (also note the input is wrong... 144, 120 and 17 are 44, 20 and 7 respectively, they even say so lol)
is one variable declaration, a for loop (to get all 5 answers), an input, and an output (with non-complex math)


var num : int
for i : 1 .. 5
    get num
    put "For ",num," men, the smallest number of coconuts is ",num ** 5 - num + 1
end for


-----------------------------------
Insectoid
Thu Jan 20, 2011 4:12 pm

RE:23 Line Pong
-----------------------------------
Things like that are what I love about programing contests. There's always an 'obvious' answer that most of the participants will use. Then there are a number of 'obscure' solutions that require you to look at the problem sideways. Anyone can figure these out given time, but it takes a different kind of thinker to figure these out within the time constraints of a contest. Imo these are the true gods of programing contests.

-----------------------------------
copthesaint
Thu Jan 20, 2011 11:53 pm

RE:23 Line Pong
-----------------------------------
:D I love programing contests, I didnt win for our contest last year on the count that I forgot to copy the java installers onto my labtop and couldn't test anything -_- but! I did get third previous year! lol
