Monday, December 24, 2012

Magic hexagon Explained

 
magic hexagon
The numbers in any row of the hexagon above sum to 38,
e.g.   9+14+15,   11+1+7+19,   3+7+5+8+15,
making this a magic hexagon (by analogy to magic squares).

If you already know why this size is the only possible size (outside of the trivial single digit "hexagon"), but aren't content to just take someone's word that no other arrangement (not counting rotations and/or reflections) of integers 1 through 19 is magic--then the C++ program below is for you.

Tom Ace

return to Tom's home page




//  magic hexagon   T. Ace   18 November 2002

#include <stdio.h>

typedef int           i32;

/*   octal indices to the Vals[] and DeriveRules[] arrays:

         variable              contingent                all

        --  --  --             13  14  10             13  14  10
      --  01  02  03         12  --  --  --         12  01  02  03
    --  04  05  06  07     11  --  --  --  --     11  04  05  06  07
      --  --  --  --         15  22  23  16         15  22  23  16
        --  --  --             17  21  20             17  21  20

(I'm not fond of octal; it's just convenient in C/C++ char strings.)  */

static const i32   VAR_COUNT = 7;

// vary the values in positions numbered 1 through VAR_COUNT; all other 
// values are contingent on those, derived in sequence by these rules:

static char   *DeriveRules[20] = {
   (char *) NULL,     // 00 isn't used
   (char *) NULL,     // 01 is not derived
   (char *) NULL,     // 02 is not derived
   (char *) NULL,     // 03 is not derived
   (char *) NULL,     // 04 is not derived
   (char *) NULL,     // 05 is not derived
   (char *) NULL,     // 06 is not derived
   (char *) NULL,     // 07 is not derived
   "\03\07",          // 10   Vals[010] = 38 - Vals[003] - Vals[007]
   "\04\05\06\07",    // 11   ... 
   "\01\02\03",       // 12  
   "\11\12",          // 13
   "\10\13",          // 14
   "\14\01\04",       // 15
   "\14\02\06",       // 16
   "\11\15",          // 17
   "\07\16",          // 20
   "\17\20",          // 21
   "\12\04\21",       // 22
   "\03\06\21"        // 23
};

// CheckRows[] describes the rows whose sums were not already 
// guaranteed by the formulas encoded in DeriveRules[]

static char  *CheckRows[] =
{
   "\15\22\23\16",    // Vals[015] + Vals[022] + Vals[023] + Vals[016] == 38 
   "\13\01\05\23\20", // ...
   "\10\02\05\22\17",
   (char *) NULL      // end marker
};

class Bits32 {
   i32      Data;

public:
   void     Clear()        { Data = 0; }
   void     Set  (i32 N)   { Data |= 1 << N; }
   void     Reset(i32 N)   { Data &= ~(1 << N); }
   bool     Test (i32 N)   { return (Data >> N) & 1; }
};

static i32     Vals[20];
static Bits32  ValsTaken;

static void PrintConfig()
{
   printf("\n"
          "      %3d   %3d   %3d\n"
          "   %3d   %3d   %3d   %3d\n"
          "%3d   %3d   %3d   %3d   %3d\n"
          "   %3d   %3d   %3d   %3d\n"
          "      %3d   %3d   %3d\n\n\n",
          Vals[013], Vals[014], Vals[010],
          Vals[012], Vals[001], Vals[002], Vals[003],
          Vals[011], Vals[004], Vals[005], Vals[006], Vals[007],
          Vals[015], Vals[022], Vals[023], Vals[016],
          Vals[017], Vals[021], Vals[020]);
}

static void InitNVals(i32 N)
{
   // set up the initial configuration of the first N values

   ValsTaken.Clear();
   do {
      Vals[N] = N;
      ValsTaken.Set(N);
   } while (--N > 0);
}

static bool NextNVals(i32 N)
{
   // generate the next configuration of the first N values;
   // return 0 if there are no more

   i32  V = Vals[N];
   ValsTaken.Reset(V);
   do {
      if (V < 19) {
         V++;
      }
      else {
         if (N == 1 || !NextNVals(N - 1)) return 0;
         V = 1;
      }
   } while (ValsTaken.Test(V));
   ValsTaken.Set(V);
   Vals[N] = V;
   return 1;
}

