Pages

13 May 2013

we're all cranks-in-waiting

So I read this article, linked to on this Slashdot article which prompted me to post this on my G+ account.

Easy to Crank

Earlier this morning it occurred to me that I was behaving in the manner of a crank. I was acting as if my inexpert opinion counted as much as the opinions of those who've studied and practiced computer programming much of, if not most, of their careers.

Additionally, it doesn't seem to take much to turn one into a crank.

Aside:

I still can't stop futzing with the code.



#include <stdio.h>

int fizz_buzz(int num)
{
        int m1 = 3, m2 = 5, f = 0;

        if (num % m1 == 0) {
                f = 1;
        }

        if (num % m2 == 0) {
                f = f + 2;
        }

        return(f);
}

int main() 
{
        int max = 100, n = 1;
        char s1[] = "fizz", s2[] = "buzz";

        while (n <= max) {
                switch (fizz_buzz(n)) {
                        case 1:
                                printf("%s", s1);
                                break;
                        case 2:
                                printf("%s", s2);
                                break;
                        case 3:
                                printf("%s%s", s1, s2);
                                break;
                        default:
                                printf("%d", n);
                                break;
                }
                
                printf("\n");
                n++;
        }
        return 0;
}

30 March 2013

learning fortran

I've decided that a person with a science degree is probably lacking if s?he doesn't know a bit of Fortran, so I've taken the liberty of teaching myself by following the tutorial available a Fortran Tutorial. I ran into a bit of a snag on Exercise 6.3 on the Subroutines and Functions lesson. For some reason I couldn't get the subroutine to work the way I wanted. I knew the algorithm for the finite difference matrix itself was correct, but it kept crashing on me

I'm using gfortran on both my workstation and on my android device, but they both seem to work differently when it comes to arrays and fortran procedural programming and I think gcc on my android is broken. This only made things more frustrating for me, so I began to do a lot of reading on Fortran 95 and how it handles arrays, functions and the like while trying things out.

Happily, I was able to figure it out but it only works on my workstation. It's too bad the gcc android port I'm using is broken, I'll have to find a replacement. Anyhow, here is the code I was able to cobble together. Try not to be too critical.


program exercise6_3
    !print out a finite difference matrix using a function
    implicit none
    integer :: row, col, length
    integer, allocatable, dimension(:,:) :: matrix 
    print *, 'How big is your nxn matrix?'
    read *, length

    allocate(matrix(length, length))
    call d_matrix(length, matrix)

    do row = 1, length
          write(*, 10) (matrix(row, col), col = 1, length)
    end do

    10 format(100i2)

    deallocate(matrix)

    end program exercise6_3

    subroutine d_matrix(count, array)
    !finite difference matrix
        implicit none
        integer :: count, m
        integer, dimension(count,count) :: array
        !array dimensions must be specified

        array = 0
        do m = 1, count
              array(m, m) = 2
              if ( m /= count ) then
                    array(m, m + 1) = -1
                    array(m + 1, m) = -1
                end if
        end do

        end subroutine d_matrix

19 March 2013

fun with a basic algorithm

On Twitter Ed announced that he was playing around with a BASIC program that ran on the venerable Commodore 64. I myself am not a professional programmer, but I've taken several programming courses and have played with code from time to time. I fondly remember programming instructions in BASIC or Pascal on the school computers and was always a bit saddened that my home didn't have one for our personal use.

Naturally, Ed posting about 10 PRINT made me curious. Since I run OpenBSD on my workstation I don't have a native version of BASIC, but I do have a C compiler in the form of GCC. So I set out to port "10 PRINT" in C.

10 PRINT

The Code

10 PRINT CHR$(205.5+RND(1)); : GOTO 10

10 PRINT Output - Frodo C64 Emulator

My First Porting Attempts

The variant of UNIX that I doesn't have the PETSCII character set that the Commodore 64 uses in the 10 PRINT program. As a result my first attempts used the slash "/" and the backslash "\" characters from the standard ASCII library.

maze.c


/* auto maze generator */

#include <stdio.h>
#include <stdlib.h>

/* print to screen the backslash or forward
 * slash depending if the value of i is
 * odd or even. */

int main (int argc, char *argv[])
{
        do {
                int i = random();

                if ( i%2 == 0 )
                        printf ("\\");
                else
                        printf ("/");

        } while ( 1 );

        return 0;
}

maze1.c


/* auto maze generator, mk1 */

#include <stdio.h>
#include <stdlib.h>

/* determine if the number passed is
 * odd or even and return result. */

int odd_even (number)
        int number;
{
        if ( number % 2 == 0)
                return 0;
        else
                return 1;
}

/* print the forward slash or backslash
 * depending on returned result. */

int main (int argc, char *argv[])
{
        do {
                int i = random();

                if ( odd_even(i) == 0 )
                        printf ("\\");
                else
                        printf ("/");

        } while ( 1 );

        return 0;
}

maze2.c


