Author Topic: [CHALLENGE]Logic and Optimization  (Read 27567 times)

0 Members and 1 Guest are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #60 on: January 21, 2011, 12:18:09 am »
Oh, I noticed that the offset in the string was 1 for Rock, 5 for Paper and 10 for Scissors. {1,5,10} happens to be the first 3 numbers in the 5th row of Pascals Triangle. I think nCr is n!/((n-r)!r!) so plug in 5 nCr 1 would be 5!/(4!1!)=120/24=5.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [CHALLENGE]Logic and Optimization
« Reply #61 on: January 21, 2011, 01:23:20 am »
Merging lines and using ":" does not save any bytes of memory and slows the code down a little, so I avoid using the semicolon as a line break.

Didja like my math with the string?
It slows the code down? O.O I never noticed that. I sometimes use the : to reduce scrolling time accross a 15 KB program when an error occurs (I hate waiting 789 hours for scrolling and sometimes I don't have enough space for DCS7)

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #62 on: January 21, 2011, 07:56:31 am »
Ah, well, it slows it down slightly from what I can tell (I could be wrong), but it isn't by much.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #63 on: January 21, 2011, 11:21:10 am »
Code: [Select]
1→B
ClrHome
Disp " ROCK"," PAPER"," SCISSORS
Repeat A=105
Output(B,1,"}
Repeat Ans
Getkey
End
Output(B,1,"                                     ;There is a space there
B+(Ans=34)-(Ans=25
If A>3 Or not(Ans
1+2not(Ans
Ans→B
End
B-1→B
randInt(0,2→A
"WIN!
If B=3fPart((A+2)/3
"LOSE.
If B=A
"TIE.
ClrHome
Disp Ans,"CALC:","YOU:
A
For(A,0,1
Output(A+2,6,sub("ROCKPAPERSCISSORS",5 nCr Ans,Ans²+4
B
End

That should work :D
« Last Edit: January 21, 2011, 11:21:48 am by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #64 on: January 21, 2011, 11:25:54 am »
You need A later in the loop, so it won't work :(

EDIT: Never mind :D

You put A>3 instead of Ans :P I didn't catch that immediately... Nice! 2 bytes saved :D

REEDIT: Nevermind, you DO need A to complete the Repeat A=105 loop.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #65 on: January 21, 2011, 12:44:06 pm »
Enough edits?  :P

Anyway, all that I can remember changing is eliminating the Getkey->A because you change the A before the loop repeats.
« Last Edit: January 21, 2011, 02:33:19 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #66 on: January 21, 2011, 02:04:43 pm »
It doesn't change A to my knowledge; It only changes B which determines the location of the cursor. It needs A to stay intact because pressing enter returns 105 which exits the loop.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #67 on: January 21, 2011, 02:35:39 pm »
I will optimize this if it kills me.
* Qwerty.55 hopes it doesn't kill him
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #68 on: January 21, 2011, 05:02:16 pm »
Crap! I must hurry up and add some unoptimisations!

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #69 on: January 21, 2011, 08:07:24 pm »
And where's Runer? The Extreme Optimizer ;D

Code: [Select]
1→B
ClrHome
Disp " ROCK"," PAPER"," SCISSORS
Repeat A=105
Output(B,1,"}
Repeat Ans
Getkey
End
Output(B,1,"                                     ;There is a space there
B+(Ans=34)-(Ans=25
If A>3 Or not(Ans
1+2not(Ans
Ans→B
End
B-1→B
randInt(0,2→A
"WIN!
If B=3fPart((A+2)/3
"LOSE.
If B=A
"TIE.
ClrHome
Disp Ans,"CALC:","YOU:
A
For(A,0,1
Output(A+2,6,sub("ROCKPAPERSCISSORS",5 nCr Ans,Ans²+4
B
End

Nice, it looks really well, probably optimized as well as it can be.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #70 on: January 21, 2011, 08:13:31 pm »
I wanted to challenge people to make one, but I wanted to keep the same graphics and stuff, so I just posted it instead :( But... I don't know if I should do this... Okee, I will! How about I pose this challenge. Make a Tic-Tac-Toe game that has user input, win/lose/tie detection and has AI that is more than a random number generator. Try to post the smallest version (I have a few that I liked giving out to friends at school. The calc usually won). Oh, and make it so that the user can choose if they are X versus Calc,O versus Calc, or if it is two player (X versus O).

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #71 on: January 21, 2011, 08:16:36 pm »
I wanted to challenge people to make one, but I wanted to keep the same graphics and stuff, so I just posted it instead :( But... I don't know if I should do this... Okee, I will! How about I pose this challenge. Make a Tic-Tac-Toe game that has user input, win/lose/tie detection and has AI that is more than a random number generator. Try to post the smallest version (I have a few that I liked giving out to friends at school. The calc usually won). Oh, and make it so that the user can choose if they are X versus Calc,O versus Calc, or if it is two player (X versus O).

Woah, Tic Tac Toe AI? That looks challenging. I once made a TIC TAC TOE game, but it was Axe and it was two players on one calculator.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #72 on: January 21, 2011, 08:27:54 pm »
My first "major" BASIC program was a source for tic-tac-toe my brother found on the internet. It was just two people could play on the calc. I later made my version which was about half the size and had AI and 2 player. But I still appreciate that first program because it exposed me to all sorts of new commands (I had no idea what getKey did or that it existed as well as Goto or Lbl or Text( or a bajillion others).

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: [CHALLENGE]Logic and Optimization
« Reply #73 on: January 21, 2011, 08:45:07 pm »
Code: [Select]
:DelVar BClrHome
:Disp " ROCK"," PAPER"," SCISSORS
:Repeat A=105
:Output(B+1,1,"}
:Repeat Ans
:getKey→A
:End
:Output(B+1,1,"
:B+sum(DeltaList(Ans={25,34
:Ans-3int(Ans/3→B
:End
:int(3rand→A
:"WIN!
:If B=3fPart((A+2)/3
:"LOSE.
:If B=A
:"TIE.
:ClrHome
:Disp Ans,"CALC:","YOU:
:A
:For(A,2,3
:Output(A,6,sub("ROCKPAPERSCISSORS",5 nCr Ans,Ans2+4
:B
:End
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: [CHALLENGE]Logic and Optimization
« Reply #74 on: January 21, 2011, 08:54:19 pm »
Wow. 14 bytes saved. That is awesome! I've almost never used the DeltaList thing and the int(3rand thing is just... wow. Nice.