RSS

Tag Archives: codecademy

New Coding Challenge – The Quincunx!

ImageThe Quincunx – A triangular pegboard that will create a nice normal distribution as balls are dropped from the top and bounce down randomly over the triangular array of pegs.

Society’s greatest achievement, The Price Is Right, demonstrates the use of a plinko board in this video with the most excited player ever.

The coding challenge is to design a quincunx that demonstrates each of the following four points… No animation is required, simply (1)show the board as an array of X’s with a (2) user-determined number of rows (1-20) and the (3)resulting bins filling with integers as a (4)user-determined number of balls (1-100,000) is dropped. This time, I’m awarding prizes to the cleanest, most clearly documented entries in each language represented on Codecademy (Ruby, JS, Python).

As always, the prizes are bragging rights, presentation of your code on my blog with full attribution to you and a promo copy of any of my eBooks on iPad for you to share with the youngster in your life (or keep yourself). Each of my books presents educational material  in the form of a story (Heracles and the Gas Laws, Sisyphus and the Laws of Motion, Zombies and Fractions).

Happy Coding!

(submit your entries as links in the comments below)

 
Leave a comment

Posted by on July 10, 2013 in Uncategorized

 

Tags: , , , , , , , , ,

RubyMonk

ImageI mention codecademy all the time here and rant about how great a way it is to learn a variety of languages and markups online, on your own time and free. I’ve been following both the web programming track and the Ruby tracks aggressively lately (I’m on a 20 day streak presently). However, I have to also mention another free site that does much the same thing. RubyMonk offers free online courses in Ruby (and Python, under PythonMonk). The Monk websites are clean, well structured and provide an element of atmosphere as well.

Unfortunately, RubyMonk does not provide a forum where I can pitch my project challenges – er, I mean Koans. But if you are learning Ruby or Python with the Monk, please feel free to come here from time to time to see if there are any simple programming challenges open.

 
Leave a comment

Posted by on June 28, 2013 in Uncategorized

 

Tags: , , , , , , , , ,

Coding Challenge II: Make Mine a MASTERmind

ImageDon’t worry, Coding Challenge I is still open, but someone was writing about games to develop in the codecademy discussion groups. 

A while ago, when I was first following the JavaScript pathway, there, I decided to write a MasterMind program. Many of the versions I saw prohibited players from using the same number/color more than once, but I felt that was a cop-out. My solution works, but as usual for me, had some tortuous logic.

So, here’s the challenge:

In any language, write a MasterMind game where the computer chooses the numbers and the user deduces them.

