Log In  
Follow
shadowtide13
[ :: Read More :: ]

In order to experiment with the Picotron v10 Gui library, I made this simple 4 op (more like 6 op) calculator! Just copy and paste the following code into a blank Picotron project and press ctrl+r!

gui = Gui()
set_window(79,73)
buttons = {}
state = 0
a = 0.0
b = 0.0
op = nil
buffer = ""

function _init()
    for i=1,9,3 do
        for j=0,2 do
            add(buttons, gui:attach_button({label=tostr(i+j),x=j*16,y=(abs(i-9)/3)*14+8,bgcol=0x0d01,fgcol=0x070d,tap=function()add_buf(i+j)end}))
        end
    end
    add(buttons, gui:attach_button({label="0",x=0,y=59,bgcol=0x0d01,fgcol=0x070d,tap=function()add_buf(0)end}))
    add(buttons, gui:attach_button({label=".",x=16,y=59,bgcol=0x0d01,fgcol=0x070d,tap=function()add_buf(".")end}))
    add(buttons, gui:attach_button({label="=",x=32,y=59,bgcol=0x0902,fgcol=0x0209,tap=function()eval()end}))
    add(buttons, gui:attach_button({label="+",x=48,y=17,bgcol=0x0b03,fgcol=0x030b,tap=function()set_op("+")end}))
    add(buttons, gui:attach_button({label="-",x=48,y=31,bgcol=0x0b03,fgcol=0x030b,tap=function()set_op("-")end}))
    add(buttons, gui:attach_button({label="*",x=48,y=45,bgcol=0x0b03,fgcol=0x030b,tap=function()set_op("*")end}))
    add(buttons, gui:attach_button({label="/",x=48,y=59,bgcol=0x0b03,fgcol=0x030b,tap=function()set_op("/")end}))
    add(buttons, gui:attach_button({label="c",x=64,y=17,bgcol=0x0902,fgcol=0x0209,tap=function()clear()end}))
    add(buttons, gui:attach_button({label="^",x=64,y=31,bgcol=0x0b03,fgcol=0x030b,tap=function()set_op("^")end}))
    add(buttons, gui:attach_button({label="%",x=64,y=45,bgcol=0x0b03,fgcol=0x030b,tap=function()set_op("%")end}))
    add(buttons, gui:attach_button({label="_",x=64,y=59,bgcol=0x0d01,fgcol=0x070d,tap=function()inv()end}))
end

function _draw()
    gui:update_all()
    cls(n)
    if state==-1 then
        ?"err",1,4,7
    else
        ?buffer,1,4,7
    end
    gui:draw_all()
end

function inv()
    buffer = tostr(buffer)
    if sub(buffer,1,1) != "-" then
        buffer = "-"..buffer
    else
        buffer = sub(buffer, 2)
    end
end

