Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Odd order Magic square with 0 Determinant

3 views
Skip to first unread message

Libra/Virgo

unread,
Nov 1, 2009, 10:21:24 AM11/1/09
to
# Use it from top level of repository, and specify name one
# or more patches you wish to see webrevs of.
#
# Implementation
# --------------
# It works by it takes a temporary clone of the parent repository, and
pushes
# patches up to the specified patch in the series. Then, using a list
of the
# files the specified patch modifies, it copies these to a new
temporary repository.
#
# This new (probably small) repository is then cloned, and the same
list of
# files from the current repository are copied to this repo and
committed.
#
# Finally, we invoke webrev on this temporary repository against it's
# parent.

REAL_CHILD=$(pwd)

# FIXME need to make sure this version of hg has support for "qgoto"
HG=/usr/bin/hg
QUIET="-q"
# setting this to a non-empty string makes the script emit more
messages
DEBUG=""
# XXX hardcoding the path to webrev here is probably wrong
WEBREV=/ws/onnv-tools/onbld/bin/webrev

# write an awk script that can print deleted and added files
# from a given patch
function write_deleteadd_script {

cat > /tmp/patch_webrev.$$.awk <<EOF
#!/bin/nawk -f

# This awk scripts patch files, printing which files were
# added and deleted from the new area.

# An example record:

#diff --git a/newfile b/newfile
#new file mode 100644
#--- /dev/null
#+++ b/newfile
#@@ -0,0 +1,1 @@
#@diff --git a/deleteme b/deleteme
#deleted file mode 100644
#--- a/deleteme
#+++ /dev/null
#@@ -1,1 +0,0 @@

BEGIN {
seen_deleted=0
seen_added=0
}

/^deleted file mode [0-9]+\$/ {
seen_deleted=1
# set \$0 to be the next line
getline
}

/^new file mode [0-9]+\$/ {
seen_added=1
# set \$0 to be 2 lines further down
getline
getline
}

{
if (seen_added==1){
added_file=\$NF
len=length(added_file)
print "added "substr(added_file,3,len-2)
seen_added=0
}

if (seen_deleted==1){
deleted_file=\$NF
len=length(deleted_file)
print "deleted "substr(deleted_file,3,len-2)
seen_deleted=0
}
}
EOF
chmod 755 /tmp/patch_webrev.$$.awk
}

function usage {
echo "patch-webrev.ksh <patch> [ <patch2> <patch2> ... patchn>"
exit 1
}

function log_debug {
if [ -n "$DEBUG" ] ; then
echo $@
fi
}


# print a list of files that given patch modifies
function changed_files {
ws=$1
patch=$2
if [ ! -f $ws/.hg/patches/$patch ]
then
echo "ERROR changed_files() unable to find $ws/.hg/patches/$patch"
exit 1
fi
LIST=$(/usr/xpg4/bin/grep -e +++ -e --- $ws/.hg/patches/$patch \
| awk '{print $2}' | sed -e 's,^a/,,g;s,^b/,,g' | grep -v /dev/null
| sort -u)
echo $LIST
}

# print a list of files that a given patch deletes
function deleted_files {
ws=$1
patch=$2
echo $(cat $ws/.hg/patches/$patch | /tmp/patch_webrev.$$.awk | grep
"^deleted " | awk '{print $2}')
}

# print a list of files that a given patch adds
function added_files {
ws=$1
patch=$2
echo $(cat $ws/.hg/patches/$patch | /tmp/patch_webrev.$$.awk | grep
"^added " | awk '{print $2}')
}