int main(int argc,char **argv)
{
   i32            Count;
   i32            I;
   i32            Index;
   char           *IndexP;
   i32            NewValue;
   char           **Row;
   i32            Sum;
   Bits32         Taken;

   InitNVals(VAR_COUNT);
   Count = 0;

   do {
      Taken = ValsTaken;

      // derive the (19 - VAR_COUNT) contingent values, if possible

      for (I = VAR_COUNT; ++I <= 19; ) {
         NewValue = 38;
         for (IndexP = DeriveRules[I]; (Index = *IndexP) != '\0'; IndexP++) {
            NewValue -= Vals[Index];
         }
         if (NewValue < 1 || NewValue > 19) goto NextConfig;
         if (Taken.Test(NewValue)) goto NextConfig;
         Taken.Set(NewValue);
         Vals[I] = NewValue;
      }

      // DeriveRules guarantees the correct sum in most of the rows; 
      // we now verify the sums in the rows that weren't used in derivations

      for (Row = CheckRows; (IndexP = *Row) != NULL; Row++) {
         Sum = 0;
         for ( ; (Index = *IndexP) != '\0'; IndexP++) {
            Sum += Vals[Index];
         }
         if (Sum != 38) goto NextConfig;
      }

      // magic config found

      PrintConfig();
      Count++;

      NextConfig:;
   } while (NextNVals(VAR_COUNT));

   printf("\n %d magic configurations found   "
          "(expected:  12 rotations/reflections)\n",
          Count);

   return 0;
}





 LINK:
magic hexagon

 http://www.minortriad.com/magichex.html



Mindfulness Explained

 “Feelings come and go like clouds in a windy sky. Conscious breathing is my anchor.”
― Thich Nhat Hanh, Stepping into Freedom: Rules of Monastic Practice for Novices
tags: breath, breathing, feelings, meditation, mindfulness




“Walk as if you are kissing the Earth with your feet.”

― Thich Nhat Hanh, Peace Is Every Step: The Path of Mindfulness in Everyday Life
tags: buddhism, gratitude, joy, mindfulness, zen



“The most fundamental aggression to ourselves, the most fundamental harm we can do to ourselves, is to remain ignorant by not having the courage and the respect to look at ourselves honestly and gently.”

― Pema Chödrön, When Things Fall Apart: Heart Advice for Difficult Times
tags: courage, mindfulness, pain, self-awareness, truth





“Feelings, whether of compassion or irritation, should be welcomed, recognized, and treated on an absolutely equal basis; because both are ourselves. The tangerine I am eating is me. The mustard greens I am planting are me. I plant with all my heart and mind. I clean this teapot with the kind of attention I would have were I giving the baby Buddha or Jesus a bath. Nothing should be treated more carefully than anything else. In mindfulness, compassion, irritation, mustard green plant, and teapot are all sacred.”
― Thich Nhat Hanh, The Miracle of Mindfulness: An Introduction to the Practice of Meditation
tags: mindfulness, miracle, of



“The present moment is filled with joy and happiness. If you are attentive, you will see it
. (21)”
― Thich Nhat Hanh, Peace Is Every Step: The Path of Mindfulness in Everyday Life
tags: attention, happiness, joy, mindfulness, peace, present-moment



 
“In the end, just three things matter:
How well we have lived
How well we have loved
How well we have learned to let go”

― Jack Kornfield
tags: inspirational, mindfulness



“Do not ruin today with mourning tomorrow.”
― Catherynne M. Valente, The Girl Who Circumnavigated Fairyland in a Ship of Her Own Making
tags: mindfulness, philosophy, present-moment





“Do every act of your life as though it were the very last act of your life.”

― Marcus Aurelius, Meditations
tags: act, last, life, mindfulness





“If someone comes along and shoots an arrow into your heart, it’s fruitless to stand there and yell at the person. It would be much better to turn your attention to the fact that there’s an arrow in your heart...”

― Pema Chödrön, Start Where You Are: A Guide to Compassionate Living
tags: awakening, buddhism, mindfulness


“True happiness, we are told, consists in getting out of one's self; but the point is not only to get out - you must stay out; and to stay out you must have some absorbing errand.”

― Henry James, Roderick Hudson
tags: altruism, happiness, mindfulness, philosophy


 
“Be happy in the moment, that's enough. Each moment is all we need, not more.”

― Mother Teresa
tags: happiness, mindfulness, moment




“In this moment, there is plenty of time. In this moment, you are precisely as you should be. In this moment, there is infinite possibility. (
17)”
― Victoria Moran, Younger by the Day: 365 Ways to Rejuvenate Your Body and Revitalize Your Spirit
tags: acceptance, mindfulness, now, possibility, present, this-moment, time







“Few of us ever live in the present. We are forever anticipating what is to come or remembering what has gone.”
― Louis L'Amour
tags: life, mindfulness, present



“Don't believe everything you think. Thoughts are just that - thoughts.”

― Allan Lokos, Pocket Peace: Effective Practices for Enlightened Living
tags: compassion, illusion, mindfulness, reality, thinking, thoughts, wisdom



