Fastest 3 out of 25 Horses Problem

Problem Statement

You have 25 horses, and you want to pick the fastest 3 horses out of those 25. Each race can have maximum of 5 horses at the same time. What is the minimum number of races required to find the 3 fastest horses without using a stopwatch?

Solution

Let’s say that we have 5 races of 5 horses each, so each row in the table above represents a race.

H1 H2 H3 H4 H5
H6 H7 H8 H9 H10
H11 H12 H13 H14 H15
H16 H17 H18 H19 H20
H21 H22 H23 H24 H25

Let each row represent a race.

Step 1: Perform 5 races of each set.

Result:

1st 2nd 3rd 4th 5th
H1 H2 H3 H4 H5
H6 H7 H8 H9 H10
H11 H12 H13 H14 H15
H16 H17 H18 H19 H20
H21 H22 H23 H24 H25

Step 2: Elimination by logical analysis:

  • We can eliminate the slowest 2 horses in each group since those horses are definitely not in the top 3
  • The 5 group leaders are not necessarily the 5 fastest horses, therefore race those 5 horses against each other (H1, H6, H11, H16, and H21) {Race 6}, Let’s say that the 3 fastest in that group are H1, H6, and H11 – automatically we can eliminate H16 and H21 since those 2 are definitely not in the top 3
  • We can automatically eliminate all the horses that H16 and H21 competed against in the preliminary races as they were slower than H16 and H21
  • We also know that H1 is the fastest horse in the group since he was the fastest horse out of the 5 group leaders
  • if H6 and H11 are the 2nd and 3rd fastest in the group leaders, then we should be able to eliminate H8 since H6 raced against him and he was in 3rd place in that race
  • We can also eliminate H12 and H13 since H11 was the 3rd fastest in the group leaders, and H12 and H13 were slower than H11
  • This leaves us with the following horses to determine the 2nd and 3rd fastest horses:
H2 H3 H6 H7 H11

Race the last Set {Race 7} to get the Top 2nd and 3rd racers with H1 as the fastest.

Total number of Races: 7

Enable/Disable Proxy Service in OSB via ANT+Python

Below is the configurable code for developers to maintain an ant script to be able to control(Enable/Disable) Proxy Services via Ant Script.

Files:


WLSTbuild.properties

weblogic.home.dir=<OSB Home>/wlserver_10.3
weblogic.lib.dir=${weblogic.home.dir}/server/lib


build.properties

fmw.home=<OSB Middleware Home>
wls.username =<Weblogic User Id>
wls.password =<Weblogic Password>
wls.server = t3://:<Weblogic Host>:<Weblogic Port>
service.script=osb_enable_service.py
service.project="<Project Name>/<Sub Project Name or 'ProxyServices' >"
service.name =<Proxy Name>
service.action = <disable/enable>


build.xml

<?xml version="1.0" encoding="windows-1252" ?>
<project name="ServiceControl" default="ServiceControl">
   <property file="./build.properties"/>
   <property file="./wlstbuild.properties"/>
   <taskdef classname="weblogic.ant.taskdefs.management.WLSTTask" name="wlst">
      <classpath>
         <pathelement location="${weblogic.lib.dir}/weblogic.jar"></pathelement>
      </classpath>
   </taskdef>
   <target name="ServiceControl">
      <echo>${weblogic.lib.dir}</echo>
      <wlst filename="${service.script}" debug="true" failonerror="false"
            arguments="${wls.username} ${wls.password} ${wls.server} ${service.project} ${service.name} ${service.action}">
         <classpath>
            <pathelement location="${weblogic.lib.dir}/weblogic.jar"></pathelement>
            <pathelement location="${fmw.home}/<OSB Installation Folder>/lib/sb-kernel-api.jar"></pathelement>
            <pathelement location="${fmw.home}/<OSB Installation Folder>/lib/sb-kernel-impl.jar"></pathelement>
            <pathelement location="${fmw.home}/<OSB Installation Folder>/lib/osb-coherence-client.jar"></pathelement>
         </classpath>
      </wlst>
   </target>
</project>

osb_enable_service.py

from com.bea.wli.sb.management.configuration import SessionManagementMBean
from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
from com.bea.wli.config import Ref
from java.lang import String
from com.bea.wli.monitoring import StatisticType
from com.bea.wli.config import Ref
from com.bea.wli.sb.util import Refs
from com.bea.wli.sb.management.configuration import CommonServiceConfigurationMBean
from java.lang import String
from com.bea.wli.monitoring import StatisticType
from com.bea.wli.config import Ref
from com.bea.wli.sb.util import Refs
from com.bea.wli.sb.management.configuration import CommonServiceConfigurationMBean
adminUser = sys.argv[1]
adminPassword = sys.argv[2]
adminUrl = sys.argv[3]
project = sys.argv[4]
service = sys.argv[5]
action = sys.argv[6]
connect(adminUser,adminPassword,adminUrl)
domainRuntime()
print('WLST Connected')

Create a session name

