Saturday, August 27, 2022

GRAPH Traveral

 let routes = [

    { start: "mumbai", end: "paris" }
    ,{ start: "mumbai", end: "dubai" }
    ,{ start: "mumbai", end: "boston" }
    ,{ start: "paris", end: "boston" }
    ,{ start: "dubai", end: "paris" }
    ,{ start: "paris", end: "ny" }
    ,{ start: "dubai", end: "ny" }
    ,{ start: "boston", end: "ny" }
    ,{ start: "ny", end: "dubai" }
]

/* we want a graph like this
 *
    {
        mumbai:[paris, dubai, ny],
        paris: [dubai, ny]
    }
 */

const queue = [];

const hasPath = (graph, src, dest) => {
   
    if (src === dest) {
        queue.push(src)
        return true;
    }
 
    for (let neighbor in graph[src]) {
        queue.push(src)

        if (hasPath(graph, graph[src][neighbor], dest)) {
            return true;
        }
       
    }
    console.log("return false");

    queue.shift()  
    return false;
}

const buildGraph = (edges) => {
    const graph = {};
 
    edges.forEach(edge => {
        if (!graph.hasOwnProperty(edge.start)) graph[edge.start] = []; // this is 1 directional graph.
        graph[edge.start].push(edge.end)
    });
   
    console.log(graph);
    return graph;
}


const buildGraphUndirected = (edges, src, dest) => {
    const graph = {};


    for (let edge in edges) {
        if (!graph.hasOwnProperty(edges[edge]["start"]))graph[edges[edge]["start"]] = [];
        if (!graph.hasOwnProperty(edges[edge]["end"]))graph[edges[edge]["end"]] = [];       // this would become non-directed graph

        graph[edges[edge]["start"]].push(edges[edge]["end"])
        graph[edges[edge]["end"]].push(edges[edge]["start"]);        // this would become non-directed graph
    }
    //console.log(graph);
    return graph;
    }


hasPath(buildGraph(routes), "mumbai", "boston");

console.log("----------------------------------------");
console.log(queue)
//buildGraphUndirected(routes);
console.log("----------------------------------------");


    /*
     * alternate for of loop ...but doesn't work in IE

     * if input was of tuples we could have used iterable syntax
     * need to put up another code block for that type

   
    for (let edge of edges) {

    }
     */

Thursday, April 7, 2016

Arduino Serial Communication with ESP8266

Here's the wiring.
Here's the wiring diagram....
Using AltSerial ensured that I was not getting a whole lot of gibberish in Serial Com. I also think the RX and TX pins on the ESP8266 are 5V tolerant. Been using them for a direct connection Arduino UNO with no problem. I will add a 10K Ohm resistor on the TX pin from arduino to see if it makes a difference to stability of the connection. ESP8266 chips are total flakes when it comes to a stable connection. Use the ESP-201s instead that have extra pins as well.
1. Program the ESP8266 to be an HTTP webserver. I used the sample that was provided with ESP8266 library on GITHUB
/*
 *  This sketch demonstrates how to set up a simple HTTP-like server.
 *  The server will set a GPIO pin depending on the request
 *    http://server_ip/gpio/0 will set the GPIO2 low,
 *    http://server_ip/gpio/1 will set the GPIO2 high
 *  server_ip is the IP address of the ESP8266 module, will be 
 *  printed to Serial when the module is connected.
 */

#include 

const char* ssid = "i_am_mumbhai-2.4";
const char* password = "!ceCr3am";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  //Serial.begin(9600);
  delay(10);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("wait\r\n");
  }
  Serial.print("connect\r\n");
  
  // Start the server
  server.begin();
  Serial.println("started\r\n");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  
  // Wait until the client sends some data
  //Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
  
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  //Serial.println(req);
  client.flush();
  
  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1) {
    Serial.println(0);
    val = 0;
  } else if (req.indexOf("/gpio/1") != -1) {
    Serial.println(1);
    val = 1;
  } else if (req.indexOf("/gpio/2") != -1) {
    Serial.println(2);
    val = 2;
  } else if (req.indexOf("/gpio/3") != -1) {
    Serial.println(3);
    val = 3;
  } else {
    Serial.println(req);
    client.stop();
    return;
  }

  Serial.println(req);
  
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\n\r\nGPIO is now  " + String(val) + "\r\n\r\n\n";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected 
  // when the function returns and 'client' object is detroyed
}


