karel defends democracy solution

so i solved this problem pretty quickly.  probably took about 30 minutes.  decomposition was very easy as well.  not much else to say.  been slacking on the coding since i’ve been putting more time on my gym workout routine. i need to watch some youtube videos on how to use github so i can upload my solutions on there.

import stanford.karel.SuperKarel;
public class defendDemocracyKarel extends SuperKarel{
public void run(){ //algorithm is not finished
	move();
	while (frontIsClear()){
		if (beepersPresent()){
			moveNextRectangle();
		} else {
			cleanChad();
			moveNextRectangle();
		}
	}
}

//moves karel 2 spaces forward when possible.
private void moveNextRectangle(){
	if (frontIsClear()){
		move();
		if (frontIsClear()){
			move();
		}
	}
}

//cleans the chad, starts and ends with karel at the middle facing right
private void cleanChad(){
	turnLeft();
	move();
	while (beepersPresent()){
		pickBeeper();
	}
	turnAround();
	move();
	move();
	while (beepersPresent()){
		pickBeeper();
	}
	turnAround();
	move();
	turnRight();
}


}

Karel java midpoint solution

I finally solved, the karel midpoint problem. This took me probably a total of 12 hours on and off to code over a few days. I found it much tougher than the checkerboard problem which I solved in a few hours. The fact that we’re limited from using variables makes it much harder but it was a fun challenge to solve it using only the allowed predefined Karel methods.  I think my code’s pretty clean compared to some other people’s code I’ve looked at.

</span>
<pre>/*
* File: MidpointFindingKarel.java
* -------------------------------
* When you finish writing it, the MidpointFindingKarel class should
* leave a beeper on the corner closest to the center of 1st Street
* (or either of the two central corners if 1st Street has an even
* number of corners).  Karel can put down additional beepers as it
* looks for the midpoint, but must pick them up again before it
* stops.  The world may be of any size, but you are allowed to
* assume that it is at least as tall as it is wide.
*/

import stanford.karel.*;

public class MidpointFindingKarel extends SuperKarel {
public void run(){
	layRow();
	findMidpoint();
}

private void findMidpoint(){
	if (frontIsBlocked()){ //checks for case of street of 1 unit length
		turnAround(); //program will end
	} else{ //checks for every other case
			backandForthRemoval();
			turnAround();
			move();
	}
}

private void backandForthRemoval() {  //unfinished method, should decompose this further

	while (beepersPresent()){
			move();
			if (beepersPresent()){ //keep on removing beepers
				turnAround();
				move();
				turnAround();
				pickBeeper();
				moveToWall();  //goes to opposite wall and turns around
				moveToNearestBeeper();
			} else {
				//does nothing, means there is only 1 beeper left and it is in the middle
			}
	}
}

//pre: karel is not standing on a beeper
//post:karel is now standing on the nearest beeper
private void moveToNearestBeeper(){
	while (noBeepersPresent()){
		move();
	}
}

//pre: karel will be facing towards either wall
//post: karel will move to the wall it was facing and turn around
private void moveToWall() {
	while (frontIsClear()){
		move();
	}
	turnAround();
}
//post: karel will have laid a row of beepers and will face west
private void layRow() {
	while (frontIsClear()){
		putBeeper();
		move();
	}
	putBeeper();
	turnAround();
}

}

Earlier, I didn’t know how to get the indentation to show up correctly in the source code. I googled for about 30 minutes  to figure out how to make the source code look like it is in Eclipse. The tab to switch between visual and Text editor is near the upper right corner of the blog editing page.  Clearly, I am not the only one with this problem as evidenced by the numerous identical questions. WordPress is starting to aggravate me.  I probably should’ve gone over the wordpress tutorial.

slow progress but progress nonetheless

So….., since last week I’ve attempted to make progress on learning how to code.  The car business that I currently work in has slowed down heavily allowing me a lot more free time to learn or do whatever I want lately, the only drawback is obviously a drop in income.  I’ve taken a few introductory C programming courses during undergrad.  It was fairly boring, dry and I couldn’t see the financial benefit to learning it.  Obviously ever since web 2.0 things have changed.

I’m following Natasha the robot’s study plan and starting with the Stanford CS 106A Java course.  The course at least so far has been using Karel the robot to teach the basics of coding.  It focuses less so on the syntax and more instead on the logical reasoning and algorithmic design to solve the problems they give you.  I really like this approach.  It focuses on the reasoning rather than the syntax.  I remember in the past being bogged down with learning syntax and thus hampering my learning of design.  I also like that I can see the robot move around in it’s own little world versus a regular programming class that would show a black screen and have only text input and outputs.  I am definitely a visual learner.  I visualize when information is passed from one section of a program to another.  I wasn’t a huge fan of abstract concepts.  I preferred physics much more than math.  I preferred civil engineering over electrical since I could visualize everything that was happening.  It made intuitive sense to me.  I finished the first 2 problems of the first assignment.  I did have to look at the answers for the first problem.  The 2nd problem, I solved on my own.  I did have to spend about an hour trying to debug it.  The process to debugging felt pretty similar to solving an engineering problem.  Solving problems is kind of fun, I just wish I could get paid for it immediately lol.

