I made a prime sieve: <a href="http://i.imgur.com/Elk5A.png" rel="nofollow">http://i.imgur.com/Elk5A.png</a><p>It was pretty fun.<p>JS generated isn't so bad..<p><pre><code> var n;
var A;
var i;
var x;
var j;
n = 100;
A = [];
for (i = 0; i <= n; i++) {
A[i - 1] = true;
}
var i_end = Math.sqrt(n);
for (i = 2; i <= i_end; i++) {
if (A[i - 1] == true) {
j = Math.pow(i, 2);
while (j <= n) {
A[j - 1] = false;
j = (j || 0) + i;
}
}
}
for (x = 2; x <= n; x++) {
window.alert([x,': ',A[x - 1]].join(''));
}</code></pre>
The name of this language immediately made me think of the blocky.io (<a href="http://blocky.io/" rel="nofollow">http://blocky.io/</a>) visual programming language, which was written in Common Lisp by David O'Toole before this language was developed. Blocky.io is <i>very</i> similar to this language, in more then just name, it even has its own MIT scratch like interface: <a href="http://blocky.io/blog/wp-content/uploads/2012/03/Screenshot-1-300x217.png" rel="nofollow">http://blocky.io/blog/wp-content/uploads/2012/03/Screenshot-...</a>.
i solved a problem featured on the yc company interviewstreet.com codesprint.<p>the problem: Count the number of one-bits from 0 to 2^n - 1, for n from 1 to 20.<p>my solution: <a href="http://i.imgur.com/hUxt0.png" rel="nofollow">http://i.imgur.com/hUxt0.png</a><p>when you run the solution:<p><pre><code> Number of one-bits in 1 bit numbers from 0 to 1 = 1
Number of one-bits in 2 bit numbers from 0 to 3 = 4
Number of one-bits in 3 bit numbers from 0 to 7 = 12
Number of one-bits in 4 bit numbers from 0 to 15 = 32
Number of one-bits in 5 bit numbers from 0 to 31 = 80
Number of one-bits in 6 bit numbers from 0 to 63 = 192
Number of one-bits in 7 bit numbers from 0 to 127 = 448
....</code></pre>
JS:<p><pre><code> var list;
var x;
var prev;
var onebits;
var doubleatprev;
list = [];
list[0] = 1;
list[1] = 4;
for (x = 2; x <= 20; x++) {
prev = x;
onebits = Math.pow(2, prev);
doubleatprev = list[x - 1] * 2;
list[1 + x - 1] = onebits + doubleatprev;
}
for (x = 1; x <= 20; x++) {
window.alert(['Number of one-bits in ',x,' bit numbers from 0 to ',Math.pow(2, x) - 1,' = ',list[x - 1]].join(''));
}
</code></pre>
Took 15 minutes to code up and 45 minutes to debug the array indexing :) One of these days I'll be able to write the JS and get the Blockly instead of the other way around - that'd be super awesome!
Hey, you can create new maze puzzles for your fun from the JavaScript console (WebKit Inspector, Firebug,...)! First create a new function to paint the custom map by pasting this code into the console: <a href="https://gist.github.com/2848451" rel="nofollow">https://gist.github.com/2848451</a><p>Next setup Maze.MAP matrix with value 1 for empty cell, 0 for path and 2/3 for start/finish positions.<p>Now run loadMazeMap() to load your new challenge ;)<p>Example: <a href="http://www.dodaj.rs/f/f/nM/4w3wop7u/custommaze.png" rel="nofollow">http://www.dodaj.rs/f/f/nM/4w3wop7u/custommaze.png</a>
This seems to be done by an extraordinarily smart guy - Neil
Fraser. He's behind "google-diff-match-patch" [1] project,
which is AFAIK the machinery behind realtime collaboration
on google docs.<p>Definitely worth watching.<p>[1] <a href="http://code.google.com/p/google-diff-match-patch/" rel="nofollow">http://code.google.com/p/google-diff-match-patch/</a>
I should note that the appearance of Blockly is very similar to App Inventor[1]. It seems that visual programming languages with imperative and sequential semantics converge to one direction: "blocky" combining core primitives and custom primitives. In this sense I think it's THE future of domain-specific languages.<p>[1] <a href="http://www.appinventor.org/" rel="nofollow">http://www.appinventor.org/</a>
I noticed something interesting and disturbing after reading some of the answers: people are more concerned with the length of the code rather than the optimal solution (no extra turns / backtracking). This reminds me of interviewing at MS about 12 years ago and all they cared about was the ability to write recursive code.<p>IMO, yes, elegant code is fantastic, but don't lose track of why we write code in the first place.<p>Edit: consolidating from post below.<p><a href="http://imgur.com/Nvy8u" rel="nofollow">http://imgur.com/Nvy8u</a><p>Here's a minimal solution with optimal logic (for this map) without hard coding. It also ensures that there is a forward step in every iteration of the while loop.<p>Basically it's just an order of precedence:<p>Turn right > turn left > go straight
The puzzle-piece representation of structure is neat, but at a 2-minute glance it seems not to scale to real complexity.<p>One of the big ideas in programming is abstraction/modularity/reuse, and I don't see how that fits in here.<p>(I found the "procedure" block, but I don't see anything that fits inside it other than "break out of loop", which doesn't make any sense. And I don't see how to call the procedure.)<p>So I find myself looking at the samples everyone's demonstrating here and finding they're harder to read than real well-organized code.
<a href="https://imgur.com/VBsht" rel="nofollow">https://imgur.com/VBsht</a><p><pre><code> while (true) do
if not (wall to the left) then
(turn left)
while (wall ahead) do
(turn right)
(move forward)
</code></pre>
This uses the general maze-solving logic of following the outer wall in one direction until you find the exit. It never turns then turns back or runs into a wall.
After I placed <i>turn left</i> after <i>move forward</i>, what was my first instinct? Same as yours, I wanted to right-click <i>move forward</i> and place the copy after <i>turn left</i>.
Can this program be made any shorter? <a href="http://www.dodaj.rs/f/1K/vW/2gLz63rl/blockly.png" rel="nofollow">http://www.dodaj.rs/f/1K/vW/2gLz63rl/blockly.png</a>
Reminds me of Sprog - <a href="http://sprog.sourceforge.net/" rel="nofollow">http://sprog.sourceforge.net/</a><p>Back in the day I was looking at Sprog for some client-facing project so probably worth looking back at it again. Here's a nice example of <i>Data Munging with Sprog</i> - <a href="http://www.perl.com/pub/2005/06/23/sprog.html" rel="nofollow">http://www.perl.com/pub/2005/06/23/sprog.html</a>
This past weekend at the Vancouver Polyglot Conference there was a session with the author of Waterbear (<a href="http://waterbearlang.com/" rel="nofollow">http://waterbearlang.com/</a>) that got a fairly good turnout. It looks remarkably similar.
Waterbear still has my vote for generating Javascript with the block based coding metaphore<p><a href="http://waterbearlang.com" rel="nofollow">http://waterbearlang.com</a>
This could become pretty interesting, especially if there is a platform aspect. Meaning I could easily extend this with my own elements and commands.<p>I can see some use for example in one application where we are importing data from other systems. Something like this could be used to create a quite nice user interface for creating simple programs that would manipulate and filter the incoming data.
I like it a lot, and look forward to trying it out on my girlfriend to see how a non-coder responds to it.<p>Whilst working out the while loop however, I put the code to loop outside the block instead of inside, thereby making an infinite loop. Now the Chrome browser window is completely unresponsive, and won't even close, so it seems I have to kill chrome to get rid of it.<p>Other than that, cool!
I've always thought it would be cool to have a backend environment similar to labVIEW (but faster!). I use labview in my research and it is the best solution I've found for encouraging / allowing for code re-use. This Google Blockly, to some extent, seems to be heading that way - I'm looking forward to seeing how it develops.
Cool beans.<p>My suggestion based on no evidence what-so-ever is that I'd like to see something like this in a richer environment.<p>To give a bad example, VB. The original VB had forms (maybe it still does). You'd make a form. Double click the button and add code for "onclick" basically. I guess maybe that was inspired by Hypercard.<p>In any case it was really easy to see how to make a useful program because of the structure a form plus code snippets gave. If those code snippets were Blockly that might be better for learning.<p>A maybe better example is Unity3D. You add a 3d object, attach a Script and start editing code to move that object by supplying an Update() function or something along those lines. Maybe a Step() where you can define state change code snippets?<p>All I'm saying is a language like Blockly that removes the syntax errors, attached to a larger framework (games, graphics, or webapps), seems like it would make it far more approachable. You could actually make something useful or fun in a less steps.
Looks good, but I just crashed my chrome after putting a "repeat while>and" block in between one of the move functions. Might want to watch out for new users accidentally crashing their browsers while trying to do something innocent.
I remembered a trick about mazes: if you keep your hand on the right wall, you'll eventually reach the end of the maze (assuming that the beginning and end share a contiguous wall)<p><a href="http://imgur.com/i2uOj" rel="nofollow">http://imgur.com/i2uOj</a><p>Fun puzzle!
Love this idea for teaching kids. Reminds me of the visual programming in Click N Create / Multimedia Fusion / Games factory which was/is very advanced and powerful.<p>Given sufficient resource and polish something like this could be awesome.
Wall follower for the maze: <a href="http://imgur.com/w8xoQ" rel="nofollow">http://imgur.com/w8xoQ</a><p>I'd love to do Trémaux's algorithm if they'd add the full list of block types to the maze.
I want something to code on my smartphone, without having to type more than is necessary. I expected this kind of thing to arrive. I hope they become more than a little toy.