Previous | Next

Conspirators

# 1

CATCHING CONSPIRATORS

  • Presented at TPM, Sept 30, 2004

  • Presenter: Glenn Simpson gsimpson@mountaincable.net

  • Slides generated by: slideshow.pl

  • For information about slideshow.pl, contact

    Indigostar.com
TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 2

THE BACKGROUND

  • In the Sept issue of Dr Dobbs Journal, there is a column featuring Dr Ecco.

  • The column presents puzzles for the reader's to solve.

  • I select some of those puzzles and play with identifying a solution.

  • The column implies that readers set down with pencil and paper and work out a solution.

  • As I am computer and Perl oriented, I use the computer and Perl to assist me.

  • In this issue, an informant has indicated there are conspirators.

  • In this instant, 3 conspirators are ring leaders.

  • The remaining conspirators are making their decisions based on the action of the ring leaders.

TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 3

THE TRADES

  • In the following table, a '1' represents a buy, and a '0' represents a sell

  • There are 6 conspirators who have participated in 12 events.

  • Table of trades

      conspirator 1  1 1 0 1 0 0 0 1 0 1 1 1
      conspirator 2  0 1 0 1 1 1 1 0 0 1 1 1
      conspirator 3  1 1 0 1 0 0 0 1 0 1 1 1
      conspirator 4  1 1 0 0 1 1 1 0 1 0 0 0
      conspirator 5  0 0 0 0 1 1 1 1 1 0 0 0
      conspirator 6  0 1 0 0 0 0 0 1 1 0 0 0
    
TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 4

THE TOOLS OF THE FOLLOWERS

  • We are told that the follower conspirators have no communications with the ring leaders.

  • Each follower has a simple pair of logic boxes that they configure and then make a trade based on the result of the logic combo.

  • A logic box performs either an AND on the inputs, or an ODD on the inputs.

  • Here is an example of a 3 input AND box and an example of a 3 input ODD box

  • If the 3 inputs to the AND box are a 'buy' then the output is a 'buy', else it is a sell.

  • If the 3 inputs to the ODD box have an odd number of 'buy' transactions, then the output is a 'buy', else it is a 'sell'.

TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 5

LOGIC COMBOS

  • In addition to the 3 input AND, and 3 input ODD shown above, the following

        combinations can be configured if we have 3 ring leaders.
    
TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 6

