RSS

Tag Archives: programming

A Post Across Two Blogs

Image

Where did my mind go?

I admit that I have a problem.

That problem is that I have to try-really try to be organized (if any students are reading this, they won’t believe that I am ever organized, even after trying, but that’s only partly correct). It does not come naturally to me and I tend to add complexity when I should be adding simplicity. The good thing is, at least I recognize this and I have a couple solutions, one of which I’ll fess up to right away: When I get lost in my own web, the best thing I can do is put my problem down and come back after a good night’s sleep.

It’s rare that I actually get a good night’s sleep though, but it often works out that any degree of shut-eye will do. And this is just what neurologists have been telling us for a long time. We don’t fully understand sleep, but we do know that it’s important. Recent data has just come out from the University of Wisconsin-Madison lending further support to the hypothesis that sleep is an organizing tool for our brains.

Image

Really, this is an important part of my work.

 

 Dr. Giulio Tononi, of the UW Center for Sleep and Consciousness. “During wake, learning strengthens the synaptic connections throughout the brain, increasing the need for energy and saturating the brain with new information. Sleep allows the brain to reset, helping integrate newly learned material with consolidated memories, so the brain can begin anew the next day.”

We know that sleep functions in many ways to help out brains. Again, from the UW-M website,Indeed, there is evidence that sleep enhances important features of memory, including acquisition, consolidation, gist extraction, integration and “smart forgetting,” which allows the brain to rid itself of the inevitable accumulation of unimportant details.”

Prior work from Brown University also shows that “sleep is not just a waste of time.” While the data from UW-M suggests that sleep is important in the organization, integration and normalization of new material, Masako Tamaki and co-workers from Brown have shown that sleep is necessary in order to learn new motor tasks. This means, that we need sleep not only to make sense of information, but also to be able to retrieve it more efficiently and tie it to specific musculature functions (e.g. riding a bike, playing an instrument).

The other evening I was lost in the complexity of a new programming project I have been working on. I had an idea of how I wanted to attack the task, but it involved learning a number of new methods for handling and retrieving data. The point of the project was to create an program that was incrementally advancing in the way it was crafted – i.e. it was a learning tool for me. There’s no need for this project, just practice for me. Yet, I was doing something that I’ve learned not to do again and again in science. I was adding more than one variable to an experiment and then being frustrated by my inability to work out the kinks and get any meaning.

I needed sleep and knew it. So, I did the nest I could to make notes about what I was dealing with and closed everything (including myself) down.

The next day, I gave myself permission to re-examine the problem from scratch and figure out if I was going about it in the best way possible. The first thing I did was to ratchet back the number of new methods used and made a larger, more cumbersome program, but one that was functionally simpler. I also permitted myself to ‘cheat’ a couple of aspects of the program in order to get it working and then try to re-introduce the items that I cheated by removing before. An example of this was to just use a simple integer, like ‘5’ where I really wanted to generate a random number based on the size of a container that was holding ‘objects’ I used in the program. This meant that I could focus on the use of the data without needing to feed in the ‘real’ information yet.

Most importantly, I feel better about the project now. I think I can finish it with a couple more hours of work and I don’t think I have to throw my computer out of a high window just yet. Take my advice. When working on something that is giving you trouble, give it a good go, then stop, sleep, regroup, and start fresh the next day. Your time is better spent sleeping than spinning your wheels.

code_cpp

goto the code

In fact, I am still having problems, but they are becoming more well defined and manageable. I’m posting the program itself and some discussion of my problems on my other blog, but I thought I would start with a little Neurobiology here first.

Sarah Allen in the Southern Methodist University explains how this works when learning music…

 
4 Comments

Posted by on May 15, 2014 in Uncategorized

 

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

A Book and an App

Image

Bring just one pencil

The Book

I’m enjoying a new (to me) book over the holiday break: The Mysterious Benedict Society, about several children- but one in particular – who are recruited by the odd, reclusive, Mr. Benedict. Their recruitment, itself, is a bit of an adventure. Each responded to this strange add appearing in the newspaper.