/* auto maze generator, mk3 */

#include <stdio.h>
#include <stdlib.h>

/* print to screen the backslash or forward
 * slash depending if the value of i is
 * odd or even. */

int main (int argc, char *argv[]){do {int i = random();if (i%2==0) printf("\\");else printf("/");}while(1);return 0;}

Output of First Attempts

My Following Attempts

I wasn't satisfied with the use of slash and back slash to build the output. While using slash and backslash approximated the output of 10 PRINT somewhat, it was obvious that the approximation was lacking. Fortunately, it turns out that Unicode has a solution that more approximates the diagonal lines used in PETSCII. The right leaning line has the Unicode symbol

0x2571
and the left leaning line has the symbol
0x2572
in C. So, using those symbols I modified my code accordingly. I also used an terminal emulator that was capable of rendering the Unicode symbols I was using to view my output, in this case Gnome Terminal.

maze4.c


/* auto maze generator, mk4 */

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>

/* print the forward slash or backslash
 * depending on returned result. */

int main (int argc, char *argv[])
{
        char *locale;
        locale = setlocale (LC_CTYPE, "en_US.UTF-8");
        int i;

        while (1) {
                wprintf (L"%lc", (i = 2571.5 + arc4random_uniform(2), i == 2571) ? L'\x2571' : L'\x2572');
        }

        printf ("\n");

        return 0;
}

maze5.c


/* auto maze generator, mk5 */

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>

/* Adds a value 0 < x < 1 to passed float
 * value and return an integer. */

int find_value (given)
        float given;
{
        given = given + arc4random_uniform(2);
        return (given);
}

/* print the forward slash or backslash
 * depending on returned result. */

int main (int argc, char *argv[])
{
        char *locale;
        locale = setlocale (LC_CTYPE, "en_US.UTF-8");
        int i;

        while (1) {
                wprintf (L"%lc", (i = find_value(2571.5), i == 2571) ? L'\x2571' : L'\x2572');
        }

        printf ("\n");

        return 0;
}

Output of Following Attempts

Thoughts

I find the original algorithm in C64 BASIC interesting for a couple of reasons.

  1. The entire script is one line.
  2. The script uses a 'goto' statement.
  3. The script takes advantage of how characters are defined in PETSCII

If I were to do this properly in C I would either have to have a similar set of characters that I could call on, or I would have to call on C's graphical abilities and define line segments for various values in the algorithm.

The fact that there are two opposing slash characters in Unicode that are numerically adjacent to each other is fortuitous. I don't know if the spec for Unicode came before 10 PRINT and PETSCII or after, but I suspect that if it's the latter then perhaps the designers were influenced by 10 PRINT? This is something that I may have to look into a bit, just to satisfy my curiosity.

19 February 2013

fossil fuel interests and funding of climate change denial groups

>Peter Sinclair of "Climate Denial Crock of the Week", 19 February 2013.

Mr Sinclair has posted a new blog about a recent peer reviewed study titled Study Links Tobacco, Tea Party, Climate Denial,… and Fox News. The verifiable, peer reviewed evidence against the fossil fuel interests continues to build.

06 January 2013

Christmas Vacation 2012

Today we tore down the Christmas Tree (Holiday Tree?) The kids wanted the lights on and the activity rode into their bedtime. Now I'm left to finish the tear down on my own.

As I work on the tree, and indeed over the past several weeks, my thoughts were haunted by the realization that things were different this year. You see, my father passed away in August and this was the first year we were all celebrating without him.

Normally I find myself growing excited with anticipation as Christmas approaches, but this year I had a hard time finding that anticipation and excitement. I could see that my kids felt it but I could also see that my wife was struggling as much as myself.

Overall, we had a good vacation; we saw friends and family, some whom we haven't seen in years. My mom was holding up well though I'm sure it has been hardest on her. My sisters and their families did their best to make our visit with them memorable and happy.

What Christmas means to me has changed several times in my life and such a change occurred again this year. To me Christmas is another opportunity in a world of missed opportunities to spend time with your loved ones while they're still here and still exist. May you find opportunities throughout the year to have those you cherish near you.

21 September 2012

more meanderings on atheism plus

I've been giving things a bit more thought and I think I have a more coherent take on Atheism Plus. Yesterday was the first time I ran across the term "Atheist Plus" and the turmoil it seemed to have caused some people.

Atheism Plus' Causes

First let's break down some of the causes listed by Atheism Plus, just so we are all talking about the same thing. I'm probably oversimplifying some of the causes here but please bear with me.

Atheism

A person is an atheist if they do not believe in a god. In strict terms this means a lack of belief in any god. That's it.

Care for Social Justice

Action to have a lack of justice in our society that disadvantages or harms others rectified.

Support Women's Rights

Action to have women treated as equals to men and to protect women from being harmed or disadvantaged simply for being female.

Protest Racism

Action to have people of all races treated as equal and protect any one race from being harmed or disadvantaged simply for being of that race.