1. use numbers (four of them,#s1-4, randomly chosen by the computer), rather than colors

2.  that allows multiple uses of the same numbers, i.e. ‘1122’

3. provides appropriate feedback to the user to help them close in on the correct sequence.

4. keeps track of the number of turns taken

5. (optional) can also be played with 2 users -or- user sets the code and computer guesses

6. (optional) allow user to select # of positions and range of numbers used.

 

simple code trumps tangly code. I prefer languages I can read (C++, javascript, python) but all are welcome.

 
Leave a comment

Posted by on June 22, 2013 in Uncategorized

 

Tags: , , , , , , , ,

Codecademy Problem

ImageI’ve mentioned many time on this blog how I am a big fan of codecademy. I think this is an excellent way to develop some coding skills in a simple hand-held way. I’ve been following the javascript track for some time and really enjoy it. Recently, Ruby and Python tracks have been introduced, although I have only given each one minimal attention so far. In the future, I am hoping to concentrate on the web programming elements in order to provide some context for the javascript work.

Presently, I have been stuck on a problem that should be easy, but the walkthrough does not seem to guide you in the right direction. The problem is intended to take a string of text and search for your name within this text. I think the difficulty arises from the fact that the walkthrough sounds like you should be solving the whole problem, but may actually be asking for less. 

Below, with a few extra details, I present a solution that effectively gets the job done. I’ve included some documentation so you can see what I was thinking as well as some debugging aids to visualize what the program is doing at each step.
ImageThis solution will get a ‘pass’ for the problem, but I am wondering how this might be simplified.
If you can simplify this solution, please leave a comment and I will update the code if significant advances are made.

/*jshint multistr:true */

var text = “hdajkslhgjalhjghjklhjackfghjdskghjkdfajlk”;  //the text we search through
var myName = “jack”;                                                  //what we are looking for
var hits = [];                                                                  //array storing match
var j=0;                                                                         //a counter for myName array

/////////first loop for match with myName[0]////////////
for (i=0;i< text.length;i++){
console.log(i); // enumerates position in text array
if (text[i] === myName[j]){

//////advances position in myName array, second loop continues search/////
for(var j=i;j<i +myName.length;j++){
console.log(“testing if”,text[j],” = “,myName[j-i]); //shows match test
if(text[j] != myName[j-i]){
hits.length = 0; //if no match, hits array is cleared
j=0; //array position in myName is reset
break; //exits inner loop
} //end ‘if no match’

if (text[j] === myName[j-i]){ //for each match, letter is pushed
hits.push(text[j]); //onto hits array
} //end ‘if match’
} //end inner loop

/////if reach size of myName array ////////
if (hits.length === myName.length){
console.log(“we found your name: “, hits); //output match
break;
} //end ‘size of array
}//end outer loop
}//end program

/* output
0
1
2
3
testing if j = j
testing if k = a
4
5
6
7
8
9
testing if j = j
testing if a = a
testing if l = c
10
11
12
13
testing if j = j
testing if g = a
14
15
16
testing if j = j
testing if k = a
17
18
19
20
testing if j = j
testing if a = a
testing if c = c
testing if k = k
we found your name: [ ‘j’, ‘a’, ‘c’, ‘k’ ]

*/

 
Leave a comment

Posted by on June 12, 2013 in Uncategorized

 

Tags: , , , ,

Two minutes into my latest coursera lecture….

Two minutes into my latest coursera lecture (introduction to interactive programming in python) the instructor indicated his frustration in javascript programming saying that it’s a terrible language. This may be the case… so far I don’t have a lot to compare against, but I have been enjoying learning JS in codecademy and I’m dying to know why he thinks so.

If you have experience programming in javascript and python (or other languages…ruby?) let me know if you agree with the above statement and what makes you think so. As a new programmer I am interested in learning as much as possible – if I can understand what faults people see in these languages I think that would be very instructive.

Thanks

 
3 Comments

Posted by on October 25, 2012 in Uncategorized

 

Tags: , , , , , , , , ,

Stuck at 98%

I’ve been procrastinating – with a lot of things really.

The one that brought me to writing this is that I am 98% finished the codecademy Javascript course with only the Blackjack game remaining. And I’ve already put a lot into that as well. I just need to get off my lazy ass and finish it. Instead, I’ve allowed myself to get distracted by the new courses in python and ruby. I think I’m going to have to set aside a night and get this finished though.

The problem has been that I put javascript aside for long enough that I’m starting to forget the syntax. I think tonight I’ll print out a couple of my old syntax guides (perhaps update them and post them here) and get back in the saddle.

I also have an ePublishing workshop coming up this Thursday. My (biology) class has been given the day off and I’ve hired a babysitter so that I can go. In my mind it is a good way to network with some people who are interested in ePublishing but not comfortable enough to jump in and hopefully learn some things too.

I’ll be taking the iPad with The Thirteenth Labor of Heracles as a demonstration of a finished product and I’m hoping to have The Curse of Sisyphus far enough along that it can be demonstrated as well. I like the way The Curse is coming along – it incorporates more self-testing opportunities than the Thirteenth Labor. I’m also looking into how to develop my own widgets (another project! Great!), but realistically, I recognize that this is probably a long way off for me. I would love to be able to develop a more versatile version of the interactive image widget to use with mathematical equations.

Oh right, I’m also supposed to preparing for an exam! I’ve written all of about ten questions so far and haven’t even looked at my Jeopardy – review yet. And then the lab… damn. I did make that promise didn’t I?

Well, let’s just see how things go one day at a time.

One last thing: My wife is away for what amounts to two weeks. Day one – two minutes after she left: Dingleberry on the dog. I don’t think the cat has realized what’s up yet because I haven’t found any surprises.

 
1 Comment

Posted by on October 16, 2012 in Uncategorized

 

Tags: , , , , , , , , , , , ,

Codecademy – Recursion explanation

Image

Russian Nesting Dolls

This post is primarily for those readers who are working through the Codecademy.com course on javascript. I was having trouble with mastering the recursion problem for solving factorials there and noticed that many others were in the same boat.

This code was really blowing my mind. I was having the worst time understanding it. I was OK with the idea of recursion, but I don’t think I was really understanding it.

I was following the code and could see it is working, but didn’t see why it actually returned the correct value. Additionally, I had a conceptual block – i.e. how does the code store the value of each recursion without a variable?

Here’s the problem:

Write a recursing code that solves for the factorial of any given value.

Recall that factorials are the product of all numbers from 1 to n, where n is the value you are solving for. For example, the factorial of 3 : In mathematical terms this is written, 3!, so

3! = 1*2*3 = 6

4! = 1*2*3*4 = 12

The problem suggests that you set a ‘base case’ as returning 1 if n === 0, and that you use a terminator to prevent crash if negative numbers are entered (because they will otherwise never get to the terminator)

Here’s my code:

function factorial(n) {

if (n<0){

console.log(“We can only compute factorials from positive integers”);

return;     // the catch-all in case a negative number is entered

}

if (n ==0){

return 1;    // the base case

}

else{

return n* factorial (n-1);    // the nested function call

}

}

factorial(4);    // function call to test program

If we start at 4 (as an example), then we go through the code and get to the nested function call that says

return n * factorial(n-1)

if we sub in the actual values for n, it would read:

return (4) * factorial(3)

But factorial(3) is not a number – it is a function call, so before (4) is multiplied by anything, it sends a new value to factorial. This keeps happening until we get to n=0. At that point we’re at the base case and no further recursion will happen – the code simply returns 1.

So, we have to start moving our way back out of the loop. We set n=1 here, so the innermost recursion actually looks like this:

return 1* factorial(0)

because factorial(0) returns 1, we are actually doing this:

return 1*1     (*   = 1    *)

then we back out to the next step:

return 2* 1     (*   = 2   *)

then we get to…

return 3*2…   (*    = 6     *)

return 4*6      (*    = 24     *)

Or, if you can see this more clearly, this is how the computer sees the code:

return 4 * (return 3 * (return 2 * (return 1 * (1))));

work backwards doing the math from the inside out:

1*1 = 1

2*1 = 2

3*2 = 6

4*6 = 24

Q.E.D.

 

postscript: I just received a reply to my post on codecademy.com from a moderator, Alex. He directed me towards an article he had written explaining the same topic using a very elegant flow diagram. You can find that article here.  – I had to write this as a postscript, because his article is so clear that if you read it first, you would have no need to read mine.

 
Leave a comment

Posted by on September 21, 2012 in Uncategorized

 

Tags: , , , , , , , ,

Programming Fundamentals

I just started a ‘Programming Fundamentals’ course last week to see if it looked like it could add comething above and beyond my codecademy classes alone. So far I’m interested. We use a language / coding environment called Alice, which was developed to provide a simple way to start thinking about programming. Essentially, it’s a self-contained program that lets the user drag and drop coding fragments in a way that it creates a program step-by-step. I suppose it’s good – although for old guys like me, it’s very strange. I’d much prefer just using a language and typing the code out. However, I do recognize how the Alice approach might be more accessible to users that have grown up with sophisticated touch devices, etc.

Presently, I’m just working through chapter two, so I’m not too deeply into it yet, but I have found some fascinating things. For one: I’ve completely re-invented the wheel. Through a lot of trial and error I’ve come to a coding style that this text describes as modular, ‘top-down’ design. I also have been doing all of my debugging (what I called troubleshooting) starting with unit testing within a testing shell and then putting everything together in an integrated test.

So far, the major difference between my coding methods and the book’s is that I didn’t develop a whole lexicon for what I was doing. (Ironically, that’s exactly one of the things that I teach in biology – Mendel was successful with his experiments in part because he developed a language to describe his work).

Well, enough chatter. I actually have homework to finish up before I go to class in one hour.

 
Leave a comment

Posted by on August 29, 2012 in Uncategorized

 

Tags: , , , ,

Codecademy Problem

I’m stuck. In working on a section in codecademy’s JavaScript class relating to methods and objects that inherit these methods, I’ve become a bit confused. The problem that I’m on involves an original Object that is a Car that contains the method ‘accelerate.’ – I’m OK with this:

Objects are things within a class, i.e. they are all contain similar property. In this example our Objects are Cars. There can be many different kinds of cars, each with different property such as (different colors, makes, speed, etc). But they are all in the same ‘class’ (i.e. same kind of thing: cars)

Methods are Functions that manipulate Objects. In this example, if we have made a Car Object that has the property Blue and Ford and 10 mph, we can now do something with this object using a method. The codecademy project has us write an ‘accelerate’ Method that adds 10 to the speed. OK – so every time we send our car object to that method, it looks for the speed property and increases it by 10.

Inheritance is a way of making subsets of an Object so that they automatically get the properties that the ‘parent’ Object has, but can also be given new properties that the ‘parent’ Object does not have. In the present codecademy example, we are making an ElectricCar Object that inherits from the Car Object. No problem, this is a good example because we can easily see that it is still a kind of car and that means it makes sense that it should have all the same properties as other cars (color, make, speed – perhaps Blue, Chevy Volt, 20Mph) But we also want to give it properties that other cars do not have, like ‘electricity’ (meaning battery charge).

 

OK, here’s what I have with some notes to follow along an to indicate where I am having problems. Help is greatly appreciated.

 

function Car( listedPrice ) {
var price = listedPrice;
this.speed = 0;
this.numWheels = 4;

this.getPrice = function() {
return price;
};
}

Car.prototype.accelerate = function() {
this.speed += 10;
};

function ElectricCar( listedPrice ) {
var price = listedPrice;
this.electricity = 100;
}
ElectricCar.prototype = new Car();

// Write the accelerate method for ElectricCar here
myElectricCar.accelerate = function() {
this.speed += 20;
};

// Write the decelerate method for ElectricCar here
myElectricCar.decelerate = function(secondsStepped) {
this.speed -= (5*secondsStepped);
};

myElectricCar = new ElectricCar(500);

myElectricCar.accelerate();
console.log(“myElectricCar has speed ” + myElectricCar.speed);
myElectricCar.decelerate(3);
console.log(“myElectricCar has speed ” + myElectricCar.speed);

 

 

 
Leave a comment

Posted by on August 7, 2012 in Uncategorized

 

Tags: , , , , , , ,

Slightly Unhealthy Obsession

I read a post a week or so ago (I’ll look for a citation) on whether blogging was addictive. Every characteristic of an addicted blogger made by the writer was something that I think I had just done within the past five minutes: obsessive checking of the blog for comments and likes, convulsively watching my blog’s stats for activity and trolling of the blogosphere for similar blogs in order to like them so that they might come visit my page in return.

I admit it, I’m totally addicted. And I need your help.

Oh no, I don’t want to quit. I don’t really want to control it at all. What I’d prefer to have is some satisfying stats. So, to that end, could you please stop by my blog once in a while. Hit ‘like’ and maybe leave a comment. Perhaps subscribe… and then maybe get someone you know to come by and do all that again.

Right now I get a paltry handful of visits a day (I think my record was 41 – I wish I knew what I had done right that day). I’d like to see if I can get some decent numbers by the end of the summer. It would also be good for me because I know that I’ll write more (and better) if I knew there was someone out there reading.

I have two blogs, this one for DownHouse Software (although I drop anything that’s going on in my life here) and AppCampus, which is a little more serious. I’ve been trying to post some articles on technology in education. I’d also appreciate some article ideas if you have any.

So, if you can help my feed my addiction a little, thank you.

 
5 Comments

Posted by on July 31, 2012 in Personal Life

 

Tags: , , , , , , , ,