“[T[his isn’t just “another day, another dollar.” It’s more like “another day, another miracle.”
― Victoria Moran, Lit From Within: Tending Your Soul For Lifelong Beauty
tags: appreciation, daily-living, life, mindfulness, miracles, perspective



“Suffering usually relates to wanting things to be different from the way they are.”

― Allan Lokos, Pocket Peace: Effective Practices for Enlightened Living
tags: buddhism, health, inspiration, inspirational, mindfulness, suffering



“One is a great deal less anxious if one feels perfectly free to be anxious, and the same may be said of guilt.”

― Alan Wilson Watts, Psychotherapy East and West
tags: mindfulness, psychology


“Respond; don't react.
Listen; don't talk.
Think; don't assume.”

― Raji Lukkoor
tags: inspirational, meditation, mindfulness



“You cannot control the results, only your actions.”

― Allan Lokos, Patience: The Art of Peaceful Living
tags: buddhism, compassion, insight, karma, meditation, mindfulness





“Don’t let a day go by without asking who you are…each time you let a new ingredient to enter your awareness.”

― Deepak Chopra, The Book of Secrets: Unlocking the Hidden Dimensions of Your Life
tags: awareness, identity, mindfulness, spirituality



“In a true you-and-I relationship, we are present mindfully, nonintrusively, the way we are present with things in nature.We do not tell a birch tree it should be more like an elm. We face it with no agenda, only an appreciation that becomes participation: 'I love looking at this birch' becomes 'I am this birch' and then 'I and this birch are opening to a mystery that transcends and holds us both.”

― David Richo, When the Past Is Present: Healing the Emotional Wounds that Sabotage our Relationships
tags: mindfulness, mystery, relationship



“Mindfulness is simply being aware of what is happening right now without wishing it were different; enjoying the pleasant without holding on when it changes (which it will); being with the unpleasant without fearing it will always be this way (which it won’t).”
– James Baraz”
― James Baraz



“You have to remember one life, one death–this one! To enter fully the day, the hour, the moment whether it appears as life or death, whether we catch it on the inbreath or outbreath, requires only a moment, this moment. And along with it all the mindfulness we can muster, and each stage of our ongoing birth, and the confident joy of our inherent luminosity.”

― Stephen Levine, A Year to Live: How to Live This Year as If It Were Your Last
tags: confidence, death, joy, life, mindfulness, rebirth, reincarnation

 

“Whatever you eye falls on - for it will fall on what you love - will lead you to the questions of your life, the questions that are incumbent upon you to answer, because that is how the mind works in concert with the eye. The things of this world draw us where we need to go.”

― Mary Rose O'Reilley, The Barn at the End of the World: The Apprenticeship of a Quaker, Buddhist Shepherd
tags: desire, mindfulness, objects, questions






“You might be tempted to avoid the messiness of daily living for the tranquility of stillness and peacefulness. This of course would be an attachment to stillness, and like any strong attachment, it leads to delusion. It arrests development and short-circuits the cultivation of wisdom.”

― Jon Kabat-Zinn, Wherever You Go, There You Are
tags: evolving, life, mindfulness, peace



“If you’re reading these words, perhaps it’s because something has kicked open the door for you, and you’re ready to embrace change. It isn’t enough to appreciate change from afar, or only in the abstract, or as something that can happen to other people but not to you. We need to create change for ourselves, in a workable way, as part of our everyday lives.”

― Sharon Salzberg, The Power of Meditation: A 28-Day Programme for Real Happiness
tags: buddhism, change, inspiration, meditation, mindfulness, wisdom




“It stands to reason that anyone who learns to live well will die well. The skills are the same: being present in the moment, and humble, and brave, and keeping a sense of humor. ”

― Victoria Moran, Younger by the Day: 365 Ways to Rejuvenate Your Body and Revitalize Your Spirit
tags: bravery, dying, humility, humor, living, mindfulness, present-moment, sense-of-humor



“When even one virtue becomes our nature, the mind becomes clean and tranquil. Then there is no need to practice meditation; we will automatically be meditating always.”
― Swami Satchidananda, The Yoga Sutras
tags: meditation, mindfulness, tranquility, virtue



“Each place is the right place--the place where I now am can be a sacred space.”

― Ravi Ravindra, The Wisdom of Patanjali's Yoga Sutras: A New Translation and Guide by Ravi Ravindra
tags: mindfulness, sacred-space, space




“As we encounter new experiences with a mindful and wise attention, we discover that one of three things will happen to our new experience: it will go away, it will stay the same, or it will get more intense. whever happens does not really matter.”

― Jack Kornfield, A Path with Heart: A Guide Through the Perils and Promises of Spiritual Life
tags: mindfulness




“Meditation is the ultimate mobile device; you can use it anywhere, anytime, unobtrusively.”

― Sharon Salzberg, Real Happiness: The Power of Meditation
tags: compassion, health, meditation, mind-training, mindfulness, social-media, technology




“With mind distracted, never thinking, "Death is coming,"
To slave away on the pointless business of mundane life,
And then to come out empty--it is a tragic error.

trans by Robert Thurman”
― Huston Smith, Tibetan Book of the Dead
tags: death, error, life, mindfulness



“Patience has all the time it needs.”
― Allan Lokos, Patience: The Art of Peaceful Living
tags: buddhism, compassion, mindfulness


“Inner Peace can be seen as the ultimate benefit of practicing patience.”

― Allan Lokos, Patience: The Art of Peaceful Living
tags: buddhism, mindfulness, psychology-spirituality



“One doesn't have to be religious to lead a moral life or attain wisdom.”

― Allan Lokos, Pocket Peace: Effective Practices for Enlightened Living
tags: buddhism, health, inspiration, mindfulness



“It's good to have an end in mind but in the end what counts is how you travel.”

― Orna Ross
tags: life-and-living, mindfulness



“Do not speak about anyone who is not physically present.”

― Allan Lokos, Pocket Peace: Effective Practices for Enlightened Living
tags: inspiration, inspirational, meditation, mindfulness




“Mindfulness, also called wise attention, helps us see what we’re adding to our experiences, not only during meditation sessions but also elsewhere.”
― Sharon Salzberg, Real Happiness: The Power of Meditation
tags: buddhism, compassion, inspiration, mindfulness



“The mind which is created quick to love, is responsive to everything that is pleasing, soon as by pleasure it is awakened into activity. Your apprehensive faculty draws an impression from a real object, and unfolds it within you, so that it makes the mind turn thereto. And if, being turned, it inclines towards it, that inclination is love; that is nature, which through pleasure is bound anew within you.”

― Dante Alighieri, The Divine Comedy
tags: love, mindfulness



“. . . I feel we don’t really need scriptures. The entire life is an open book, a scripture. Read it. Learn while digging a pit or chopping some wood or cooking some food. If you can’t learn from your daily activities, how are you going to understand the scriptures?”
― Swami Satchidananda, The Yoga Sutras
tags: learning, living, mindfulness, scriptures


“Restore your attention or bring it to a new level by dramatically slowing down whatever you're doing.”

― Sharon Salzberg, Real Happiness: The Power of Meditation
tags: buddhism, healing, health, meditation, mindfulness


 
“True compassion is undirected &amp; holds no conceptual focus. That kind of genuine, true compassion is only possible after realizing emptiness.”

― Tsoknyi Rinpoche, Carefree Dignity: Discourses on Training in the Nature of Mind
tags: buddhism, mind-training, mindfulness




“Mindfulness isn't difficult, we just need to remember to do it.”

― Sharon Salzberg, Real Happiness: The Power of Meditation
tags: health, meditation, mindfulness, psychology




“All beings want to be happy, yet so very few know how. It is out of ignorance that any of us cause suffering, for ourselves or for others”

― Sharon Salzberg, Lovingkindness: The Revolutionary Art of Happiness
tags: buddhism, mindfulness, psychology, suffering
 



“Yoga practice can make us more and more sensitive to subtler and subtler sensations in the body. Paying attention to and staying with finer and finer sensations within the body is one of the surest ways to steady the wandering mind.”

― Ravi Ravindra, The Wisdom of Patanjali's Yoga Sutras: A New Translation and Guide by Ravi Ravindra
tags: body, mind, mindfulness, practice, yoga





“Looking beauty in the world, is the first step of purifying the mind.”

― Amit Ray
tags: inspirational, mindfulness



“Mindfulness has never met a cognition it didn't like.”

― Daniel J. Siegel, The Mindful Brain: Reflection and Attunement in the Cultivation of Well-Being
tags: buddhism, mindfulness, psychology






“Like a child standing in a beautiful park with his eyes shut tight, there's no need to imagine trees, flowers, deer, birds, and sky; we merely need to open our eyes and realize what is already here, who we already are - as soon as we stop pretending we're small or unholy.”
― Bo Lozoff
tags: being-present, mindfulness, reality




“We use mindfulness to observe the way we cling to pleasant experiences &amp; push away unpleasant ones.”

― Sharon Salzberg, Real Happiness: The Power of Meditation
tags: buddhism, compassion, meditation, mindfulness




“A bird cried jubilation. In that moment they lived long. All minor motions were stilled and only the great ones were perceived. Beneath them the earth turned, singing.”

― Sheri S. Tepper, The Revenants
tags: life, mindfulness








Kate Bush - Nocturn - Eat me. Drink me. - YouTube


Published on Dec 8, 2011
 
Kate Bush - Nocturn Eat me. Drink me.
Alice's Adventures in Wonderland - The Royal Ballet





Kate Bush - Nocturn - Eat me. Drink me. - YouTube