Friday, March 20, 2015

(After a VERY long Hiatus) Problem 44 in Scratch!

I have taken quite the long break from solving Project Euler problems and posting on this blog, but as Spring Break is coming up, I decided that now would be the perfect time to try to solve some problems, possibly using some languages that I have seen in the time since I was last solving.

Problem 101 happens to be quite hard; I have a solution, but it is in Python and uses numpy for some non-trivial linear algebra calculations, so it might take a little while for me to get a challenge-legal solution to it.

So, I decided to instead work on an easier problem, in a "fun" programming language, so I decided to use Scratch: a Blocks Programming Language courtesy of some people at MIT, which is intended mainly to teach young kids to program. As such, it is not exactly a powerhouse in terms of abstraction or performance, but it worked for this problem.

Using a Blocks programming language was certainly interesting. The main issues I ran into were

1) Figuring out where things are/how to do things in terms of the UI, which took a bit of time (though this probably could have been alleviated by watching a tutorial, it didn't take more than 5-10 minutes for me to get things by feeling around).

2)  Having to navigate back and forth through the UI in order to do seemingly trivial things: maybe there are some advanced shortcuts or something. But as I interpret it, in order to make "If a + b = 2" you need to open the controls tab, and grab an if block, then grab the operators tab, and grab an = block and drag it into the if block, then grab a + block and drag it into the left hand side (being careful not to accidentally place it incorrectly and replace the = block), and then you have to go to the data tab and click and drag both a and b into their respective circles, and then you have to write in a 2. That is a lot of steps and involves going through at least 3 tabs and click-and-dragging 4 things, which is a lot of work for what in most programming languages is about 7 characters of typing.

3) Dealing with lack of abstraction: Every variable has to be global (no local variables in functions), and "functions" can't return anything, so I had to use global variables for their return values.

But anyway, I have a solution, it works, and it meows when it is done, so I am happy.

PS: my table-making script is on another computer, so I will update the table soon, but not now.

A picture of my program is below:


No comments:

Post a Comment