Showing posts with label for. Show all posts
Showing posts with label for. Show all posts

Tuesday, August 27, 2013

Rules for success

This just came into my head, and I think it's worth writing down.

What are the rules for success? I know what #1 is: Don't be stupid. How about the rest?

Rules for Success
  1. Don't be stupid
  2. Set Reasonable Goal
  3. Make Plan
  4. Do Plan
  5. Adjust previous steps until done
  6. Success!!!

And well, that's all there is to it. Of course, the devil is in the details, but as long as you can follow these steps, I think you'll be fine. :)

Monday, October 1, 2012

Petit Computer Journal #9


Petit Computer Journal #9

Loops and Banner

A quick diversion here, I want to discuss a little bit about loops. We have been doing it, and it's not hard to do, but that doesn't mean people understand them completely. I keep seeing people do things in inefficient ways. I know I'm bucking the convention here, but I think making the program work the way you want it is the minimum requirement. You should also improve the program in such a way that it is well structured, implemented, and clear.

So, what's so hard about loops? Nothing. That's why it's important for you to master loops. There are several kinds:

1. Infinite loop: This is easy. You basically want to repeat something over and over. Most C programmers would use this construct:

while (1) { ... }

That's an infinite loop. But I think this is the case where GOTO is better. Here it is in Smile BASIC:

@LOOP
...
GOTO @LOOP

And that's it for infinite loop. It's good for use as IDLE loop.

2. REPEAT-UNTIL loop: Also known as DO-WHILE, this is just like infinite loop, but it ends when there is a certain condition to be met. You can do it like this:

@LOOP
...
IF (NUM

or this

@LOOP
...
IF !(NUM>=MAXNUM) GOTO @LOOP

or this

FOR I=1 TO 1:VSYNC 1:I=BTRIG():NEXT

That last example is basically "Press any BUTTON to continue". It works because as long as I is zero, the loop repeats.

Another example of REPEAT-LOOP would be this program in finding out the value of PI using fraction:

'PI
N1=3:N2=1
R1=ABS(PI()-(N1/N2))

FOR I=1 TO 1
R2=(ABS(PI()-(N1/N2)))
IF (N1/N2)
IF (N1/N2)>PI() THEN N2=N2+1
I=!R2:'TERMINATE WHEN I==0.

IF R2
NEXT

?PI()
?(N1/N2)

The structure is similar to HI-LO game, and it's a good exercise for you to do in order to see if you understand the concept. In the meantime, if you see the statement I=!R2 where R2 is fraction, we can say that I'm abusing ! operator to the max!

Haha, joking aside, I do tend to push the interpreter beyond standard convention. It takes a lot of trial and error, with mostly error on the result. But you can't argue that the result is good.

3. WHILE-WEND loop: This loop differs from REPEAT-UNTIL loop by the fact that the code may not be executed at least once. By putting the condition on top of the loop, the whole code may be skipped.

@LOOP
IF (NUM>=MAXNUM) GOTO ENDLOOP
...
GOTO @LOOP
@ENDLOOP

or this

@LOOP
GOTO @ENDLOOP
...
@ENDLOOP
IF (NUM

or this MADLIBS example

A$="HELLO [N]. HOWDY [N]. GOODBYE [N]."
LINPUT "NAME";N$
T$="[N]"

@WHILE LOOP
FOR I=0 TO INSTR(A$,T$)
A$=SUBST$(A$,INSTR(A$,T$),LEN(T$),N$)
NEXT
?A$

Yes, it's that easy! See explanation on FOR-LOOP on how this works.

4. FOR-LOOP. The standard BASIC loop. The workhorse loop of BASIC. How difficult can it be? It's just like WHILE loop, except the value of I is incremented within the code. Smile BASIC will not execute the loop when the parameters do not match, such as this:

FOR I=0 TO -1 STEP 1

I took advantage of this fact by putting INSTR() directly on the loop declaration. You don't see "STEP 1" written out, but it is implied. If you need stepping other than 1, then you need to write it out. STEP 4, STEP -1, and so on.

NUM=0
@LOOP
IF (NUM>MAXNUM) GOTO ENDLOOP
...
NUM=NUM+1:'OR NUM=NUM+N WHERE N IS THE STEP VALUE
GOTO @LOOP
@ENDLOOP

FOR NUM=0 TO MAXNUM: ... :NEXT

And that's it for LOOP structures. There is a couple more things we need to talk about. BREAK and CONTINUE.

CONTINUE is the way for the loop to skip processing to the next step. That is, whatever we want to do, we're done! We don't want to do any more.

@LOOP
...
IF CONTINUE GOTO LOOP
...
GOTO @LOOP

Let's do an example with FOR loop. Let's say we want to skip displaying vowels. We can do this:

A$="HELLO SAILOR!"
FOR I=0 TO LEN(A$)-1
IF INSTR("AEIOU",MID$(A$,I,1))>=0 THEN NEXT
? MID$(A$,I,1);
NEXT
?:?"DONE!"

Yes, you have two NEXT statements in there. The NEXT on IF line functions as CONTINUE. Pretty easy, right? (1)

BREAK, however, is not so easy. Not that it's difficult to understand, but it's difficult to implement because we cannot GOTO out of LOOP. Or maybe we can, but I don't quite understand how it works exactly despite my numerous experiments. So, we won't GOTO out of FOR loop.

@LOOP
...
IF BREAK GOTO @ENDLOOP
...
GOTO @LOOP
@ENDLOOP

That's it. Just breaking out of the loop cycle. Now let's see it with FOR loop.

A$="HELLO SAILOR!"
FOR I=0 TO LEN(A$)-1
IF INSTR(" ",MID$(A$,I,1))>=0 THEN I=LEN(A$):GOTO @ENDLOOP:'NEXT
? MID$(A$,I,1);
@ENDLOOP
NEXT
?:?"I=";I

You can see immediately that the structure isn't good. We have to use GOTO @ENDLOOP, instead of a simple NEXT because the program will return to the line of execution, resulting NEXT without FOR error. We have to put the label @ENDLOOP in separate line. The value of I is 14, which may not be what we want. In all, BREAKing out of loop isn't a good solution with this BASIC.

SAMPLE PROGRAM: TOUCH SCREEN KEYBOARD
@TOUCH
MX=256:MY=192:'MAXX,MAXY
SX=8:SY=6:'SPANX,SPANY
WX=FLOOR(MX/SX):WY=FLOOR(MY/SY):'WIDTHX,WIDTHY
TX=TCHX:TY=TCHY
FOR I=1 TO TCHST
IF TX
VSYNC 1:GFILL 0,0,MX,MY,0:GFILL KX*WX,KY*WY,(KX+1)*WX,(KY+1)*WY,8
LOCATE 0,0:?"KX=";KX;"  KY=";KY;"   "
NEXT
GOTO @TOUCH

Here is a simple way to divide the screen to rectangular areas.
MAXX,MAXY = SCREEN AREA/KEYBOARD SIZE
SPANX,SPANY=NUMBER OF KEYSPAN X,Y
WIDTHX,WIDTHY=INTERNAL VALUES USED FOR DRAWING
KX and KY =THE VALUE IN SPANX,SPANY THAT DENOTES ACTIVE CELL

If you look at FOR I=1 TO TCHST code, you maybe forgiven to think that it is a loop. It's not a loop. It is a multi-line IF, which is something Petit Computer does not support. It works in this case, but it's a special case.


SAMPLE PROGRAM: BANNER

Here is an example of nested loop. That is, loop within loop structure. It is also an example of GPUTCHR, where I'm using it for fine scrolling and zooming technique.

@ASKB
ACLS
LINPUT "MESSAGE 1/3?";B1$
LINPUT "MESSAGE 2/3?";B2$
LINPUT "MESSAGE 3/3?";B3$
B$="      "+B1$+B2$+B3$+"      "
ACLS

@LOOP
FOR I=1 TO LEN(B$)-5
FOR X=63 TO 0 STEP -4
VSYNC 1:IF BTRIG() THEN GOTO @ASKB
GCLS
FOR J=-1 TO 3:GPUTCHAR X+(J*64),40,"BGF0",ASC(MID$(B$,I+J,1)),0,8:NEXT
NEXT
NEXT
GOTO @LOOP

The sharp eyes among you will see that I did GOTO out of FOR loop with GOTO @ASKB. How does that work? Isn't GOTO out of loop is bad? Yes, it is. I don't understand it myself. It seems to work fine in this case, but I still discourage its use. Good for demos, but please don't use it for professional programs.

'HI-LO
S=RND(100)+1
FOR I=1 TO 1
INPUT "GUESS A NUMBER(1-99)";N
IF N>S THEN ?"TOO HIGH"
IF N
I=!ABS(N-S)
NEXT
?"CORRECT!"

'HI-LO
S=RND(100)+1
@LOOP
INPUT "GUESS A NUMBER(1-99)";N
IF N>S THEN ?"TOO HIGH"
IF N
IF N==S THEN ?"CORRECT!":END
GOTO @LOOP





(1) BTW, even though the CONTINUE looks fine, you have to be careful that you don't end the loop at CONTINUE, because the loop will end there and you will get NEXT without FOR error. There is the reason why I end the string with "!" when the condition only checks for vowels. That's being sneaky, and it's all right for you to do it, but do document it. Try adding exclamation mark at INSTR:

A$="HELLO SAILOR!"
FOR I=0 TO LEN(A$)-1
IF INSTR("AEIOU!",MID$(A$,I,1))>=0 THEN NEXT
? MID$(A$,I,1);
NEXT
?:?"DONE!"



Wednesday, July 11, 2012

Nasty People


Have you ever tried to have an argument with a totally unreasonable person? Very frustrating, wasn't it? Yet, it happens all the time. This last one was absolutely horrible, and when I was reflecting upon it, the full extent of horror revealed itself, and it's not pretty.

First of all, I will refer to have read a certain kind of BOOK. Specifically, Anthony Weston's A Rulebook for Argument. It is a small, concise guide to have a reasonable argument. It also details a few logical fallacies that unreasonable people love to use. I tell everybody to read it and use it. So far, no luck.

There are 2 people involved here, I will mention person A and person B. This is not the complete conversation. I remove certain passages, especially near the end, due to ramblings and decency. I do preserve the lines as much as possible.

Person A: Solving the problem of unaffordable healthcare by requiring everyone to buy healthcare is like trying to solve homelessness by requiring everyone to buy a home.

Me: We already did that with SS retirement. I wonder why they didn't just extend Medicare for everybody. 30% admin fee of insurance for care adds up to a lot of money! I sure want to buy cheap, government back health care than expensive private ones.

Person A: Cheap government healthcare will turn into rationed government healthcare.....no thanks

[So far so good. I agree with Person A. Cheap government healthcare = rationed healthcare. I don't like it either, but that's what we have right now with Medicare. I pay money into it, and it's rationed to 65 years old or older, and only hospital stay unless you want to pay extra for MediGap.]

Person B: Ya want expensive healthcare? It's coming soon....... Government run healthcare isn't free....WE WILL PAY FOR IT>>>>>> DUH !

[This is the unreasonable person. You can tell right away by his tone of voice. "Ya want" instead of "You want", "DUH" which implies that what he says is common knowledge. (ad populus) This has all the superiority complex written all over it.]

[His claim (even though he phrased it as a question) that I want expensive Health Care is false. I specifically mentioned that I want cheap health care. What is wrong with this guy? Does he somehow equates "I want cheap" into "I want expensive"? I'm surprised he didn't say "rationed healthcare" is "unlimited healthcare". Same logic. Why did he pick on me?]

[So we have several statements:
False statement: You want expensive healthcare.
Maybe False statement: It's coming soon.
True, but irrelevant statement: Government run healthcare isn't free.
False statement: We will pay for it.
]

Me: We WILL pay for it? Last time I check they take out Medicare from my paycheck. We are paying for it now! I think Person A is right. Rationed is much more probable. Take a look at VA hospital situation if you want to see how it goes.

[I concentrate on the last statement. When somebody blatantly twisted my word into his own agenda, I don't bother. It's bottomless misery. This knowledge is gained by hard experience. Some people don't care about the truth. They just want to pick a fight with somebody for no reason.]

[I mention Medicare tax, which this person has been paying, but somehow completely ignore the fact. Ignoring clear facts when it invalidates your claims isn't a good trait to have. A normal person would have apologized for this oversight.]

Person B: I meant we are going to pay MORE.........way more, those of us that work that is. He said it would reduce healthcare costs, and steadily it has risen for all policies.

[He didn't apologize. Also notice a new line of reasoning coming out of nowhere: "He said it..." Who's he? None of the text above mentioned anybody claiming to reduce healthcare costs. This is an unexpected jab from the left field. Notice how he put in statement that may be true, but totally irrelevant? This trick on putting in irrelevant materials is an old trick that posers use. By "posers", I mean people who pretends to be somebody else, usually a much better person that the poser. In my experience, this process will take anywhere between 30-45 minutes to exhausts itself. In the meantime, said poser will have covered anything and everything under the sun...except the relevant topic.

Dubious claim: I meant we are going to pay WAY MORE.
There are several factors here.
1. The implicit agreement that right now, we aren't paying a lot, or at least reasonable fee.
2. That sometime in the future, the fee will radically increase.
3. Congress will do nothing to prevent this from happening.
4. Healthcare will have runaway cost, and that isn't happening right now.

I can tell you that there is a lot of grumbling right now that health insurance costs are climbing rather high. But they are all in the private sector side. The government side is still on the cheap side, just not available (being rationed).

However, his statement did pique my interest. A few questions comes to mind: How much more this will get? How soon will this happen? and What is the probability/confidence factor of this happening within that said time frame and level?Whenever somebody say "MUCH, MUCH more", I always ask "How much more EXACTLY?"
]

Me: Road tax < Toll Road fee. State College < Private College. I don't see how you can say Government Health Care will cost more than private ones. [snip] As far as paying more, that's a given. But how much more compared with privatization? Have you any resource to back your statement or are you going by unconfirmed hearsay?

Person B: [sarcasm deleted] Please name me one Government Institution that is efficient or cost saving, [snip] Rationing? You and the government can keep it, I don't want any part of it. Costs are going up now, my friends that pay for it tell me so.[snip] As most Democrats feel....believe everything you hear him say and none of what you see with your own eyes. Hope America wakes up before it's too late. Car companies, college tuition, now me and my doctor.....keep the change.

[I am having trouble following this train of thought. He was rambling, especially at the end. It gives me headache to try to follow through his reasoning. Read that last sentence again, and if you can decipher the meaning, please tell me. I can't make any sense out of it. Here goes:"Car companies, college tuition, now me and my doctor.....keep the change."

Basically, there are several nouns, followed by an imperative "keep the change". I don't see the connection at all. There is no verb. What is he trying to say? Looking at the preceding sentence "Hope America wakes up" didn't help. The sentence before that didn't help either. I believe he simply regurgitate random things, literally. Why? I don't know. But some curmudgeon likes to do that for no reason.

Insult: Please name me one Government Institution that is efficient or cost saving
The order of the sentences is correct. I gave him TWO examples how government is more efficient than private institution, and he followed by asking me to give him ONE example. Unless you are a contestant in Jeopardy!, it is considered extremely rude to follow up an answer with the question! This is a blatant attempt to erase my statement. This may work on unrecorded conversation, but on message board for all to see, this is just silliness.

False claim: Rationing? You and the government can keep it, I don't want any part of it.
What makes you think I want rationing? In fact, this statement "I wonder why they didn't just extend Medicare for everybody." actually shows that I DO NOT want rationing. I simply agreed with Person A that rationing is likely. I never endorse it. By falsely claiming that I want it, he makes it look like I'm some ignorant fool. This is an indirect attack on me. In my experience, this is what somebody does when he wants to do personal attack in an attempt to discredit a person. Very difficult to defend in normal face-to-face conversation. With recorded text? It can easily be shown false.

Hearsay: Costs are going up now, my friends that pay for it tell me so.
Yes, that is hearsay. Unless you can tell me exactly how much costs are going up, I'm going to call it hearsay. Anyway my statement "As far as paying more, that's a given. But how much more compared with privatization?" has just been tossed away. I already said that costs are going up. Why is he saying costs are going up, AFTER I said costs are going up? This is just like asking the question after getting the answer. Another insult. Also notice that he never answered my question: HOW MUCH MORE?

False statement: As most Democrats feel....believe everything you hear him say and none of what you see with your own eyes.
This God-like attribute is usually connected with Obama, but notice that he never mention the name? In any case, I'm not a Democrat. I'm an Independent. Notice how he randomly assign labels on me? This is so that he can claim that I am a sheep, blindly obeying somebody's statement, which is not true at all. This labeling is blatant attempt to manipulate opinions, which if you haven't read THE BOOK, is very effective.
]

Person B: Cheap government healthcare hehehehe, think again.

[I don't see how he can make this statement. Go back to the beginning. Specifically:
Me: We WILL pay for it? Last time I check they take out Medicare from my paycheck. We are paying for it now! I think Person A is right. Rationed is much more probable. Take a look at VA hospital situation if you want to see how it goes.
Person B: I meant we are going to pay MORE.........way more,

The previous exchange has shown that we have cheap government health care right now! It's called Medicare! Hello? Does he just randomly toss statements left and right without thinking whatsoever? Oh, what am I talking about? Of course he does!

Me: Gosh, you are so negative. You don't want this. You don't want that. Are you some kind of old curmudgeon? Because, as I see it, you ARE going by unconfirmed hearsay.

Person B: I wouldn't call my personal experiences with the VA as "hearsay". Another democrat argument, when you can't win the argument just start calling people names....... And personally, your opinion of me is less than meaningless. [sarcasm deleted]

[This is another misdirection. Typical of ramblings and/or deflection when it comes to the truth. Notice another democrat labeling. 
Misdirection: I wouldn't call my personal experiences with the VA as "hearsay" 
Nor did I say that. I was referring specifically to your friends' claim, of which you never actually see the figure yourself.

Leading: Another democrat argument,
False accusation: when you can't win the argument just start calling people names
Interesting that he says that, because I have shown that he's the one losing the argument, mostly because he's rambling. I also notice that he use the "Democrat" label on me. Do I call him names? Nope. I did ASK A QUESTION, whether or not he's a curmudgeon.

As to the question, he could have answered these way:
1. No, and here's why... I'd probably believe him.
2. Yes, and I'm sorry. I'd probably forgive him.
3. Not answer at all. It'll be an open question.
He didn't do any of that. What he did was:
4. Rambling, misdirection, heavy sarcasm and insults - which is exactly what a genuine curmudgeon would do.
]

At this point I knew that further communication is meaningless. Not because I lost the argument, but because he is being unreasonable, unwilling to listen, and unwilling to be wrong. He's insulting, and blames his defects on me. I do not need to consult a dictionary to understand that "less than meaningless" are words designed to hurt, not communicate. I could have said a lot of nasty things, but I didn't. I did pull out my computer to confirm my initial assessment of him, just because my blood boils. It was confirmed.

Me: Curmudgeon status: Confirmed. I have better things to do. Bye now! :)

Later on, Person A intercede on Person B behalf.

Person A: Calling Person B a curmudgeon is like calling a turd a rose. Nothing could be further from the truth. Simply having a negative opinion about something does not a curmudgeon make.[snip] I am all for good debates, but let us please be respectful with no name calling. That, to me, is a sign of losing an argument.

[Oh great. Another idiot in the art of rhetoric. Why can't people read THE BOOK?!
I have laid down the foundations why I think Person B fits a curmudgeon, and all that is ignored in favor of only one thing: a negative opinion. 

Are you kidding, Person A? Do you not read what was written? It's more than that!

This got snipped, but his claim that VA will not help Person B's cancer may be accurate, but insurance or no, private hospitals are required to help a person regardless of money. It just means Person B will be paying for it for the rest of his life.
]

Me: So, then, when Person B is calling me a Democrat, even though I'm Unaffiliated Independent, does that mean he's losing the argument? I'm not so stupid as not to know what hearsay/insult/sarcasm is. Sometimes good message can be sour, if the delivery is done poorly. Until Person B can clean up his language, I will keep calling him a curmudgeon, and rightly so.

Person A: so let me get this straight, you use a computer program to determine whether someone is negative or annoying? [snip] as far as calling you a democrat, I believe he is pointing out that you calling names instead of proving your point or providing facts is a typical tactic of many democrats. Just because someone may not be able to deliver the message in a flourish of brilliant verbage, does not automatically make their argument null. [snip]

[
Hidden assumption: so let me get this straight, you use a computer program to determine whether someone is negative or annoying?
I didn't realize this at first, but there is a hidden assumption here.

There are two possibilities:
1. What happened: I felt insulted. Anger has a way to distort perception. To be fair, I use objective calculation. Thus, I confirm my initial perception with a computer.
2. What is assumed: I am stupid. I therefore subject my will to a 2 bit machine to tell me what to do.

If you know me, then you know that assuming #2 is a GREAT INSULT to me, and if I stop at un-friend you at facebook, consider yourself very, very lucky!
]

[as far as calling you a democrat, I believe he is pointing out that you calling names instead of proving your point or providing facts is a typical tactic of many democrats.

Sigh. This statement is why I think we are premature in withdrawing flexible leather strap as educational implement, since I believe he needs one. But since we are in Modern times, let me just say this:


"You quack like a duck, sir. Not that I'm labeling you a duck, or calling you a duck. But you look like a duck, act like a duck, and quack like a duck!"

Get it?

I noticed he failed to mention Person B employed that very tactic!
]

Me: Yes, I use a computer. How else would you know the truth? Yes, rationed health care like Canada and VA aren't good. Do you somehow miss that? Very annoying to be criticized for believing something you don't believe. I don't believe that's a mark of a good man. You don't do that, Person A. Why is Person B doing that to me? He doesn't have to be brilliant (isn't that a straw man argument?), just not insulting or ignoring facts. Look, do me a favor and read Anthony Weston's A rulebook for Argument. If after readling it, you still think Person B is not being insulting, I will take your word. How's that?

[Here I was referring to Person B's constant derisions/ignorance, but I am too polite in these matters.]

Person A: I will leave it at this. No computer program is going to show intent. One of the problems with FB is that intent, tone and personal contact are missing. I do know Person B, and insulting is not his intent I am sure, however his experience sure carries a lot of weight with me. we are not all professional debaters, just people trying to make our way through.

[
1. I will leave it at this. No computer program is going to show intent.
This is when I suspect there is a hidden assumption.

2.  One of the problems with FB is that intent, tone and personal contact are missing.
True enough. But it doesn't take a genius to notice that his vocabulary changes. Also, the constant misdirection cannot be misinterpreted either.

3. Hearsay: I do know Person B, and insulting is not his intent I am sure, however his experience sure carries a lot of weight with me.
Did you ask Person B to make sure? No? Hearsay.

4. we are not all professional debaters, just people trying to make our way through.
This is a polite way of saying he will never read THE BOOK. Got it loud and clear, buddy. Sigh.

]

Me: That is true. And I will take your word that Person B has no intention to insult me. Then again, I have insulted many people *unintentionally*. So will you accept the fact that Person B may have insulted me unintentionally? When there is strong clashes of opinions, that is when I use the program to see who is the most opiniated. It works.

[
Even at this late term, I'm still willing to forgive Person B's transgressions. The hope, of course, that Person A will tell Person B that he has insulted me unintentionally, and apologize for it. 

Well, so far that hasn't happened. There is only one conclusion, then. Person B *intentionally* insulted me. Looking at the exchanges above, I don't see how it can be interpreted differently.
]

[
When there is strong clashes of opinions, that is when I use the program to see who is the most opiniated. It works.
I said this just to clarify which of the two assumption applies.
]



Alright. What do we have here?
Person A is reasonable, and accurate, even though he hasn't read THE BOOK. Person B is an old irascible grump, who has no qualms of ignoring facts, deriding people, twisting words, make false and ridiculous assumptions, and generally misleading people.

He also makes claims that are vague and generic, the kinds that cannot be fingered as false. Obviously, he cannot stand criticism. He cannot handle being wrong.

He also is willing to blame his defects on other people, as to make his faults other people, thus shifting the spotlight of blame away from himself.

Wait a minute.

This feels familiar.

Where have I seen this pattern before?

Ah.

I have it!

Here are the patterns:
1. Unwilling to listen
2. Unwilling to be wrong
3. Blames his defects upon other people
4. Drag in any irrelevant subjects to the discussion
5. Scream, yell, and behave abusively. (throwing tantrum)

We didn't exactly get to step 5, but all the signs point there.

The pattern fits that of Invalidators, as described by Jay Carter, in his book "Nasty People." Go read it. Go read THE BOOK, and go read this book.

Nasty People. Invalidators. Figures. Sigh.
Person B=Invalidator.

To Person B:
Now that I know what you are, I hope you understand that the time of forgiveness is past, and that any future attempt to apologize will be seen as deceitful manipulation attempt on your part. Go read Nasty People book for explanation. Thank you for understanding, and sorry that this happened.