Here is a link to the Stanford CS 106A class on Java programming.  The link contains the software needed to get started.

http://www.stanford.edu/class/cs106a/software.html

Hopefully, none of you guys will run into the problem that I had with the Java versions.  The Stanford CS 106A course uses a program called Eclipse to run the homework assignments. Try to download the newest version of Eclipse.  I had used an older version which kept giving errors where the program would not even start.  It uses some type of java software version 1.6  that you need to download.  Version 1.7 will not make Eclipse work correctly.  I had ver 1.7 installed and after compiling the pop up screen would be blank.  So I went into the control panel and manually uninstalled ver 1.7 of java.  Then I reinstalled ver 1.6 from the stanford CS 106a link.  After that I went back into control panel, searched for java and clicked it open.  Then I unchecked the box where it automatically updates.  I do not want automatic updates to a newer version of Java as that would make Eclipse work incorrectly.  I had to google around to figure out why i was getting all these errors and then a blank compiler screen, took me about 1.5 hours.  Very fucking annoying…

Anyways, I do plan to finish the CS 106A course in it’s entirety.  It’s pretty important to have a strong fundamental base of knowledge of programming techniques.  After this, I would probably head straight into learning ruby online.

I’ve made a github account but haven’t uploaded anything yet.  I might have to download some type of github for windows clone or whatever that is.  I’m little hesitant to do that, since I have a pretty old laptop.  If i really end up enjoying coding, I might have to splurge on a macbook air in a few months.

another thing to do is to learn how to use more features of wordpress.  it seems the proofread feature only highlights the typos unlike microsoft Word which prompts you to correct each typo.

I want to note a very useful piece of info from the CS 106a course.  Decomposition is very important.  This is a concept that is new to me despite having gone through almost 90% of the ruby course on code academy.  I was never taught this in my undergrad intro to programming courses.

Decomposition:

a.) a method solves 1 problem

b.) methods should be roughly 1-15 lines

c.) have good names, i.e. the name should describe the method

d.) use comments, preferably use pre and post conditions within comments

So, until next time.  May the odds be ever in my favor.

The genesis post

Hello world!!!

I’ll be recording my journey/experiment with coding on here.  I had read http://learnwithjeff.com.  Apparently, he was a self taught programmer who switched in to the tech field with 6 months of self taught hardcore grinding code.  I’ve been reading more and more articles about developer bootcamps too.  I also bought a $10 coding ebook on field of programming by Natasha Murashev, http://www.natashamurashev.com.  Both her and Jeff recommended starting a blog to document my own learning process as well as to create a personal brand.  Let’s see where this goes.

I have a degree in civil engineering but I am currently working in a separate industry for my friend’s small business.  I will make a decision probably by sometime early next year whether or not to go back into civil engineering or possibly even a career in tech.

I think coding is a very useful skill and am currently motivated enough to experiment with it.

1. It’s probably the quickest way to become an entrepreneur without burdening yourself with massive amounts of debt.  All you need is a laptop, maybe $12/month for web hosting and the rest is up to your own talent and effort that determines the success of your endeavors.

2.  It currently pays well.  That said, I have my doubts on how long the current “drought” of programmers will last and how long the current high salaries will continue to be offered.

3.  I don’t have a have a huge passion for my original major in Civil Engineering.  I’m okay with it.  I find it interesting but not something I would seek out for fun.  I find chess to be  interesting.  That said I never studied the game of chess on any level.  It takes time to become good at something.  It’s hard for me to stay motivated unless I am making money at something or that it will contribute to long term financial gain.  I had and still have to a lesser extent a passion for poker.  The complexities of the game, the calculated risk taking, the thrill of setting your opponent up with a well timed trap, bluffing, the freedom of being your own boss was very attractive to me especially during the time I was a college student.  I was taught myself poker through online resources and books.  I never had a formal coach, but I did have a poker study group to discuss hands, strategy with other poker enthusiasts.  The difference between poker and chess was that poker was profitable.

I think that I see the same thing in coding that I do with poker.  It takes time, dedication and some degree of natural talent to rise towards to the top.  Though in poker, I never had the drive to rise to the top.  I only wanted to chase the highest $ hourly with the least amount of stress.  I do believe that is a worthy goal in poker.  The reality of losing money, putting in hours to break even or lose money can be very discouraging and extremely stressful and damaging to your physical and mental health.  Anyways… I see coding requiring the similar critical thinking thought process but it’s not a zero sum game.  Success in poker comes at the cost of someone else’s loss.  My profit was someone else’s loss.  In coding, that doesn’t seem to be true even if you look at people competing for jobs.  The rockstar engineers who created smartphones, ipads, google glass also created a huge demand for more apps and more demand for engineers.  Their success as an engineer, coder doesn’t really come at the cost of someone else’s job.

I also find the idea of being a freelance coder to be pretty attractive.  You get to choose your clients, your projects, your prices (as long as you can find customers willing to pay them) and hours.  I do believe I have the right personality and mindset for coding but time will tell.