PERL TO THE ASSIST

  • The following loops over the candidates, and proposes 3 ring leaders, which are passed to the evaluation function.

    local @aoa = (
        ["C1", 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1],
        ["C2", 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1],
        ["C3", 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1],
        ["C4", 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0],
        ["C5", 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
        ["C6", 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0]);
    
    $candidates = @aoa;
    
        # propose ring leaders
    for $rldr1 (0 .. $candidates - 2) {
       for($rldr2 = $rldr1 + 1; $rldr2 < $candidates - 1; $rldr2++) {
           for($rldr3 = $rldr2 + 1; $rldr3 < $candidates; $rldr3++) {
               test_logic3($rldr1, $rldr2, $rldr3);
           }
       }
    }
    
  • Sub test_logic3() is where all the work is done.

TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 7

EVALUATING CANDIDATES

     # evaluate each candidate that is not a proposed ring leader
 for($c = 0; $c < $candidates; $c++) {
   next if($rldr1 == $c || $rldr2 == $c || $rldr3 == $c);
                                                                                
   for $n (0 .. $rules) {          # init count of rule hits
     $ruleCnt[$c][$n] = 0;
   }
        # apply the rules to each event for this candidate
   for $e (1 .. $events) {         # column zero is not an event
     $tmp = ($aoa[$rldr1][$e] & $aoa[$rldr2][$e]) ? 1 : 0;
     $res[0] = ($aoa[$rldr3][$e] != $tmp) ? 1 : 0;   # 2 inp AND with ODD

     $tmp = $aoa[$rldr1][$e] & $aoa[$rldr3][$e];
     $res[1] = ($aoa[$rldr2][$e] != $tmp) ? 1 : 0;

     $tmp = $aoa[$rldr2][$e] & $aoa[$rldr3][$e];
     $res[2] = ($aoa[$rldr1][$e] != $tmp) ? 1 : 0;

     $res[3] = ($aoa[$rldr1][$e] + $aoa[$rldr2][$e] +
                $aoa[$rldr3][$e]) & 1;          # 3 inp ODD
TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 8

EVALUATION CONT'D

     $res[4] = $aoa[$rldr1][$e] & $aoa[$rldr2][$e] & $aoa[$rldr3][$e]; # 3 inp AND

     $tmp = ($aoa[$rldr1][$e] + $aoa[$rldr2][$e]) & 1;  # 2 inp ODD with AND
     $res[5] = $aoa[$rldr3][$e] & $tmp;

     $tmp = ($aoa[$rldr1][$e] + $aoa[$rldr3][$e]) & 1;
     $res[6] = ($aoa[$rldr2][$e] & $tmp);

     $tmp = ($aoa[$rldr2][$e] + $aoa[$rldr3][$e]) & 1;
     $res[7] = ($aoa[$rldr1][$e] & $tmp);

     print " !! Rule results !!\n" if($debug > 2 && $e < 2);
     for($r = 0; $r < $rules; $r++) {     # count the rule hits
       print "( $res[$r] vs $aoa[$c][$e])" if($debug > 2);
       if($res[$r] == $aoa[$c][$e]) {
          $ruleCnt[$c][$r]++;     # add to the 'hit' count
       }
     }
     print "\n" if($debug > 2);
   }
TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 9

EVALUATION CONT'D

  my $rcnt = 0;
  @ary = ();
  for($r = 0; $r < $rules; $r++) {   # collect list of follower conspirators
    print " rule $r: good $ruleCnt[$c][$r] times\n" if($debug > 1);
    next if($ruleCnt[$c][$r] < $events);
    $ary[$rcnt++] = $r;              # save which rule qualified
  }
  push @resTable, [@ary];
  print "Rules that qualified: @ary\n" if($debug && $rcnt);
                                                                                
  if($rcnt) {
    if($debug > 1) {
      my $cn = $c + 1;
      print "Rule(s) @ary qualify candidate $cn\n";
    }
  } else {
    return;     # ignore this leader combo
  }
 }
TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 10

EVALUATION CONT'D

  • Time to report the results

        my $cnt = 0;
        for($i = 0; $i < $#[$resTable]; $i++) {
            $cnt++ if($#[$resTable[$i]]);
        }
                                                                                    
        print " !! Final result !!\n  Leader $ldr1, $ldr2 and $ldr3 are ";
        my $ans = ($cnt < 2) ? "probably the leaders" : "not the leaders";
        print "$ans\n";
    }
    
TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Previous | Next

Conspirators

# 11

SUMMARY

  • The flexibility in Perl for generating loops

        foreach $i (@list)
    
        for $n ($low .. $high)
    
        for($x = 0; $x < $y; $x++)
    
        etc.
    
  • The ease of building list of lists (array of arrays) and hash of hashes.

        push @mainList, [@subList];
    
  • Simplicity of building a list of data.

        $ary[$cnt++] = $value;  
    
  • I hope you have found this presentation a fun item to think about and maybe

        it represents yet another way to enjoy practicing your Perl skills.
    
TPM Sept meeting

Index

Sep 30,2004

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Table of Contents

1. CATCHING CONSPIRATORS
2. THE BACKGROUND
3. THE TRADES
4. THE TOOLS OF THE FOLLOWERS
5. LOGIC COMBOS
6. PERL TO THE ASSIST
7. EVALUATING CANDIDATES
8. EVALUATION CONT'D
9. EVALUATION CONT'D
10. EVALUATION CONT'D
11. SUMMARY