Log In  

Hello all.
Can any of you clever folk make this code shorter?
It's bugging the life out of me but I don't know how to make it shorter though it looks like it can be.
Cheers.

    --p.c= n / 2 + 0.5 ?
    if (p.t/p.die<7/#p.c_table) p.c=4
    if (p.t/p.die<5/#p.c_table) p.c=3
    if (p.t/p.die<3/#p.c_table) p.c=2
    if (p.t/p.die<1/#p.c_table) p.c=1
P#98516 2021-10-11 18:13

Not 100% sure but try this:

p.c = ceil(((p.t * #p.c_table) / p.die + 1) / 2)

You should be able to get rid of the inner-most parens so this should work too using one less token (I think)

p.c = ceil((p.t * #p.c_table / p.die + 1) / 2)
P#98518 2021-10-11 18:48

Wow, jasondelaat.
That was quick.
It looks like it works too.
Thanks so much for that :-)

P#98520 2021-10-11 20:20

@Peej
No worries, happy to help.

I don't know exactly what this code is doing or why it's doing it but you should be aware though that my version is potentially brittle if any of the numbers in your code need to change. Like, in the first line of your original code if you want that to be p.c = 5 for some reason my version won't work anymore.

P#98523 2021-10-11 21:38

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 06:00:25 | 0.022s | Q:11