2. Program the arduino to talk to the ESP8266 over serial and parse the incoming string to read the pin number and intended value.
#include 

//#include 

//SoftwareSerial esp8266(11,10);

AltSoftSerial esp8266;


char* pch;
void setup() {
  // put your setup code here, to run once:
  pinMode(7, OUTPUT);
  Serial.begin(115200);
  esp8266.begin(115200);
  Serial.println("start");
  esp8266.println("esp start");
  
}


void loop() {
  
  
  /* 2nd attempt - works better */
  String content = "";
  char character;
  delay(500);
  //
  while(esp8266.available()) {
    cli();
    character = esp8266.read();
    content.concat(character);
    sei();    
  }
    
  if (content != "" && (content.indexOf("/state/on")>0 || content.indexOf("/state/off")>0)) {
    
    Serial.println(content);
    Serial.println("============");

    /* String manip 2nd attempt */
    int start = content.indexOf("/gpio/");
    int end_1 = content.lastIndexOf("/off");
    int end_2 = content.lastIndexOf("/on");
    
    String interest = (end_1>0) ? (content.substring(start,end_1))+"/off" : (content.substring(start,end_2))+"/on";
    int pinValue = (end_1>0) ? HIGH : LOW;
    Serial.println("interest:" + interest);
    String pin = interest.substring(6,7);
    Serial.println("pin:" + pin);

    digitalWrite(pin.toInt(), pinValue);
  }
  
  
}

Friday, May 9, 2014

Layouts using Dojo 1.9

Generate layout and add side accordion container
/*
 * @File : layout.js
 */