Fight Homophobia and Transphobia

Action to have homosexuals and transexuals treated as equals to heterosexuals and to protect them from being harmed or disadvantaged simply for not being hetrosexual.

Use Critical Thinking and Skepticism

Actively using logic and evidence in order to make rational decisions about claims in order to protect oneself from accepting falsehoods.

Atheism WRT Causes

Some people contend that the above causes are natural outcomes of atheism. I'm not so inclined to agree. Lacking a belief in a god does not make one more likely to support these causes than would having a belief in said god.

If you support the above causes it's because you believe in supporting those causes for one reason or another. Certainly, most good people support one or more of the above be they theist or atheist.

Conversely, supporting one or more of these causes doesn't mean one is an atheist either. Possibly being involved with these causes may cause one to see things that will challenge one's faith, but it doesn't guarantee deconversion.

A Bit About Myself

I am a skeptic and critical thinker, I care about social justice, I support women's rights, I am against racism and I support Homosexuals and Transexuals in their cause for equality. I support the climate scientists and other environmental scientists in their fight against the forces of antiscience and corporate greed.

I'm also an atheist, none of the above causes increase or decrease my status as such. By Atheism Plus' Charter I could possibly be a member, but I don't know if I feel the need for another label.

Certainly, I think that any atheist involved in any of the above causes, where it's reasonably safe to do so*, should let the people they're working with know that they're atheist. Similarly, other atheists should support each other if they're working in these causes. Atheists should make it known when other atheists (again, when it's reasonably safe to do so*) are working in such causes so that the general public knows that many atheists are concerned about these things.

I think Atheism Plus is a good idea, but I don't know if it's necessary or even if it'll work. When Atheism Plus started there were some divisionary comments made, but to be fair they came from both sides. There have been atheists on both sides that haven't made things better and there are examples where atheists on both sides have been trying.

In the meantime, I'll keep reading, watching and listening. All the best whether you are an Atheist Plus member or not.

*Sometimes the atheist involved might have his or her safety compromised if the people they work with know they're atheists. Even if there aren't safety issues sometimes there are personal issues that could be complicated if one's atheism is exposed, especially if one isn't ready.

20 September 2012

what the heck is atheism plus

(Please note that the following should be taken with a large helping of NaCl. I'm still researching Atheism + and lot of my ideas about it are still forming. I may have a totally new perspective on Atheism + come tomorrow.)

This is What Happens When You're Out of The Loop

c0nc0rdance posted the following video.

Apparently Atheism + (formally Atheism Plus) is causing some consternation among atheists. So, just what is Atheism +?

Declaration of Atheism+ on Ftb

The bloggers at FtB started the Atheism +. Richard Carrier posted an artcle Jen McCreight posted an article describing Atheism +.

In summary, Atheism + is:

We are…
Atheists plus we care about social justice,
Atheists plus we support women’s rights,
Atheists plus we protest racism,
Atheists plus we fight homophobia and transphobia,
Atheists plus we use critical thinking and skepticism.

Frankly, these are worthwhile goals. Personally, I'd put critical thinking and skepticism at the top as it was critical thinking and skepticism that lead me out of theism. When I think "atheist" I tend to think "naturalist" and "skeptic". I digress.

That said, let me examine these one-by-one from my own limited perspective on the whole Atheism + issue.

  • Social Justice: I'm very concerned about issues like social justice. I see social issues around me all of the time and I do what I can when I can. However, someone not being concerned about social issues, or even denying social issues doesn't make one less an atheist. Uneducated perhaps, maybe ineducable in others, but not any less an atheist.
  • Women's Rights: I consider myself a feminist. I have a wife that I love and who faces challenges in the working world simply for being female. I have three little girls and I worry about what kind of future they'll have. Women's issues weigh heavily in my life and it's important to me that the women in my life have equal opportunities and support. Again, even atheists that are misogynist pigs are still atheists. I agree that currently misogyny is the more pervasive and insidious of the two, but misandry exists and can't be ignored either.
  • Racism: Again, an issue I see around me all of the time. Again, atheists that are racists are still atheists.
  • Homophobia and Transphobia: Another prevalent issue. Same as above.
  • Critical Thinking and Skepticism: Important skills to have, but many atheists aren't critical thinkers or skeptics. In fact, there exist superstitious and even religious atheists. They just don't believe in gods.

All of these issues are good, but what if one is an atheist and otherwise a very good person, except they fall short on one area? What if this atheist were a homophobe, or racist? Is every good thing they've done undone?

If these issues are important than one shouldn't be afraid to correct or admonish the individual in question. One could state how they think others should interact with this person if they don't change. From what I've seen so far, atheists who don't conform to Atheism +'s ideals seem to get quite strongly attacked (by the movement?).

Conclusion

Currently I have none. I'm still reading and trying to figure out what Atheism + means to me, if anything. Now you'll probably want some water from eating all of that salt. :-)