#!/bin/sh
#  If you don't got ksh, delete the 'k' above.
#
# NOTE: The MBTI Temperament Sorter questions and answers are 
#       copyrighted and use thereof is limited to one copy per
#       person for the purpose of personal research, this material
#       is presented for this purpose ONLY.  Any other use may 
#       subject the user to penalties under copyright law.
#
#   The script itself is in the public domain.  AWF
#   My employer has no knowledge of and has given no approval for
#       this script: it is the result of personal research and is 
#       presented here to aid you in your personal research. AWF
#       
#  The Keirsey Temperament Sorter 
#  (a Myers Briggs Type Indicator test)
#  Taken from _Please_Understand_Me,_Character_&_Temperament_Types
#       by David Keirsey and Marilyn Bates
#       ISBN 0-9606954-0-0
rnsd=`date +"%S%M%H`
awk -F';' ' BEGIN {i=0;askd[0]="yes"}
{   i+=1;
    ques[i] = $2;
    ansa[i] = $3;
    ansb[i] = $4;
    askd[i] = "no";
}
END {srand(rnsd);
    for (j=1;j<=i;j++)
    {   k=0;
        while (askd[k] != "no")
        {   k = int (rand * (i+1)) ;
            #printf "%3d  %s\n",k,askd[k];
        }                              
        askd[k] = "yes"
        
        # the following "if" prints the answers in proper order about 1/2 the
        #   time and swaps answer a and b for the other half.
        # OK, so I am an INFP and the "proper" answer for me is "b" -- always.
        # I want to repeat this test over time without biasing myself, by
        # randomly reversing the a answer with the b, I can read the answers
        # without and automatic "b is me" prejudice.  (yeah, I am weird).
        if ((rand * 2) > 1)
        {   printf "\n\n%s\n(A) %s\n(B) %s\n[A or B]? ",ques[k],ansa[k],ansb[k];
            getline answ <"/dev/tty" ;
            resp[k] = "xx" ;
            if (answ ~ /A/ || answ ~ /a/)
            {   resp[k] = "A" ;
            }
            if (answ ~ /B/ || answ ~ /b/)
            {   resp[k] = "   B" ;
            }
        }
        else
        {   printf "\n\n%s\n(A) %s\n(B) %s\n[A or B]? ",ques[k],ansb[k],ansa[k];
            getline answ <"/dev/tty" ;
            resp[k] = "xx" ;
            if (answ ~ /A/ || answ ~ /a/)
            {   resp[k] = "   B" ;
            }
            if (answ ~ /B/ || answ ~ /b/)
            {   resp[k] = "A" ;
            }
        }


    }
    
    line_separator = "********************************************************************************"

    colcount = 1;
    print line_separator ;
    printf ("\n\n                     KEIRSEY TEMPERAMENT SORTER Score Card\n") ; 
    for (j=1;j<=i;j++)
    {   printf ("%3d :%-4s  ",j,resp[j]);
        if (colcount++ >= 7)
        {   colcount = 1;
            printf ("\n");
        }
    }
    
    #default to type XXXX
    type_EI = "X" ;
    type_SN = "X" ;
    type_TF = "X" ;
    type_JP = "X" ;

    # Calculate E/I factor
    ans_E = 0;
    ans_I = 0;
    for (j=1;j<=i;j+=7)
    {   if (resp[j] == "A")
            ans_E++ ;
        if (resp[j] == "   B")
            ans_I++ ;
    }
    if (ans_E > ans_I)
        type_EI = "E"
    if (ans_E < ans_I)
        type_EI = "I"

    # Calculate S/N factor
    ans_S = 0;
    ans_N = 0;
    ans_Sa = 0;
    ans_Na = 0;
    ans_Sb = 0;
    ans_Nb = 0;
    for (j=3;j<=i;j+=7)
    {   if (resp[j] == "A")
            ans_Sb++ ;
        if (resp[j] == "   B")
            ans_Nb++ ;
        if (resp[j-1] == "A")
            ans_Sa++ ;
        if (resp[j-1] == "   B")
            ans_Na++ ;
    }
    ans_S = ans_Sa + ans_Sb ;
    ans_N = ans_Na + ans_Nb ;
    if (ans_S > ans_N)
        type_SN = "S"
    if (ans_S < ans_N)
        type_SN = "N"

    # Calculate T/F factor
    ans_T = 0;
    ans_F = 0;
    ans_Ta = 0;
    ans_Fa = 0;
    ans_Tb = 0;
    ans_Fb = 0;
    for (j=5;j<=i;j+=7)
    {   if (resp[j] == "A")
            ans_Tb++ ;
        if (resp[j] == "   B")
            ans_Fb++ ;
        if (resp[j-1] == "A")
            ans_Ta++ ;
        if (resp[j-1] == "   B")
            ans_Fa++ ;
    }
    ans_T = ans_Ta + ans_Tb ;
    ans_F = ans_Fa + ans_Fb ;
    if (ans_T > ans_F)
        type_TF = "T"
    if (ans_T < ans_F)
        type_TF = "F"

    # Calculate J/P factor
    ans_J = 0;
    ans_P = 0;
    ans_Ja = 0;
    ans_Pa = 0;
    ans_Jb = 0;
    ans_Pb = 0;
    for (j=7;j<=i;j+=7)
    {   if (resp[j] == "A")
            ans_Jb++ ;
        if (resp[j] == "   B")
            ans_Pb++ ;
        if (resp[j-1] == "A")
            ans_Ja++ ;
        if (resp[j-1] == "   B")
            ans_Pa++ ;
    }
    ans_J = ans_Ja + ans_Jb ;
    ans_P = ans_Pa + ans_Pb ;
    if (ans_J > ans_P)
        type_JP = "J"
    if (ans_J < ans_P)
        type_JP = "P"

    MBTI = type_EI type_SN type_TF type_JP ;

    printf ("    %2d %2d",ans_E,ans_I);
    printf ("      %2d %2d      %2d %2d",ans_Sa,ans_Na,ans_Sb,ans_Nb);
    printf ("      %2d %2d      %2d %2d",ans_Ta,ans_Fa,ans_Tb,ans_Fb);
    printf ("      %2d %2d      %2d %2d\n",ans_Ja,ans_Pa,ans_Jb,ans_Pb);

    printf ("     |  |       ^--^----->%2d %2d",ans_Sa,ans_Na);
    printf ("       ^--^----->%2d %2d",ans_Ta,ans_Fa);
    printf ("       ^--^----->%2d %2d\n",ans_Ja,ans_Pa);

    printf ("    %2d %2d",ans_E,ans_I);
    printf ("                 %2d %2d",ans_S,ans_N);
    printf ("                 %2d %2d",ans_T,ans_F);
    printf ("                 %2d %2d\n",ans_J,ans_P);

    printf ("     E  I");
    printf ("                  S  N");
    printf ("                  T  F");
    printf ("                  J  P\n");

    printf ("\n\n%s\n",line_separator);

    printf ("%16s: Relative Strength\n","Characteristic");

    printf ("%16s:","Extrovert");
    for (j=1;j<=ans_E;j++)
        printf("******");
    printf ("\n");

    printf ("%16s:","Introvert");
    for (j=1;j<=ans_I;j++)
        printf("******");
    printf ("\n");
    printf ("\n");

    printf ("%16s:","Sensing");
    for (j=1;j<=ans_S;j++)
        printf("***");
    printf ("\n");

    printf ("%16s:","iNtuitive");
    for (j=1;j<=ans_N;j++)
        printf("***");
    printf ("\n");
    printf ("\n");

    printf ("%16s:","Thinking");
    for (j=1;j<=ans_T;j++)
        printf("***");
    printf ("\n");

    printf ("%16s:","Feeling");
    for (j=1;j<=ans_F;j++)
        printf("***");
    printf ("\n");
    printf ("\n");

    printf ("%16s:","Judging");
    for (j=1;j<=ans_J;j++)
        printf("***");
    printf ("\n");

    printf ("%16s:","Perceiving");
    for (j=1;j<=ans_P;j++)
        printf("***");
    printf ("\n");
    printf ("\n");

    printf ("\nYour personality type is %s: ",MBTI);
                  
    if (MBTI == "ESFJ") 
    {   printf ("The Seller.\n");
    }
    else
    if (MBTI == "ISFJ") 
    {   printf ("The Conservator.\n");
    }
    else
    if (MBTI == "ESFP") 
    {   printf ("The Entertainer.\n");
    }
    else
    if (MBTI == "ISFP") 
    {   printf ("The Artist.\n");
    }
    else
    if (MBTI == "ESTJ") 
    {   printf ("The Administrator.\n");
    }
    else
    if (MBTI == "ISTJ") 
    {   printf ("The Trustee.\n");
    }
    else
    if (MBTI == "ESTP") 
    {   printf ("The Promotor.\n");
    }
    else
    if (MBTI == "ISTP") 
    {   printf ("The Artisan.\n");
    }
    else
    if (MBTI == "INTP")
    {   printf ("The Architect.\n");
    }
    else
    if (MBTI == "ENTP")
    {   printf ("The Inventor.\n");
    }
    else
    if (MBTI == "INTJ") 
    {   printf ("The Scientist.\n");
    }
    else
    if (MBTI == "ENTJ") 
    {   printf ("The Fieldmarshal.\n");
    }
    else
    if (MBTI == "ENFP") 
    {   printf ("The Journalist.\n");
    }
    else
    if (MBTI == "INFJ") 
    {   printf ("The Author.\n");
    }
    else
    if (MBTI == "ENFJ") 
    {   printf ("The Pedagogue.\n");
    }
    else
    if (MBTI == "INFP") 
    {   printf ("The Questor.\n");
    }

    printf ("\n");

    if (type_EI=="E")
        printf ("Extroverted -- \"re-charge\" by interaction with others.\n");
    else
        if (type_EI=="I")
            printf ("Introverted -- \"re-charge\" by being with few or no others.\n");
        else
            printf ("Extroverted & Introverted\n");

    if (type_SN=="S")
        printf ("Sensory -- focus on specific details from the 5 senses.\n");
    else
        if (type_SN=="N")
            printf ("iNtuitive -- focus on important items, ignore irrelevant details.\n");
        else
            printf ("Sensory & iNtuitive\n");

    if (type_TF=="T")
        printf ("Thinking -- logical, rule based approach.\n");
    else
        if (type_TF=="F")
            printf ("Feeling -- sympathetic approach.\n");
        else
            printf ("Thinking & Feeling\n");

    if (type_JP=="J")
        printf ("Judging -- want decisions finalized.\n");
    else
        if (type_JP=="P")
            printf ("Perceptive -- want to understand the issue.\n");
        else
            printf ("Judging & Perceptive.\n");

    printf ("\n");   
    print line_separator ;
}
' rnsd=$rnsd  <<!
1;At a party do you;interact with many, including strangers;interact with a few, known to you
2;Are you more;realistic than speculative;speculative than realistic
3;Is it worse to;have your "head in the clouds";be "in a rut"
4;Are you more impressed by;principles;emotions
5;Are you more drawn toward the;convincing;touching
6;Do you prefer to work;to deadlines;just "whenever"
7;Do you tend to choose;rather carefully;somewhat impulsively
8;At parties do you;stay late, with increasing energy;leave early, with decreased energy
9;Are you more attracted to;sensible people;imaginative people
10;Are you more interested in;what is actual;what is possible
11;In judging others are you more swayed by;laws than circumstances;circumstances than laws
12;In approaching others is your inclination to be somewhat;objective;personal
13;Are you more;punctual;leisurely
14;Does it bother you more having things;incomplete;completed
15;In your social groups do you;keep abreast of other's happenings;get behind on the news
16;In doing ordinary things are you more likely to;do it the usual way;do it your own way
17;Writers should;"say what they mean and mean what they say";express things more by use of analogy
18;Which appeals to you more;consistency of thought;harmonious human relationships
19;Are you more comfortable in making;logical judgments;value judgments
20;Do you want things;settled and decided;unsettled and undecided
21;Would you say you are more;serious and determined;easy-going
22;In phoning do you;rarely question that it will all be said;rehearse what you'll say
23;Facts;"speak for themselves";illustrate principles
24;Are visionaries;somewhat annoying;rather fascinating
25;Are you more often;a cool-headed person;a warm-hearted person
26;Is it worse to be;unjust;merciless
27;Should one usually let events occur;by careful selection and choice;randomly and by chance
28;Do you feel better about;having purchased;having the option to buy
29;In company do you;initiate conversation;wait to be approached
30;Common sense is;rarely questionable;frequently questionable
31;Children often do not;make themselves useful enough;exercise their fantasy enough
32;In making decisions do you feel more comfortable with;standards;feelings
33;Are you more;firm than gentle;gentle than firm
34;Which is more admirable:;the ability to organize and be methodical;the ability to adapt and make do
35;Do you put more value on the;definite;open-ended
36;Does new and non-routine interaction with others;stimulate and energize you;tax your reserves
37;Are you more frequently;a practical sort of person;a fanciful sort of person
38;Are you more likely to;see how others are useful;see how others see
39;Which is more satisfying:;to discuss an issue thoroughly;to arrive at agreement on an issue
40;Which rules you more:;your head;your heart
41;Are you more comfortable with work that is;contracted;done on a casual basis
42;Do you tend to look for;the orderly;whatever turns up
43;Do you prefer;many friends with brief contact;a few friends with more lengthy contact
44;Do you go more by;facts;principles
45;Are you more interested in;production and distribution;design and research
46;Which is more of a compliment:;"There is a very logical person.";"There is a very sentimental person."
47;Do you value in yourself more that you are;unwavering;devoted
48;Do you more often prefer the;final and unalterable statement;tentative and preliminary statement
49;Are you more comfortable;after a decision;before a decision
50;Do you;speak easily and at length with strangers;find little to say to strangers
51;Are you more likely to trust your;experience;hunch
52;Do you feel;more practical than ingenious;more ingenious than practical
53;Which person is more to be complimented: one of;clear reason;strong feeling
54;Are you more inclined to be;fair-minded;sympathetic
55;Is it preferable mostly to;make sure things are arranged;just let things happen
56;In relationships should most things be;renegotiable;random and circumstantial
57;When the phone rings do you;hasten to get to it first;hope someone else will answer
58;Do you prize more in yourself;a strong sense of reality;a vivid imagination
59;Are you drawn more to;fundamentals;overtones
60;Which seems the greater error:;to be too passionate;to be too objective
61;Do you see yourself as basically;hard-headed;soft-hearted
62;Which situation appeals to you more;the structured and scheduled;the unstructured and unscheduled
63;Are you a person that is more;routinized than whimsical;whimsical than routinized
64;Are you more inclined to be;easy to approach;somewhat reserved
65;In writings do you prefer;the more literal;the more figurative
66;Is it harder for you to;identify with others;utilize others
67;Which do you wish more for yourself:;clarity of reason;strength of compassion
68;Which is the greater fault:;being indiscriminate;being critical
69;Do you prefer the;planned event;unplanned event
70;Do you tend to be more;deliberate than spontaneous;spontaneous than deliberate
!

echo "#  The Keirsey Temperament Sorter "
echo "#  (a Myers Briggs Type Indicator test)"
echo "#  Taken from _Please_Understand_Me,_Character_&_Temperament_Types"
echo "#       by David Keirsey and Marilyn Bates"
echo "#       ISBN 0-9606954-0-0"
echo "#  Provided for your personal research of the topic under "
echo "#    fair use doctrine.  The person copying this file is"
echo "#    fully responsible for compliance with applicable copyright"
echo "#    laws."
echo "#  IF YOU AE WILLING TO BE LISTED IN THE MBTI DIRECTORY, at the next"
echo "#  athena prompt, type the following:"
echo "# "
echo "# athena% mhmail dagoura -body \"<yourfirstname> <yourlastname>: <MBTI score>\" "