sessionName = String("SessionScript"+Long(System.currentTimeMillis()).toString())
print('... after session. Session is: ', sessionName)

Get the session MBean and create a session

sessionMBean = findService(SessionManagementMBean.NAME,SessionManagementMBean.TYPE)
print('SessionMBean is: ', sessionMBean)
sessionMBean.createSession(sessionName)
print(String('Session was created ... ').concat(sessionName))

Get the ProxyServiceConfigurationMBean specific to our session

mbean = findService(String("ProxyServiceConfiguration.").concat(sessionName),'com.bea.wli.sb.management.configuration.ProxyServiceConfigurationMBean')

Creates a reference to a folder and 'ProxyServices' is a folder in the project and 'ProxyServices' is a folder in the project

projectName = Refs.makeParentRef(project + '/')
proxyRef = Refs.makeProxyRef(projectName, service)
if action == 'disable' :
print "Disabling " + service +" has been completed"
mbean.disableService(proxyRef)
else :
print "Enabling " + service +" has been completed"
mbean.enableService(proxyRef)

Now commit (activate) the changes

sessionMBean.activateSession(sessionName, "disabled PS")
print
disconnect()
exit()

Place all files in a single folder.

From CMD, Navigate to folder and just call ant

Verify from OSB Portal, the service will be in disabled/enabled format in Operational Settings Tab.

How to install Web Center Portal

Installing Oracle Web Center Portal has the following steps:

  • Download and Install:
    1. Weblogic Server 10.3.6 <!! 12c would not work, Only 11g Release 2 !!>
    2. Web Center Portal
      F
      ollow the complete steps or follow the wizard as shown:
      install_welcome
      install_software_updates
      install_prereqs
      install_location
      install_app_server
      *Please Note: Weblogic option will not be available if the Server version mentioned in the previous step is not 10.3.6. 12c will not work
      install_summary
      install_progress
      install_complete
    3. Database XE(Optional. install only if you dont have database already installed)
    4. RCU
      • In CMD, Open file

        <Download_folder>ofm_rcu_win_11.1.1.8.0_64_disk1_1of1rcuHomeBIN

      • Follow the below steps to install RCU:
        2015-05-05_1724 2015-05-05_1725 2015-05-05_1726 2015-05-05_1726_001 2015-05-05_1727 2015-05-05_1729 2015-05-05_1729_001 2015-05-05_1729_002 2015-05-05_1729_003 2015-05-05_1730 2015-05-05_1730_001 2015-05-05_1731 2015-05-05_1731_001 2015-05-05_1809
  • Configure Domain Config:
    2015-05-05_1818

    2015-05-05_1818_001
    2015-05-05_1819
    2015-05-05_1819_001 2015-05-05_1819_002

    2015-05-05_1820
    2015-05-05_1821
    2015-05-05_1822
    2015-05-05_1822_001
    2015-05-05_1822_002 2015-05-05_1822_003

How to install Weblogic Server 10.3.6

Follow the link: Weblogic Server 10.3.6

  • Accept the user agreement radio button. The link to download(Oracle WebLogic Server 11gR1 (10.3.6) ZIP Distribution) will be enabled.
    Note: You will be asked to login for the same.
  • click on the download link and the server jar file will be downloaded(wls1036_generic.jar)
  • Follow the complete steps mentioned here, or follow below steps:
    • Open CMD
    • Navigate to the directory where the file has been downloaded.
    • Run the following command as Admin

      java -jar wls1036_generic.jar

    • On Welcome, click the Next button.
    • On Choose Middleware Home Directory. select option

      Create a new Middleware Home

      create_middle_home_dir_win
      click the Next button

    • On Register for Security Updates, enter email id, and unselect the security updates checkbox. This will disable update information.
      reg_updates_win
      Click the Next button
    • Select Typical install on Choose Install Type Screen and keep clicking next for default options as shown:
      choose_shortcut_location
      install_type_1036
      choose_products
      jdk_select_win
      choose_install_dirs_win
      install_summary_wininstall_complete_1036
      Click on Done.
    • Domain Configuration(Quick Start) will open:
      quickstart_1036
    • On the QuickStart links panel, select this link

      Getting started with WebLogic Server 10.3.6

    • Follow the wizard as shown below:
      select_domain_source
      Enter domain related details
      specify_domain_name
      image020
      config_server_start_mode
      image022
      config_summary_win
      creating_domain_prog
  • Your weblogic server is now installed.

How to fill a increasing values in a column of a table?

How to fill a increasing values in a column of a table?

Lets assume we have a table
Table name : test

Name Value
Yogesh 0
Yogesh 0
Yogesh 0
Yogesh 0
Yogesh 0
Suresh 0
Suresh 0

Requirement : to insert 1, 2, 3 …. corresponding to values Yogesh

Query to Update :

create sequence seq start with 1 increment by 1;
update test set Value=seq.nextval where Name='Yogesh';
commit;

Output :

Name Value
Yogesh 1
Yogesh 2
Yogesh 3
Yogesh 4
Yogesh 5
Suresh 0
Suresh 0