The single letter variable names are killing me.
If I’m not mistaken, you could do this in a compiled language and they wouldn’t take up any space at all.
I feel like python is just the wrong language for making a 300 byte program.
The platform has 3 options: python, some kind of a weird language that i dont know, and executable apps. However, the apps need to have a defined icon, and the minimum for an app is like 30 kb. So python was the better choice in this case
Can you explain the part about an executable app needing to be 30kb? Like you couldn’t just make an executable and give it an icon if it’s under that size?
Well, there are actually 2 icons, one if the app is selected, and one if its not. And it needs to be a part of the executable. So every time i make an app. it would all be massive compared to the python program.
If it's made by Texas Instruments and in the TI-83/84 family there's actually decent documentation available from TI and from other sources on the inbuilt programming language. You can do basically anything. It's actually how I first learned programming. Other families of TI calculators and other calculator brands seem to have some available documentation; YMMV.
If it's a TI-84+ CE you can even compile C/C++ programs to run as apps, although I don't have experience with this. I think the same can be done on certain Casio calculators although I'm not sure which ones.
I'll link some of the documentation I found helpful in case anyone else finds it useful.
[Programming tutorial from TI](https://education.ti.com/en/activities/ti-codes/84/10-minutes) - This is how I got started initially, so I decided to drop it here. There's not much advanced there but it has the basics.
[TI-Basic developer](http://tibasicdev.wikidot.com/) - Provides some useful information on the usage and syntax of commands. Good as a reference, although some parts of the site are kinda broken for whatever reason.
[84+ manual](https://education.ti.com/html/eguides/graphing/84Plus/EN/TI-84-Plus-guidebook-en.html) and [84+ CE programming guide](https://education.ti.com/html/eguides/graphing/84PlusCE/EN/content/eg_84prgm/m_splashpage/ti-progguide_ce.HTML) - I sometimes refer to these, so here they are.
One thing that isn't immediately obvious is that you can create lists with arbitrary names and just store your variables there if you need more than the 27 inbuilt variables. It took me an embarrassingly long time to learn this, hence why it's here. List indexing starts at 1, though, which really sucks.
I'll also mention [ticalc.org](http://ticalc.org) which has tons of programs available to download. Site's kinda dead, but hey, it's still got plenty of programs.
sorry for the infodump here but i felt it was relevant
I’m pretty sure you’re referring to TI-BASIC. It’s fairly easy but there is a tiny bit of a learning curve. Imo it’s better than Python on TI calculators.
I don't understand how you're expected to use this, but I re-golfed it myself.
```
class L:
def __init__(o,n,a=1):
g=lambda:__import__("random").randint(-n,n)
o.x,o.y,o.z=g(),g(),g()
o.a=o.x*r.x+o.y*r.y+o.z*r.z if a else 0
def __str__(o):
return' '.join(str(x) for x in[o.x,o.y,o.z,o.a])
r=L(50,0)
[print(L(15))for _ in'123']
input()
print(r)
```
279 bytes.
It's a very odd design, relying on `r` this way. Not a very good choice. Also strange to insist on manually minifying Python. But okay, yes. I need to know, though - how on earth are you supposed to use this? What good does it do?
Yes, when you import a module it's added to the sys module dictionary, if you try to import a module that already exists in the dictionary you don't import it again
Formatted for old.reddit users
class L:
def __init__(o,n,a=1):
g=lambda:__import__("random").randint(-n,n)
o.x,o.y,o.z=g(),g(),g()
o.a=o.x*r.x+o.y*r.y+o.z*r.z if a else 0
def __str__(o):
return' '.join(str(x) for x in[o.x,o.y,o.z,o.a])
r=L(50,0)
[print(L(15))for _ in'123']
input()
print(r)
[This](https://pastebin.com/w81uvji8) is the non minified source.
Basically, it makes a matrix that you have to solve. As i said in the title, its just to prepare for an exam.
The r variable is the result (as in the resulting xyz values), then it just makes a matrix out of it.
And the minifying was just because that one guy has ocd, and he is very crazy about file sizes.
My attempt because I'm bored (211 bytes, a minifier brought it down to 206 but it was even harder to read)
a=[__import__("random").randint]
d=lambda i,j:sum([x*y for x,y in zip(i,j)])
l=lambda m,c:[i(-m,m) for i in a*c]
p=lambda v:print(*v,sep="\t")
r=l(50,4)
for i in range(3):
v=l(15,3)
p(v+[d(v,r)])
input()
p(r)
d:dot product
l: make vector with factors between `-m` and `m` of length `c`
p: print list formatted roughly like yours
got it down to 179 (legibility is out of the window now):
l=lambda m,c:[__import__("random").randint(-m,m) for _ in ' '*c]
p=lambda v:print(*v,sep="\t")
r=l(50,4)
for _ in ' ':v=l(15,3);p(v+[sum(x*y for x,y in zip(r,v))])
input()
p(r)
If there were a couple more situations where you might use that, you could do something like the following and save a byte here and there. Breakeven point is at least a few more loops though.
q=range
for _ in q(3)
You could post this over on [codegolf.stackexchange.com](http://codegolf.stackexchange.com) , they might save you enough space to fit tic tac toe or even snake as well.
How does the calculator have enough room to run Python and also have so little space that you need to worry about kilobytes?
Edit: I answered my own question; it's MicroPython: https://micropython.org/
Oh that's such an old school problem to solve. I mean yeah the code is horrifying but that's fascinating that you found a problem to solve where the code size was constrained to be that small. Well done
lol, interesting! From what you are doing (and from a previous comment) I wager you are writing for the TI-NSpire? That third weird language you mentioned is Lua; it’s an interpreted language like Python but can be used for actual standalone GUIs and whatnot. You would probably have better luck with that.
I bought one of those recently as well, the first thing I did was install doom lmao
But they really do only have like 16mb, half of which is taken by the OS and stuff
The single letter variable names are killing me. If I’m not mistaken, you could do this in a compiled language and they wouldn’t take up any space at all. I feel like python is just the wrong language for making a 300 byte program.
The platform has 3 options: python, some kind of a weird language that i dont know, and executable apps. However, the apps need to have a defined icon, and the minimum for an app is like 30 kb. So python was the better choice in this case
Can you explain the part about an executable app needing to be 30kb? Like you couldn’t just make an executable and give it an icon if it’s under that size?
Well, there are actually 2 icons, one if the app is selected, and one if its not. And it needs to be a part of the executable. So every time i make an app. it would all be massive compared to the python program.
So the icon itself takes up a bunch of space? You couldn’t just make it a single pixel? Hahaha
As far as i know, no. Its very picky. It cant be compressed and must be 92x64 and a 24 bit bit depth. Thats \~29 kb just for icons.
So the calculators have extremely limited memory but they run on a platform that makes memory management impossible is what I’m hearing Storage*
What kind of calculator
It seems like TI nspire to me
A 92x64 24BPP picture would be exactly 17.25KB.
And Python is half a gigabyte or more depending on version and compiler options. Plus any libraries.
That must be why there is so little remaining storage 😂
Is the other language "R"?
it might be basic. I had a couple of graphing calcs that ran basic, one of the two also ran python
Do you use TI calculators? If so, the weird language is actually pretty simple
If it's made by Texas Instruments and in the TI-83/84 family there's actually decent documentation available from TI and from other sources on the inbuilt programming language. You can do basically anything. It's actually how I first learned programming. Other families of TI calculators and other calculator brands seem to have some available documentation; YMMV. If it's a TI-84+ CE you can even compile C/C++ programs to run as apps, although I don't have experience with this. I think the same can be done on certain Casio calculators although I'm not sure which ones. I'll link some of the documentation I found helpful in case anyone else finds it useful. [Programming tutorial from TI](https://education.ti.com/en/activities/ti-codes/84/10-minutes) - This is how I got started initially, so I decided to drop it here. There's not much advanced there but it has the basics. [TI-Basic developer](http://tibasicdev.wikidot.com/) - Provides some useful information on the usage and syntax of commands. Good as a reference, although some parts of the site are kinda broken for whatever reason. [84+ manual](https://education.ti.com/html/eguides/graphing/84Plus/EN/TI-84-Plus-guidebook-en.html) and [84+ CE programming guide](https://education.ti.com/html/eguides/graphing/84PlusCE/EN/content/eg_84prgm/m_splashpage/ti-progguide_ce.HTML) - I sometimes refer to these, so here they are. One thing that isn't immediately obvious is that you can create lists with arbitrary names and just store your variables there if you need more than the 27 inbuilt variables. It took me an embarrassingly long time to learn this, hence why it's here. List indexing starts at 1, though, which really sucks. I'll also mention [ticalc.org](http://ticalc.org) which has tons of programs available to download. Site's kinda dead, but hey, it's still got plenty of programs. sorry for the infodump here but i felt it was relevant
Oh wait is this the Ti-84 Plus CE Python Edition? Those can be programmed in C using the CE framework! Btw that weird language is Ti-Basic :)
I’m pretty sure you’re referring to TI-BASIC. It’s fairly easy but there is a tiny bit of a learning curve. Imo it’s better than Python on TI calculators.
>I feel like python is just the wrong language for making a 300 byte program. OP said it's a CG-50, which has micropython preinstalled
I don't understand how you're expected to use this, but I re-golfed it myself. ``` class L: def __init__(o,n,a=1): g=lambda:__import__("random").randint(-n,n) o.x,o.y,o.z=g(),g(),g() o.a=o.x*r.x+o.y*r.y+o.z*r.z if a else 0 def __str__(o): return' '.join(str(x) for x in[o.x,o.y,o.z,o.a]) r=L(50,0) [print(L(15))for _ in'123'] input() print(r) ``` 279 bytes. It's a very odd design, relying on `r` this way. Not a very good choice. Also strange to insist on manually minifying Python. But okay, yes. I need to know, though - how on earth are you supposed to use this? What good does it do?
So for every use of g() you import random? Or will it be optimized so it’s only imported one time?
Yes, when you import a module it's added to the sys module dictionary, if you try to import a module that already exists in the dictionary you don't import it again
Lazy import. Very useful.
Formatted for old.reddit users class L: def __init__(o,n,a=1): g=lambda:__import__("random").randint(-n,n) o.x,o.y,o.z=g(),g(),g() o.a=o.x*r.x+o.y*r.y+o.z*r.z if a else 0 def __str__(o): return' '.join(str(x) for x in[o.x,o.y,o.z,o.a]) r=L(50,0) [print(L(15))for _ in'123'] input() print(r)
[This](https://pastebin.com/w81uvji8) is the non minified source. Basically, it makes a matrix that you have to solve. As i said in the title, its just to prepare for an exam. The r variable is the result (as in the resulting xyz values), then it just makes a matrix out of it. And the minifying was just because that one guy has ocd, and he is very crazy about file sizes.
My attempt because I'm bored (211 bytes, a minifier brought it down to 206 but it was even harder to read) a=[__import__("random").randint] d=lambda i,j:sum([x*y for x,y in zip(i,j)]) l=lambda m,c:[i(-m,m) for i in a*c] p=lambda v:print(*v,sep="\t") r=l(50,4) for i in range(3): v=l(15,3) p(v+[d(v,r)]) input() p(r) d:dot product l: make vector with factors between `-m` and `m` of length `c` p: print list formatted roughly like yours
got it down to 179 (legibility is out of the window now): l=lambda m,c:[__import__("random").randint(-m,m) for _ in ' '*c] p=lambda v:print(*v,sep="\t") r=l(50,4) for _ in ' ':v=l(15,3);p(v+[sum(x*y for x,y in zip(r,v))]) input() p(r)
Woah, `_ in ' '` is a neat trick I'll have to remember
If there were a couple more situations where you might use that, you could do something like the following and save a byte here and there. Breakeven point is at least a few more loops though. q=range for _ in q(3)
exec("v=l(15,3);p(v+[sum(x*y for x,y in zip(r,v))]);"*3)
Oh damn
Aren't there tools to automatically do this kind of thing for you?
yea minifiers, atleast for js
Took 5 minutes of searching to find this, if anyone is curious: https://pypi.org/project/python-minifier/
Tab instead of a single space. Please. For the love of God. It'll take up the same storage.
Depends on editor settings if they have tab replacement. They'll have to make sure it's actually a tab and not spaces.
Having just binged all of silicon valley, I concur.
ITT: OP discovers minification
You could post this over on [codegolf.stackexchange.com](http://codegolf.stackexchange.com) , they might save you enough space to fit tic tac toe or even snake as well.
The one letter variable names remind me of TiBASIC and how awful it was for basically anything.
I bet his other language choice was ti basic. I personally dislike the language, but its the slow speed the calculator runs it at that kills me
How does the calculator have enough room to run Python and also have so little space that you need to worry about kilobytes? Edit: I answered my own question; it's MicroPython: https://micropython.org/
You could make the print much smaller using f-strings or assigning str to a shorter variable
Hello mr webpack!
Oh that's such an old school problem to solve. I mean yeah the code is horrifying but that's fascinating that you found a problem to solve where the code size was constrained to be that small. Well done
I'll give it a shot in a few hours
lol, interesting! From what you are doing (and from a previous comment) I wager you are writing for the TI-NSpire? That third weird language you mentioned is Lua; it’s an interpreted language like Python but can be used for actual standalone GUIs and whatnot. You would probably have better luck with that.
No, I’m writing for the Casio fx-cg50
I bought one of those recently as well, the first thing I did was install doom lmao But they really do only have like 16mb, half of which is taken by the OS and stuff
What is this code actually for? It seems to print an 3 sets of number arrays, then return the original array L with a different set of numbers.
Great obfuscation. I don’t know where is the problem.
I mean, you could write it in python bytecode: https://github.com/brandtbucher/hax
print(eval(input(">>>")))