There are tests within tests to separate the wheat from the chaff. A test that’s a puzzle, a maze, tests of resourcefulness and honesty. And, when all that is over, the real work is just begun.

I originally bought this book for my son, who read a few pages and then decided that there wasn’t enough action in it and set it aside. But, seriously,  buying for Harry is just cover for me to get whatever I want regardless of the age of the target audience, so I wanted to read it from the start.

I’ve heard of people doing book clubs specializing in just children’s books and it’s no wonder. The youth – young adult book market has exploded over the past decade or more as every author vies to be the next JK Rowling. Sure, it’s put a lot of crap into circulation, but there are also a lot of extraordinarily creative authors getting published who may not have seemed worth the risk fifteen years ago.

I’ve only just started the Benedict Society this weekend, so I can hardly give a fair review, but as far as I’ve read, I’m enraptured and can’t help but to want to spend my days lying in front of the fire reading.

The App

Image

Big Trak

The app I found today is called ‘Cargo Bot.’ It’s a puzzle game that introduces kids to programming algorithms in a way that they can immediately see working and grasp the concepts. I recommend it for any child (or even adult) interested in learning how computers think. It’s a little reminiscent of the late 70s programmable tank toy, Big Trak, except this app is actually fun for more than two minutes.

Imagine all the fun you can have delivering apples to your dad with your own Big Trak and transported (sold separately)! I thought this thing was the bee’s knees back then, but didn’t ever get my hands on one( it sold for a whopping $43) until much later when my friend Kevin and I were talking and he mentioned that he still had one.

 
1 Comment

Posted by on December 14, 2013 in Uncategorized

 

Tags: , , , , , , , , ,

Two Projects

ImageI’ve been playing with a couple computer projects lately. One is trying to pick up some additional HTML / CSS skills so I can have a little better sense of a big picture with my coding club. To this end, I just got a couple of new books, Head First HTML and CSS    and    Head First PHP and MySQL.

So far, I’ve read through a decent amount of the HTML book, which I can skip through pretty easily if I need to as a lot of it is review. However, what I really do find unique about these texts is that they are both comprehensive and interactive. You need to commit to doing the practice exercises as you go along, but seriously, isn’t this what you’re reading this for anyway?

The other project is an infection model. The first iteration of this is similar to the zombie simulations that several people have created online with the exception of having thee classes of people (vaccinated, unvaccinated and infected). As the people wander around in a user-defined room, they may come in contact with one another. In the event that an infected individual comes into contact with an uninfected, unimmunized person, then that person gets infected.

In the currently functional version I can advance one step at a time where all people randomly move on both axes +1, 0 or -1, then are tested for new infections. The next step is to automate the movement and provide reports including how many people are infected each round.

Eventually, I would like to use this to model the spread of infection across the US (using actual state population and size data) and user- supplied info about immunization and infection rates. A similar program exists on the cdc website that simulates the rate of infection spread in a single population. I would like to cross that with a heterogeneous Imagepopulation (different population densities in each state) specific connectivity of states that could mimic regional outbreaks and ultimately a graphical output (this last will likely never happen, but it’s good to have an ideal in mind).

 
Leave a comment

Posted by on September 20, 2013 in Uncategorized

 

Tags: , , , , , , ,

Now What?

A number of software development courses, such as Codecademy or even traditional university classes, prepares the student to solve problems using their language of choice, but leaves them unprepared to go to the next step.  This next step is to take what you have created and fold it into something free-standing and usable; Something you can share with friends; Something attractively packaged.

My own dilemma is that I have been taking classes and practicing programming C++ on my mac using XCode as my IDE. Now that I have actually created something (a personal summertime project between classes), I want a good way to present my work. Something more attractive and user friendly than the Terminal environment I currently have.

According to apple, my next step is Cocoa. But, what is Cocoa?

Apple defines Cocoa as “Cocoa is an application environment for both the OS X operating system and iOS, the operating system used on Multi-Touch devices such as iPhone, iPad, and iPod touch.” Which could be meaningful… but not very descriptive to me.