require([ "dojo/dom", "dojo/on", "dojo/dom-construct", "dojo/dom-style", "dojo/dom-attr", 
  "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/layout/AccordionContainer",
  "dojo/domReady!" ], 
function(dom, on, domConstruct, domStyle, domAttr,
  BorderContainer, ContentPane, AccordionContainer) {

 var app = new BorderContainer({
  id : "appContainer",
  design : "headline"
 }, dom.byId("app"));

 var topPane = new ContentPane({
  id : "topPane",
  region : "top",
  style : "background-color:#E1EBFD;height:auto;"
 }, dom.byId("headerDiv"));
 var leftPane = new ContentPane({
  id : "leftPane",
  region : "left",
  splitter : true,
  style : "background-color:#E1EBFD;width:25%;padding:0; margin:0;overflow:hidden;"
 });
 var mainPane = new ContentPane({
  id : "mainPane",
  region : "center",
  content:"

Main Pane

" }); var btmPane = new ContentPane({ id : "btmPane", region : "bottom", content:"

Main Pane

" }); app.addChild(topPane); app.addChild(leftPane); app.addChild(mainPane); //app.addChild(btmPane); app.startup(); // ----------------------------------------- }); require(["dojo/dom", "dojo/on", "dojo/dom-construct", "dojo/dom-style", "dojo/dom-attr", "dijit/layout/ContentPane", "dijit/layout/AccordionContainer", "dojo/domReady!"], function(dom, on, domConstruct, domStyle, domAttr, ContentPane, AccordionContainer) { var ctnr = new AccordionContainer({ style : "height:100%;" }); ctnr.addChild(new ContentPane({ title : "List Posts", content : "Create/Edit Blog Posts", style : "" })); ctnr.addChild(new ContentPane({ title : "Calendar/ToDo", content : "Hi how are you?" })); ctnr.addChild(new ContentPane({ title : "Wiki", content : "Edit Wiki" })); ctnr.placeAt(dom.byId("leftPane")); ctnr.resize(); });
Now generate form elements for blog updates
/**
 * 
 * @ File  blogEdit.js
 */
/**
 * @author Anang Phatak
 */
require([ "dojo/dom", "dojo/on", "dojo/dom-construct", "dojo/dom-style", "dojo/ready",
  "dojo/dom-attr", 
  "dojox/layout/TableContainer",
   "dijit/registry", 
   "dijit/form/Form","dijit/form/TextBox", "dijit/form/Button", 
   "dijit/TitlePane",
   "dijit/Editor", 
   "dijit/_editor/plugins/FullScreen",
   "dijit/_editor/plugins/TextColor", 
   "dijit/_editor/plugins/FontChoice", 
   "dijit/_editor/plugins/LinkDialog", 
   "dijit/_editor/plugins/Print", 
   "dijit/_editor/plugins/ViewSource", 
//   "dojox/editor/plugins/PrettyPrint",
//   "dojox/editor/plugins/PageBreak",
//   "dojox/editor/plugins/ShowBlockNodes",
//   "dojox/editor/plugins/Preview",
//   "dojox/editor/plugins/Save",
//   "dojox/editor/plugins/ToolbarLineBreak",
//   "dojox/editor/plugins/NormalizeIndentOutdent",
//   "dojox/editor/plugins/Breadcrumb",
//   "dojox/editor/plugins/FindReplace",
//   "dojox/editor/plugins/PasteFromWord",
//   "dojox/editor/plugins/InsertAnchor",
//   "dojox/editor/plugins/CollapsibleToolbar",
//   "dojox/editor/plugins/TextColor",
//   "dojox/editor/plugins/Blockquote",
//   "dojox/editor/plugins/Smiley",
//   "dojox/editor/plugins/UploadImage",
   "dojox/editor/plugins/TablePlugins",
   "dojox/html/entities",
   "dojo/domReady!" ], 
function(dom, on, domConstruct, domStyle, ready, domAttr,
  TableContainer, 
  registry, Form, TextBox, Button,
  TitlePane, Editor,
  FullScreen, TextColor, FontChoice, LinkDialog, Print, ViewSource,
  TablePlugins,
  entities
//  PrettyPrint,
//  PageBreak,
//  ShowBlockNodes,
//  Preview,
//  Save,
//  ToolbarLineBreak,
//  NormalizeIndentOutdent,
//  Breadcrumb,
//  FindReplace,
//  PasteFromWord,
//  InsertAnchor,
//  CollapsibleToolbar,
//  TextColor,
//  Blockquote,
//  Smiley,
//  UploadImage
  ) {
 
 ready(function () {
  
  var tp = new TitlePane({
   title:"Login to jBlog", 
   open:true
  });
  
  var frm = new Form({
   action: '',
         method: 'post',
         label: "Login to jBlog",
         onSubmit:function () {
          console.log(arguments);
     
          return false;
         }
  });
  
  var tc = new TableContainer({
   id:"loginCntr",
   cols:1,
   showLabels:true,
   orientation:"horiz",
   valign:"top",
   label:"Login to jBlog"
  });
  
  var titleTxt = new TextBox({
   id:"txtTitle",
   name:"blogTitle",
   label: "Blog Title:",
   placeHolder: "New Blog Title",
   style:"width:100%;",
   required:true
  });
  
  var btnSubmit = new Button({
   id:"btnSubmit",
   type:"Submit",
   label: "Submit"
  });
  
  var editor = new Editor({
   id : "blogEditor",
   label : "Blog Text",
   extraPlugins : [
     'fullscreen',
     'foreColor',
     'hiliteColor',
     'createLink',
     'insertImage',
     "|",
     'insertTable',
     'print',
     'viewsource',
     "|",
     {
      name : "dijit/_editor/plugins/FontChoice",
      command : 'fontName',
      values : [ 'Segoe UI', 'Calibri', 'Courier New',
        'Helvetica', 'Verdana', 'Myriad', 'Garamond' ]
     }, 
     'fontSize', 
     'formatBlock'],
   "class" : "nihilo",
   "style" : "font-family:Courier New, font-size:8pt;"
  });
  on(editor, 'change', function(v) {
   console.log(entities.encode(v));
  });
  
  tc.addChild(titleTxt);
  tc.placeAt(frm);
  editor.placeAt(frm);
  btnSubmit.placeAt(frm, "last");
  frm.placeAt(dom.byId("mainPane"));
 });
});

Sunday, May 4, 2014

Dojo 1.9 Layout Example

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<link rel="stylesheet" href="//localhost/common/libs/dojo-release-1.9.3/dijit/themes/claro/claro.css" />
<link rel="stylesheet" href="//localhost/common/libs/dojo-release-1.9.3/dijit/themes/soria/soria.css" />
<link rel="stylesheet" href="//localhost/common/libs/dojo-release-1.9.3/dijit/themes/nihilo/nihilo.css" />
<link rel="stylesheet" href="//localhost/common/libs/dojo-release-1.9.3/dijit/themes/tundra/tundra.css" />

<script>
 dojoConfig={
   async:true
 };
</script>
 <style>
 html, body {
  width:100%;height:100%;overflow:hidden;margin:0;padding:0;
  font-family:Verdana, Helvetica, sans-serif;
  font-size:9pt;
  }
 </style>
 <script src="//localhost/common/libs/dojo-release-1.9.3/dojo/dojo.js"></script>
 <script>
 var appStyle = "claro";
 require(["dojo/dom", "dojo/on", "dojo/dom-construct", "dojo/dom-style", "dojo/dom-attr",
          "dojo/domReady!"], function (dom, on, domConstruct, domStyle, domAttr){
  domAttr.set(document.body, "class", appStyle);
  document.body.appendChild(domConstruct.create("div", {
   id:"app", 
   style:"width:100%;height:100%;"
  }));
 });
 
 require(["dojo/dom", "dojo/on", "dojo/dom-construct", "dojo/dom-style", "dojo/dom-attr",
          "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/layout/AccordionContainer",
          "dojo/domReady!"], 
 function (dom, on, domConstruct, domStyle, domAttr, BorderContainer, ContentPane, AccordionContainer){
  
  var app = new BorderContainer({
    id:"appContainer", 
    design:"headline"
   }, dom.byId("app"));
  
  var topPane = new ContentPane({
    id:"topPane",
    region:"top",
    style:"background-color:#E1EBFD;height:auto;"
   }, dom.byId("headerDiv"));
  var leftPane = new ContentPane({
    id:"leftPane", 
    region:"left", 
    splitter:true,
    style:"background-color:#E1EBFD;width:25%;padding:0; margin:0;"
   });
  var mainPane = new ContentPane({
   id:"mainPane", 
   region:"center"
  });
  
  app.addChild(topPane);
  app.addChild(leftPane);
  app.addChild(mainPane);
  app.startup();
  
  // -----------------------------------------
  var ctnr = new AccordionContainer({
   style:"height:100%"
   });
  
  ctnr.addChild(new ContentPane({
         title: "This is a content pane",
         content: "Hi!"
     }));
  
  ctnr.addChild(new ContentPane({
         title:"This is as well",
         content:"Hi how are you?"
     }));
  
  ctnr.addChild(new ContentPane({
         title:"This too",
         content:"Hello im fine.. thnx"
     }));
  
  leftPane.addChild(ctnr);
  ctnr.resize();
 });
 </script>


Saturday, May 3, 2014

Reviving Archaic Tech: Setup DB Resource/JDBC Realm in Tomcat 7

Setup JDBC Realm in Context.xml

<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost/jcredentials?user=root&password=*****"
userTable="users" userNameCol="username" userCredCol="passwd"
   userRoleTable="user_roles" roleNameCol="rolename"/>

Setup JDBC Resource in Context.xml

<Resource name="jdbc/jBlogDB"
auth="Container" 
type="javax.sql.DataSource" 
username="root" password="****"
driverClassName="com.mysql.jdbc.Driver" 
url="jdbc:mysql://localhost/jblog"
maxActive="8" maxIdle="4"/>

LAMP Installation and Setup

Installing Apache, MySQL and PHP on Xubuntu

Configure scripts:


Apache 2.4.9


./configure --prefix=/usr/local/apache --enable-modules=all --enable-isapi --enable-so --enable-cache --enable-case-filter --enable-deflate --enable-proxy --enable-rewrite --enable-ssl --with-mpm=worker

PHP 5.5.12

./configure --prefix=/usr/local/php --with-apxs=/usr/local/apache/bin/apxs --enable-bcmath --enable-calendar --with-mysqli --enable-calendar --enable-ftp --with-gd --with-curl --with-xsl --with-xmlrpc --with-bz2 --enable-intl --enable-mysqlnd --with-pear --enable-zip --enable-soap

Post Install changes to Apache http.conf

// Should be automatically added
LoadModule php5_module        modules/libphp5.so

// Add Handler Manually
AddHandler application/x-httpd-php .php

// Update Document Root
DocumentRoot "/home/user/Development/web"
// Configure root directory - default settings

<Directory "/home/user/Development/web">
    
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options 
# for more information.

Options Indexes FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit

AllowOverride None
# Controls who can get stuff from this server.

Require all granted
</Directory>

Thursday, June 28, 2007

Insertion Sort

for a given array of numbers 101 71 15 31 92 213 122 81 24 25
package net.study.algorithms;

public class InsertionSortImpl {
 private static int[] intArray = {101, 71, 15, 31, 92, 213, 122, 81,24, 25};
 //private static int[] intArray = {10,9,8,7,6,5,4,3,2,1}; //worst case
 
 private static String note = "";
 public static void main(String[] args) {
  
  for (int i:intArray) {
   System.out.print(i + " ");
  }

  for (int i=0; i<intArray.length; i++) {
   for (int j=1;j<intArray.length; j++) {
    if (intArray[j] < intArray[j-1]) {
     int a = intArray[j-1];
     intArray[j-1] = intArray[j];
     intArray[j] = a;
    }
    else {
        break; // break out of non-essential iterations
    }
   }
  }
  
  for (int i:intArray) {
   System.out.print(i + " ");
  }
 }
}


Alternatively we can code this as:
package net.study.algorithms;

public class InsertionSortImpl {
 private static int[] intArray = {101, 71, 15, 31, 92, 213, 100, 81,24, 25};
 //private static int[] intArray = {10,9,8,7,6,5,4,3,2,1}; //worst case
 
 private static String note = "";
 public static void main(String[] args) {
  for (int j=1; j< intArray.length;j++) {
   int key = intArray[j];
   int i = j-1;
   
   System.out.println(i + " > " + 0 + " and " + intArray[i] +" > "+ key);

   while (i>=0 && intArray[i] > key) {
    System.out.println("intArray["+ (i+1) + "]" + " = " + intArray[i]);
    intArray[i+1] = intArray[i];
    i=i-1;
    
   }
   intArray[i+1] = key;
  }
  
  
  for (int x:intArray) {
   System.out.print(+ x + " ");
  }
 }
}


The implementation will iterate thru' the array switching and ordering numbers in the following manner:

71 101 15 31 92 213 122 81 24 25  (1.1)  switching 101 and 71
71 15 101 31 92 213 122 81 24 25  (1.2)  switching 101 and 15
71 15 31 101 92 213 122 81 24 25  (1.3)  switching 101 and 31
71 15 31 92 101 213 122 81 24 25  (1.4)  switching 101 and 92
71 15 31 92 101 213 122 81 24 25  (1.5)  no change for 101 and 213
71 15 31 92 101 122 213 81 24 25  (1.6)  switching 213 and 122
71 15 31 92 101 122 81 213 24 25  (1.7)  switching 213 and 81
71 15 31 92 101 122 81 24 213 25  (1.8)  switching 213 and 24
71 15 31 92 101 122 81 24 25 213  (1.9)  switching 213 and 25
15 71 31 92 101 122 81 24 25 213  (2.1)  switching 71 and 15
15 31 71 92 101 122 81 24 25 213  (2.2)  switching 71 and 31
15 31 71 92 101 122 81 24 25 213  (2.3)  no change for 71 and 92
15 31 71 92 101 122 81 24 25 213  (2.4)  no change for 92 and 101
15 31 71 92 101 122 81 24 25 213  (2.5)  no change for 101 and 122
15 31 71 92 101 81 122 24 25 213  (2.6)  switching 122 and 81
15 31 71 92 101 81 24 122 25 213  (2.7)  switching 122 and 24
15 31 71 92 101 81 24 25 122 213  (2.8)  switching 122 and 25
15 31 71 92 101 81 24 25 122 213  (2.9)  no change for 122 and 213
15 31 71 92 101 81 24 25 122 213  (3.1)  no change for 15 and 31
15 31 71 92 101 81 24 25 122 213  (3.2)  no change for 31 and 71
15 31 71 92 101 81 24 25 122 213  (3.3)  no change for 71 and 92
15 31 71 92 101 81 24 25 122 213  (3.4)  no change for 92 and 101
15 31 71 92 81 101 24 25 122 213  (3.5)  switching 101 and 81
15 31 71 92 81 24 101 25 122 213  (3.6)  switching 101 and 24
15 31 71 92 81 24 25 101 122 213  (3.7)  switching 101 and 25
15 31 71 92 81 24 25 101 122 213  (3.8)  no change for 101 and 122
15 31 71 92 81 24 25 101 122 213  (3.9)  no change for 122 and 213
15 31 71 92 81 24 25 101 122 213  (4.1)  no change for 15 and 31
15 31 71 92 81 24 25 101 122 213  (4.2)  no change for 31 and 71
15 31 71 92 81 24 25 101 122 213  (4.3)  no change for 71 and 92
15 31 71 81 92 24 25 101 122 213  (4.4)  switching 92 and 81
15 31 71 81 24 92 25 101 122 213  (4.5)  switching 92 and 24
15 31 71 81 24 25 92 101 122 213  (4.6)  switching 92 and 25
15 31 71 81 24 25 92 101 122 213  (4.7)  no change for 92 and 101
15 31 71 81 24 25 92 101 122 213  (4.8)  no change for 101 and 122
15 31 71 81 24 25 92 101 122 213  (4.9)  no change for 122 and 213
15 31 71 81 24 25 92 101 122 213  (5.1)  no change for 15 and 31
15 31 71 81 24 25 92 101 122 213  (5.2)  no change for 31 and 71
15 31 71 81 24 25 92 101 122 213  (5.3)  no change for 71 and 81
15 31 71 24 81 25 92 101 122 213  (5.4)  switching 81 and 24
15 31 71 24 25 81 92 101 122 213  (5.5)  switching 81 and 25
15 31 71 24 25 81 92 101 122 213  (5.6)  no change for 81 and 92
15 31 71 24 25 81 92 101 122 213  (5.7)  no change for 92 and 101
15 31 71 24 25 81 92 101 122 213  (5.8)  no change for 101 and 122
15 31 71 24 25 81 92 101 122 213  (5.9)  no change for 122 and 213
15 31 71 24 25 81 92 101 122 213  (6.1)  no change for 15 and 31
15 31 71 24 25 81 92 101 122 213  (6.2)  no change for 31 and 71
15 31 24 71 25 81 92 101 122 213  (6.3)  switching 71 and 24
15 31 24 25 71 81 92 101 122 213  (6.4)  switching 71 and 25
15 31 24 25 71 81 92 101 122 213  (6.5)  no change for 71 and 81
15 31 24 25 71 81 92 101 122 213  (6.6)  no change for 81 and 92
15 31 24 25 71 81 92 101 122 213  (6.7)  no change for 92 and 101
15 31 24 25 71 81 92 101 122 213  (6.8)  no change for 101 and 122
15 31 24 25 71 81 92 101 122 213  (6.9)  no change for 122 and 213
15 31 24 25 71 81 92 101 122 213  (7.1)  no change for 15 and 31
15 24 31 25 71 81 92 101 122 213  (7.2)  switching 31 and 24
15 24 25 31 71 81 92 101 122 213  (7.3)  switching 31 and 25
15 24 25 31 71 81 92 101 122 213  (7.4)  no change for 31 and 71
15 24 25 31 71 81 92 101 122 213  (7.5)  no change for 71 and 81
15 24 25 31 71 81 92 101 122 213  (7.6)  no change for 81 and 92
15 24 25 31 71 81 92 101 122 213  (7.7)  no change for 92 and 101
15 24 25 31 71 81 92 101 122 213  (7.8)  no change for 101 and 122
15 24 25 31 71 81 92 101 122 213  (7.9)  no change for 122 and 213
15 24 25 31 71 81 92 101 122 213  (8.1)  no change for 15 and 24
15 24 25 31 71 81 92 101 122 213  (8.2)  no change for 24 and 25
15 24 25 31 71 81 92 101 122 213  (8.3)  no change for 25 and 31
15 24 25 31 71 81 92 101 122 213  (8.4)  no change for 31 and 71
15 24 25 31 71 81 92 101 122 213  (8.5)  no change for 71 and 81
15 24 25 31 71 81 92 101 122 213  (8.6)  no change for 81 and 92
15 24 25 31 71 81 92 101 122 213  (8.7)  no change for 92 and 101
15 24 25 31 71 81 92 101 122 213  (8.8)  no change for 101 and 122
15 24 25 31 71 81 92 101 122 213  (8.9)  no change for 122 and 213
15 24 25 31 71 81 92 101 122 213  (9.1)  no change for 15 and 24
15 24 25 31 71 81 92 101 122 213  (9.2)  no change for 24 and 25
15 24 25 31 71 81 92 101 122 213  (9.3)  no change for 25 and 31
15 24 25 31 71 81 92 101 122 213  (9.4)  no change for 31 and 71
15 24 25 31 71 81 92 101 122 213  (9.5)  no change for 71 and 81
15 24 25 31 71 81 92 101 122 213  (9.6)  no change for 81 and 92
15 24 25 31 71 81 92 101 122 213  (9.7)  no change for 92 and 101
15 24 25 31 71 81 92 101 122 213  (9.8)  no change for 101 and 122
15 24 25 31 71 81 92 101 122 213  (9.9)  no change for 122 and 213
15 24 25 31 71 81 92 101 122 213  (10.1)  no change for 15 and 24
15 24 25 31 71 81 92 101 122 213  (10.2)  no change for 24 and 25
15 24 25 31 71 81 92 101 122 213  (10.3)  no change for 25 and 31
15 24 25 31 71 81 92 101 122 213  (10.4)  no change for 31 and 71
15 24 25 31 71 81 92 101 122 213  (10.5)  no change for 71 and 81
15 24 25 31 71 81 92 101 122 213  (10.6)  no change for 81 and 92
15 24 25 31 71 81 92 101 122 213  (10.7)  no change for 92 and 101
15 24 25 31 71 81 92 101 122 213  (10.8)  no change for 101 and 122
15 24 25 31 71 81 92 101 122 213  (10.9)  no change for 122 and 213


Here is the iteration output for 10 number worst case array (reverse sorted array)

9 10 8 7 6 5 4 3 2 1  (1.1)  switching 10 and 9
9 8 10 7 6 5 4 3 2 1  (1.2)  switching 10 and 8
9 8 7 10 6 5 4 3 2 1  (1.3)  switching 10 and 7
9 8 7 6 10 5 4 3 2 1  (1.4)  switching 10 and 6
9 8 7 6 5 10 4 3 2 1  (1.5)  switching 10 and 5
9 8 7 6 5 4 10 3 2 1  (1.6)  switching 10 and 4
9 8 7 6 5 4 3 10 2 1  (1.7)  switching 10 and 3
9 8 7 6 5 4 3 2 10 1  (1.8)  switching 10 and 2
9 8 7 6 5 4 3 2 1 10  (1.9)  switching 10 and 1
8 9 7 6 5 4 3 2 1 10  (2.1)  switching 9 and 8
8 7 9 6 5 4 3 2 1 10  (2.2)  switching 9 and 7
8 7 6 9 5 4 3 2 1 10  (2.3)  switching 9 and 6
8 7 6 5 9 4 3 2 1 10  (2.4)  switching 9 and 5
8 7 6 5 4 9 3 2 1 10  (2.5)  switching 9 and 4
8 7 6 5 4 3 9 2 1 10  (2.6)  switching 9 and 3
8 7 6 5 4 3 2 9 1 10  (2.7)  switching 9 and 2
8 7 6 5 4 3 2 1 9 10  (2.8)  switching 9 and 1
8 7 6 5 4 3 2 1 9 10  (2.9)  no change for 9 and 10
7 8 6 5 4 3 2 1 9 10  (3.1)  switching 8 and 7
7 6 8 5 4 3 2 1 9 10  (3.2)  switching 8 and 6
7 6 5 8 4 3 2 1 9 10  (3.3)  switching 8 and 5
7 6 5 4 8 3 2 1 9 10  (3.4)  switching 8 and 4
7 6 5 4 3 8 2 1 9 10  (3.5)  switching 8 and 3
7 6 5 4 3 2 8 1 9 10  (3.6)  switching 8 and 2
7 6 5 4 3 2 1 8 9 10  (3.7)  switching 8 and 1
7 6 5 4 3 2 1 8 9 10  (3.8)  no change for 8 and 9
7 6 5 4 3 2 1 8 9 10  (3.9)  no change for 9 and 10
6 7 5 4 3 2 1 8 9 10  (4.1)  switching 7 and 6
6 5 7 4 3 2 1 8 9 10  (4.2)  switching 7 and 5
6 5 4 7 3 2 1 8 9 10  (4.3)  switching 7 and 4
6 5 4 3 7 2 1 8 9 10  (4.4)  switching 7 and 3
6 5 4 3 2 7 1 8 9 10  (4.5)  switching 7 and 2
6 5 4 3 2 1 7 8 9 10  (4.6)  switching 7 and 1
6 5 4 3 2 1 7 8 9 10  (4.7)  no change for 7 and 8
6 5 4 3 2 1 7 8 9 10  (4.8)  no change for 8 and 9
6 5 4 3 2 1 7 8 9 10  (4.9)  no change for 9 and 10
5 6 4 3 2 1 7 8 9 10  (5.1)  switching 6 and 5
5 4 6 3 2 1 7 8 9 10  (5.2)  switching 6 and 4
5 4 3 6 2 1 7 8 9 10  (5.3)  switching 6 and 3
5 4 3 2 6 1 7 8 9 10  (5.4)  switching 6 and 2
5 4 3 2 1 6 7 8 9 10  (5.5)  switching 6 and 1
5 4 3 2 1 6 7 8 9 10  (5.6)  no change for 6 and 7
5 4 3 2 1 6 7 8 9 10  (5.7)  no change for 7 and 8
5 4 3 2 1 6 7 8 9 10  (5.8)  no change for 8 and 9
5 4 3 2 1 6 7 8 9 10  (5.9)  no change for 9 and 10
4 5 3 2 1 6 7 8 9 10  (6.1)  switching 5 and 4
4 3 5 2 1 6 7 8 9 10  (6.2)  switching 5 and 3
4 3 2 5 1 6 7 8 9 10  (6.3)  switching 5 and 2
4 3 2 1 5 6 7 8 9 10  (6.4)  switching 5 and 1
4 3 2 1 5 6 7 8 9 10  (6.5)  no change for 5 and 6
4 3 2 1 5 6 7 8 9 10  (6.6)  no change for 6 and 7
4 3 2 1 5 6 7 8 9 10  (6.7)  no change for 7 and 8
4 3 2 1 5 6 7 8 9 10  (6.8)  no change for 8 and 9
4 3 2 1 5 6 7 8 9 10  (6.9)  no change for 9 and 10
3 4 2 1 5 6 7 8 9 10  (7.1)  switching 4 and 3
3 2 4 1 5 6 7 8 9 10  (7.2)  switching 4 and 2
3 2 1 4 5 6 7 8 9 10  (7.3)  switching 4 and 1
3 2 1 4 5 6 7 8 9 10  (7.4)  no change for 4 and 5
3 2 1 4 5 6 7 8 9 10  (7.5)  no change for 5 and 6
3 2 1 4 5 6 7 8 9 10  (7.6)  no change for 6 and 7
3 2 1 4 5 6 7 8 9 10  (7.7)  no change for 7 and 8
3 2 1 4 5 6 7 8 9 10  (7.8)  no change for 8 and 9
3 2 1 4 5 6 7 8 9 10  (7.9)  no change for 9 and 10
2 3 1 4 5 6 7 8 9 10  (8.1)  switching 3 and 2
2 1 3 4 5 6 7 8 9 10  (8.2)  switching 3 and 1
2 1 3 4 5 6 7 8 9 10  (8.3)  no change for 3 and 4
2 1 3 4 5 6 7 8 9 10  (8.4)  no change for 4 and 5
2 1 3 4 5 6 7 8 9 10  (8.5)  no change for 5 and 6
2 1 3 4 5 6 7 8 9 10  (8.6)  no change for 6 and 7
2 1 3 4 5 6 7 8 9 10  (8.7)  no change for 7 and 8
2 1 3 4 5 6 7 8 9 10  (8.8)  no change for 8 and 9
2 1 3 4 5 6 7 8 9 10  (8.9)  no change for 9 and 10
1 2 3 4 5 6 7 8 9 10  (9.1)  switching 2 and 1
1 2 3 4 5 6 7 8 9 10  (9.2)  no change for 2 and 3
1 2 3 4 5 6 7 8 9 10  (9.3)  no change for 3 and 4
1 2 3 4 5 6 7 8 9 10  (9.4)  no change for 4 and 5
1 2 3 4 5 6 7 8 9 10  (9.5)  no change for 5 and 6
1 2 3 4 5 6 7 8 9 10  (9.6)  no change for 6 and 7
1 2 3 4 5 6 7 8 9 10  (9.7)  no change for 7 and 8
1 2 3 4 5 6 7 8 9 10  (9.8)  no change for 8 and 9
1 2 3 4 5 6 7 8 9 10  (9.9)  no change for 9 and 10
1 2 3 4 5 6 7 8 9 10  (10.1)  no change for 1 and 2
1 2 3 4 5 6 7 8 9 10  (10.2)  no change for 2 and 3
1 2 3 4 5 6 7 8 9 10  (10.3)  no change for 3 and 4
1 2 3 4 5 6 7 8 9 10  (10.4)  no change for 4 and 5
1 2 3 4 5 6 7 8 9 10  (10.5)  no change for 5 and 6
1 2 3 4 5 6 7 8 9 10  (10.6)  no change for 6 and 7
1 2 3 4 5 6 7 8 9 10  (10.7)  no change for 7 and 8
1 2 3 4 5 6 7 8 9 10  (10.8)  no change for 8 and 9
1 2 3 4 5 6 7 8 9 10  (10.9)  no change for 9 and 10