if [ $# -lt 1 ] ; then
usage
fi

MODIFIED=$($HG status | /usr/xpg4/bin/grep -e ^M -e^\\?)
if [ -n "$MODIFIED" ]
then
echo "WARNING: uncommitted changes $MODIFIED appear in $REAL_CHILD"
fi


OUTGOING_DESC=$($HG -R ${REAL_CHILD}/.hg/patches outgoing --template
'{desc}')
if [ -z "${OUTGOING_DESC}" ]
then
echo "ERROR: no outgoing changes in ${REAL_CHILD}/.hg/patches"
exit 1
fi

# quick sanity check
for PATCH in $@ ; do
if [ ! -f .hg/patches/$PATCH ]
then
echo "Unable to find $REAL_CHILD/.hg/patches/$PATCH"
echo "Are you running this script from the top of the
workspace?"
exit 1
fi
done

# get the parent gate
PARENT=$( $HG paths | grep default | awk -F= '{print $2}' | sed -e 's/
^ //g')


TMP=/tmp/patch-webrev.$$
mkdir -p $TMP
mkdir $TMP/parent
cd $TMP/parent
$HG $QUIET init

log_debug "Making a qclone of $PARENT to $TMP/real-parent.hg"
$HG $QUIET qclone $PARENT $TMP/real-parent.hg

cd $REAL_CHILD
for PATCH in $@ ; do
CHANGED_FILES=$(changed_files $REAL_CHILD $PATCH)

cd $TMP/real-parent.hg
log_debug "going to $PATCH in $TMP/real-parent.hg"
$HG $QUIET qgoto $PATCH
if [ $? -ne 0 ] ; then
# XXX difficult to know what to do here, should probably
# push the parent up to the patch one level beneath
# where the new patch in the child is, iterating if that
# patch isn't in the parent either
echo "Warning $PATCH not in parent, pushing all patches instead"
$HG qpush -a
fi

# divorcing parent from real-parent.hg by creating a new temp
workspace
(tar cf - $CHANGED_FILES ) | (cd $TMP/parent ; tar xf -)
# now pop those patches out again so we can deal with the next patch
$HG $QUIET qpop -a
cd $TMP/parent
$HG $QUIET add
$HG $QUIET -R $TMP/parent commit -m "State of $PARENT at patch
$PATCH"
done


write_deleteadd_script

# Now clone a child from this parent
log_debug "Cloning $TMP/parent to $TMP/child"
$HG $QUIET clone $TMP/parent $TMP/child

for PATCH in $@
do

CHANGED_FILES=$(changed_files $REAL_CHILD $PATCH)
DELETED_FILES=$(deleted_files $REAL_CHILD $PATCH)
ADDED_FILES=$(added_files $REAL_CHILD $PATCH)
cd $REAL_CHILD
log_debug "Copying changes from $REAL_CHILD to $TMP/child"
(tar cf - $CHANGED_FILES) | (cd $TMP/child ; tar xf - )
cd $TMP/child
if [ -n "$DELETED_FILES" ] ; then
$HG remove $DELETED_FILES
fi
if [ -n "$ADDED_FILES" ] ; then
$HG add $ADDED_FILES
fi
$HG $QUIET -R $TMP/child commit -m "${OUTGOING_DESC}"

done

log_debug "At this stage, we can use webrev in $TMP/child"
log_debug "For example here are outgoing changes in $TMP/child:"
$HG -R $TMP/child outgoing -p

log_debug "Once you're finished with $TMP, you should delete it."
rm /tmp/patch_webrev.$$.awk

log_debug "Generating webrev for you"
THISDIR=$(pwd)
cd $TMP/child
$WEBREV
if [ ! -d "${REAL_CHILD}/webrev" ] ; then
cp -r webrev $REAL_CHILD
cd $REAL_CHILD
rm -rf $TMP
else
echo "webrev directory already exists in $REAL_CHILD - not
overwriting it."
echo "your webrev is at $TMP/child/webrev."
fi
On Nov 1, 7:11 am, AI <vcpan...@gmail.com> wrote:
> Can you find any Odd order Magic square with 0 Determinant or Prove
> that such
algorithm for generating odd-order magic sq exist
This simple algorithm can generate a magic square of any odd size. ...
if(not $n % 2) { die "$n is not odd.\n"; } $x = int($n/2); $y = 0; my
@S; ...
everything
Odd Magic Squares
\ { z[3]=z[1]; //150 IF N(Z5)<>0 THEN Z3=Z1:Z4=(Z2+1)-(Z6*X) ...
Order of Magic Square (Mode Screen Limit: 19) ODD-NUMBER: 4. ODD-
NUMBER: 9
Constructing odd order magic
squares.CommonsConstructing_odd_order_magic_squares.png‎ (373 × 191
pixels, ...
/File:Constructing_odd_order_magic_squares.png
Odd Magic Squares
The square told the people how big their sacrifice needed to be
in order to save ... For example, a 3x3 magic square would start like
so: 0 1 0 0 0 0 0 0 0 ...
CodeToad - Visual Basic Odd Magic Square .
8 posts - 7 authors - Last post: Jul 23, 2003
Top = 0 Grid.Rows = N Grid.Cols = N Me.Caption = "Odd Magic " _
& " Order : " & Str(N) Call MagicSquare End Sub ...
Magic Square -- and break vector (0, 1). In order for this
to produce a magic square, each break move ... A second method for
generating magic squares of odd order has been ...
: Magic square (odd order)
The last part of the procedure starting with 1 := 0; which ....
The procedure generated odd-order magic squares satisfactorily. For
orders up to 9, ...
Magic squares of any odd order can be constructed following a
pattern very ... 48 16 32 16 32 48 0 48 0 32 16 32 16 0 48 0 48 16 32
16 32 48 0 48 0 32 16 32 ...
... The "De La Loubere" rule for generating odd order magic
squares requires ... If we consider the numbers in a magic square
running from 0 to ...
A magic square of odd order n contains the integers from 1
to n2, ... all values in the square to zero for (i=0;i<n;i++) for
(j=0;j<n;j++) mSquare[i][j]=0; ...

#!/bin/ksh

# This script is a bit of a hack to allow us to use webrev on
MeAmI.org
# workspaces use MQ. Specifically, this allows us to more easily see
# the changes made over two versions of the same patch where
# patch is not at top level of qapplied.
#@ magic web http://www.meami.org

Thanks!

0 new messages