Monthly Archives: June 2013

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{


    int idNum;

    string alleles[2];


    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()



    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];


    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++) {



    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;


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


}// 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)?


How many denominations would you like to use?


We will be playing with 2 players and 4 alleles

Alleles used will be:







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


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

Getting Oxygen Where It’s Needed

Oxygen is required by many organisms for survival, luckily it is plentiful in the air, but how does it get into all the tiny cells all over the body?

periodicFirst, Oxygen is a highly electronegative atom. This means that it attracts electrons very well and can pull them away from other molecules. Only one other atom is more electronegative and that’s the most reactive element in the periodic table, Fluorine. Electronegativity becomes useful biologically because electrons are capable to storing energy that can be passed along from one molecule to the next. But , to do this, each molecule must be more electronegative than the last. Therefore, it is not surprising that Oxygen is used as the final electron acceptor in the electron transport chain of cellular respiration. This reaction is required by many organisms, and can be highly beneficial even to some organisms that can live without Oxygen. An electron transport chain is a process by which molecules in a membrane pass en electron down the line using its energy in a controlled way to extract even more energy from sugar.

But how does Oxygen get to the cells that need it? Two molecules account for much of this action, myoglobin and hemoglobin, both illustrated below:


Hb- hemoglobin, Mb-myoglobin.

What this image also elegantly portrays is the amazing similarity between the molecules that belies their evolutionary relationship.

Each of these molecules is capable of binding Oxygen, but each occurs in a different tissue. ImageHemoglobin is present in Red Blood Cells, making them capable of transporting oxygen from the lungs to other tissues. Myoglobin occurs in these ‘other’ tissues, particularly muscle cells.

Despite the fact that they both bind oxygen, they do not bind it equally well under all conditions. While hemoglobin is just as good at binding Oxygen in high concentration environments (like the lung after inhalation), it is not as good at retaining oxygen when found in less Oxygen-rich environments (such as tissues like muscle).  Under these conditions, myoglobin is much better at binding Oxygen and can pull the molecules away from hemoglobin.

Recently, several groups have published new data about how subtle differences amongst proteins involved in Oxygen transport through blood and muscle result in different binding properties. In turn, the variability in these properties underlie the amazing diversity of lifestyles found in nature, from humans to birds to giant whales capable of holding their breath for up to an hour.

Image That brings us back to the electron transport chain and Oxygen’s electronegativity, where Ois used as a ‘magnet’ for the electron traveling down the pathway from one molecule to the next. As it goes it loses some of its energy, which is converted into a new form that the cell can use. Once the electron, now at a lower energy state, gets to O2, the Oxygen splits  and takes up a Hydrogen ion to form water.

So, electronegativity and binding affinity are the forces that both transport Oxygen through the body and pulls electrons from one molecule to another. Together, the movement of electrons, like that of water through a mill, powers processes that lead to the synthesis of ATP, the energy currency of the cell (see below).



Note the electron traveling down the chain (in pink)

Given what we’ve discussed here, how do you think a baby ever gets to pull the Oxygen away from its mother’s blood / hemoglobin?


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

A cute video about the beginning of time

From the Ted Ed site:

“How did the universe begin — and how is it expanding? CERN physicist Tom Whyntie shows how cosmologists and particle physicists explore these questions by replicating the heat, energy, and activity of the first few seconds of our universe, from right after the Big Bang.”

Lesson by Tom Whyntie, animation by Hornet Inc

Leave a comment

Posted by on June 24, 2013 in Uncategorized


Tags: , , , , , , , ,

Old Aviary at KC Zoo



In the middle of a rapidly growing zoo sits this unused, overgrown structure. Reminds me of Logan’s Run.

Leave a comment

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