Image

                            Hot Cocoa

For anyone familiar with Apple lore, Cocoa was first introduced as NeXTSTEP in 1989: A product of Steve Jobs’ successor company NexT. “You can use several programming languages when developing Cocoa software, but the essential, required language is Objective-C … You can even mix C++ code with your Cocoa code and link the compiled code into the same executable.”  It is this last phrase that gives me hope that I can figure out how to possibly use the work I have don’t so far and weave it (somehow) together with cocoa to add a friendlier appearance to my work. Furthermore, it looks like I could also use Ruby or Python with Cocoa, two languages that I have been working with and find to be somewhat less awkward at times than C++.

So, how to actually put this together: C++ and Cocoa?

            -I’ve been sifting through resources for a couple days now trying to identify some starting point to this without much luck.

-Perhaps this is the wrong way to go about using my C++ code, but is there another way?

 
Leave a comment

Posted by on August 4, 2013 in Uncategorized

 

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

Stack Overflow hates me

ImageI tend to ask a lot of questions that stack overflow considers useless. I understand the format of the site – it’s a place where people can ask questions that can be answered accurately and with references. An easy way to get your question flagged is to ask for a recommendation for something – a question that can only be answered by opinion and therefore does not have a discrete, ‘provable’ answer.

However, I still want my questions answered. I really do need help and I’m not sure where else to turn to get it (to reach such a well experienced audience).

What I am dealing with is:

ImageI have a small C++ program that I have developed in Xcode. Things are pretty close to working, but I would like to take my program and wrap it in a more attractive user  interface. Somehow, I thought I was just needing to learn some more C++. I thought that was all in ‘book 2’ or something. But I am getting the impression that I need another program and I have no idea where to start.

(The layers of programming are amazingly deep)

So, please write if anyone out there knows of

#1 a good program to do this with -or- a way to approach it by linking my C++ programs in XCode to an objective-C interface (blahblah, these are words I can repeat, but I don’t understand how to do it)  

#2 know a website / book / youtube channel that embodies a walkthrough approach to doing this

 
Leave a comment

Posted by on August 2, 2013 in Uncategorized

 

Tags: , , , , , , , , ,

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: , , , , , , , , ,

My own Coding Problem

ImageI’ve been considering a new classroom exercise to describe genetics and the inheritance of alleles within a population. The idea is that every student draws two coins randomly to start – these represent two alleles for a single gene in that organism. Then each student has the opportunity to ‘breed’ with another student to make two offspring. The genetics of the offspring will be determined randomly from that of the parents (something like each parent flips their coins until they get one heads and one tails – the heads from each parent goes to the offspring).

We’ll do this for several generations and track the frequency of alleles through time.

 

OK – now to coding:

I thought this sounded like a simple project that could be simulated easily, so that’s a coding challenge for myself. To start with, I thought I would build the program up bit by bit doing unit testing along the way. At this point I am trying to just set up the parental generation. To do this, I:

1. get input from the user: how many people are playing?

                                          how many different alleles for the gene exist?

2. loop through making ‘User’ objects for each person playing. Each User object has an id number for tracking (idNum) and two alleles determined randomly(alleles[0,1]). I was thinking of keeping my list of users as an array called players[0…10max]

But, I’m stuck already!

I am getting and using my userData with no problem. I think I am even setting up my objects alright and assigning them two randomly determined elements. But instead of those elements being coins (representing alleles), I’m getting the address of a char within the first denomination….

Any help at all is greatly appreciated, but remember – I’m doing this to learn, so I need to be able to understand the solution, not just get it solved.

 

Here’s the code with some debugging output statements:

//

//  main.cpp

//  CoinsLabSimulation

//

//  Created by Jack on 6/27/13.

//  Copyright (c) 2013 Jack Treml. All rights reserved.

//

//A simulation game to test how my coins lab idea will work

#include <iostream>

#include <cmath>

#include <time.h>

using namespace::std;

class User{

private:

    int idNum;

    string alleles[2];

public:

    User(int A){idNum=A;};//int myArray[] = new int[idNum];

    char getAlleles();

    void setAlleles(string, int[]);

};

void getInput(int userInput[]);

void randomAssignment(int userInput[], string denominations[], int players[]);

int main()

{

    srand(time(NULL));

    int userInput[2];

    char p[10] = {“pennies”};   //I hate character arrays / strings in C++

    char n[10] = {“nickels”};   //I want an array of the coins we will use as alleles in this game

    char d[10] = {“dimes”};

    char q[10] = {“quarters”};

    char s[15] = {“SusanBAnthonys”};

    string denominations[5] = {p,n,d,q,s}; //this needs to be fixed so I can call on this array for coin types

    int players[10];

    getInput(userInput);

    cout<<“We will be playing with “<<userInput[0]<<” players and “<<userInput[1]<<” alleles”<<endl;

    cout<<“Alleles used will be:”<<endl;

    for (int i =0; i<userInput[1]; i++) {

        cout<<denominations[i]<<endl;

    }

    randomAssignment(userInput, denominations, players);

    return 0;

} //end main

//*****************non-member functions

void getInput(int usersChoices[]){  //fx to retreive user settings –unit test passed

cout<<“How many players will be participating(10 max)?”<<endl;

cin>>usersChoices[0];

cout<<“How many denominations would you like to use?”<<endl;

cin>>usersChoices[1];

}// end getInput

void randomAssignment(int userNumbers[], string allelesUsed[], int player[]){ //will create user objects and assign each alleles

    //————-   unit test:

    cout<<endl<<endl<<“Unit Test”<<endl;

     cout<<allelesUsed[0]<<”    “<<allelesUsed[3]<<endl<<endl;

    //————-   pass

    User *a[10];

    for (int i=0; i<userNumbers[0]; i++) {

        a[i] = new User(i);

        a[i]->setAlleles(*allelesUsed,userNumbers);  ///trace this

    }

}// end randomAssignment

//******************User Member Methods

void User::setAlleles(string allelesUsed,int userNum[]){

    int max = userNum[1];

    int randomNumber = floor(1 + (rand() % max));

    cout<<“Random number: “<<randomNumber<<endl;

    string allele1 = &allelesUsed[randomNumber];

    randomNumber = floor(1 + (rand() % max));

    cout<<“Random number: “<<randomNumber<<endl;

    string allele2 = &allelesUsed[randomNumber];

    alleles[0] = allele1;

    alleles[1] = allele2;

    //———–unit test2

    cout<<“UNIT TEST2::::Alleles for this player are: “<<allele1<<” and “<<allele2<<endl;

    //———–fail – it’s using the random number as an address within ‘pennies’

    cout<<“Alleles for this player are: “<<alleles[0]<<” and “<<alleles[1]<<endl;

}

char User::getAlleles(){}

————————————————————-

my output looks like this:

How many players will be participating(10 max)?

2

How many denominations would you like to use?

4

We will be playing with 2 players and 4 alleles

Alleles used will be:

pennies

nickels

dimes

quarters

 

 

Unit Test

pennies    quarters

 

Random number: 4

Random number: 2

UNIT TEST2::::Alleles for this player are: ies and nnies

Alleles for this player are: ies and nnies

Random number: 1

Random number: 2

UNIT TEST2::::Alleles for this player are: ennies and nnies

Alleles for this player are: ennies and nnies

 

 

 
1 Comment

Posted by on June 29, 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: , , , , , , , , ,

Winding down Coding Challenge I

ImageI’ve received several entries answering my coding challenge to demonstrate / test Goldbach’s Conjecture that all even numbers > 4 are the sum of two primes. So far python has been the language of choice for entries.

 

I will be closing down this challenge as of June 30 at 11:59pm.

Once I take a look at the entries, I’ll award the prize, a copy of my iBook, In Parts to the winner and post the code here with a walkthrough to show how the problem was tackled as well as any interesting comparisons between entrants.

 
Leave a comment

Posted by on June 26, 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: , , , , , , , ,