function add_buf(n)
    if(state==-1)state=0
    buffer = buffer..n
    if(#buffer>15)buffer=sub(buffer,1,15)
end

function set_op(n)
    if(state==-1)state=0
    if state == 0 then
        a = buffer
        buffer = ""
        op = n
        state = 1
    else
        state = -1
    end
end

function eval()
    if state == 1 then
        b = buffer
        buffer = ""
        if op == "+" then
            buffer = a + b
        elseif op == "-" then
            buffer = a - b
        elseif op == "*" then
            buffer = a * b
        elseif op == "/" then
            buffer = a / b
        elseif op == "^" then
            buffer = a ^ b
        elseif op == "%" then
            buffer = a % b
        end
        state = 0
    end
end

function clear()
    if buffer == "" then
        op = nil
        a = 0.0
        b = 0.0
        state = 0
    else
        buffer = ""
    end
end
P#130565 2023-06-05 19:21 ( Edited 2023-06-05 19:29)

[ :: Read More :: ]

Logarithm Benchmark

Cart #log_bench-0 | 2023-06-02 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Logarithm algorithms

wiki method

stats

tokens:46

description

the wiki method uses an interesting property of logarithms to compute a value. specifically:
log(A * B) = log(A) + log(B)
by using a look up table for all the logarithms (base 10 of course) of the first 9 digits (1-9) we can use the following code to compute logarithms:

log10_table = {
 0, 0.3, 0.475,
 0.6, 0.7, 0.775,
 0.8375, 0.9, 0.95, 1
}

function log10(n)
 if (n < 1) return nil
 local t = 0
 while n > 10 do
  n /= 10
  t += 1
 end
 return log10_table[flr(n)] + t
end

what this algorithm actually does is repeatedly divide by 10 and add the number of times it does this to a counter. Essentially we are assuming the number n can be expressed as m * 10 *10 *10... and we are simply removing these tens. then re-adding them in at the end.

extended wiki method

stats

tokens:98 (can probably be improved easily)

description

its the same thing but we use the following properties to extend the domain of the function:
log base n of m = log base 10 of n / log base 10 of m
log(n)=log(A)-log(A/n) when 0 < n < 1

my method

stats

tokens:118

description

I simply test 'all' the possible digits and calculate the error. then take the digit with the lowest error then I move on to test the next digit. Effectivly a brute force method.
The code:

function log(n,m)
 assert(n>0and m>0and m!=1)
 if(m<1)return log(n,10)/log(m,10)
 if(n<1)return -log(1/n,m)
 local g,cur,err='0000.0000',g,9999
 for i=1,9do
  if i!=5then
   for j=0,9do
    cur=sub(g,1,i-1)..j..sub(g,i+1)
    local c=m^tonum(cur)-n
    if abs(c)< err and c<=0then
     g,err=cur,abs(c)
    end
   end
  end
 end
 return tonum(g)
end
P#130462 2023-06-02 15:49

[ :: Read More :: ]

Goats, Cars n' Doors!

Cart #goats_cars_doors-1 | 2023-01-18 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

So...

the situation being proposed is: there are 3 doors, behind 2 of them are goats the other has a new car. you (trying to get the car) pick a door, the host stops you and opens a different door. behind that door is a goat. they then ask you "do you switch your answer".

the question: what are the odds of getting that car if you switch vs. not switching.

the problem: everyone i've asked has said its a 50% chance either way, but the answer is actually 2/3 if you switch. why? I have no idea but I built a simulation so you can answer that yourself!

P#124504 2023-01-18 13:41

[ :: Read More :: ]

Cart #kofajemop-0 | 2022-12-13 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

Its War!
Just press Z... that's it.
This cartridge was mostly to make a quick n' dirty card library and use it in practice.

You can enable/disable auto mode in the pause menu (auto mode stops when a game ends).
When you finish a game you can press X to start a new game.

P#122346 2022-12-13 20:05

[ :: Read More :: ]

Cart #boat_zeta_0-0 | 2022-10-03 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

BOAT ZETA!

This is a little remake of Yahtzee I made a while ago, it was a little janky and broken but I decided to fix it up and post it. not much but it works!

If you notice any bugs or have any advice, I encourage you to tell me!

P#118434 2022-10-03 15:15

[ :: Read More :: ]

Cart #typewriter-0 | 2022-06-08 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

ITS... a typewriter

so I made this after spending an unhealthy amount of time in google docs.
Enjoy spending your time typing in this program, it really has no practical use.

CONTROLS

⬅️/⬆️/➡️/⬇️: move the 'cursor'
🅾️: type the symbol
the green arrow is \n or newline
the red arrow is backspace
the yellow... thing is space bar
and the colored squares switch what characters are available (like upper and lower case)

There is a total of 4 character palettes, I encourage you guys to see if you can expand the palettes even more. it also supports special characters found using CHR().

Also if you find any bugs, I encourage you report them!

P#112889 2022-06-08 14:53 ( Edited 2022-06-08 14:54)

[ :: Read More :: ]

BUTTERPAN [v1.0.0]

Cart #butterpan_v1-0 | 2022-05-19 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

STORY

Its Butterpan! Join butter boy on his slippery adventure. try not to melt while gathering all the coins and gems! But watch out! Sometimes the pan gets really hot or someone drops a crab into the pan! See how high of a score you can get!

CONTROLS

arrow keys to move
[o] button to dash
[x] button to shoot hot butter
the meter on the right is how much butter you have left, if it drops to zero you lose.

Extras

this is my first pico-8 cartridge! I could use some feed back on the game and its game play. Have fun! (my personal best score is something like 5000 points)

P#112057 2022-05-19 21:45 ( Edited 2022-05-19 21:48)