Monday, 10 April 2017

Tidy Numbers - Display all positive integers in ascending order

Tidy Numbers - Display all positive integers in ascending order


Ananya likes to keep things tidy. Her toys are sorted from smallest to largest and pencils are sorted from shortest to longest. One day, when practicing her counting skills, she noticed that some integers, have their digits sorted in non-decreasing order. She calls 8, 123, 555, and 224488 as numbers tidy. Numbers that do not have this property, like 20, 321, 495 and 999990, are not tidy.
She just finished counting all positive integers in ascending order from 1 to N. What was the last tidy number she counted?
Input
The first line of the input gives the number of test cases, T. T lines follow. Each line describes a test case with a single integer N, the last number counted by Ananya.
Output
For each test case, output is the last tidy number counted by Ananya.
1 ≤ T ≤ 100.
Sample Input:
5
132
1000
7
621
489
Sample Output:
129
999
7
599
489


Solutions :

<?php
$path="input.txt"; //File containing Input elements
$fh=fopen($path,"r");

function tidynum($fh) {
 $res='';
 fscanf($fh,"%d",$case); //$case gives no. of test cases
 for($j=0;$j<$case;$j++) { //Loop moves for total number of cases
  $no=fgets($fh); //Read each remaining element one by one
  $arr=str_split(trim($no)); //split number in array. 
  $cnt=count($arr); //Total number of elements in array
  if($cnt>1) { //If count is greater than one
   for($i=1;$i<$cnt;$i++) { //Loop until finishes the number
    $prev=$i-1; //Previous key
    if($arr[$prev]>$arr[$i]) { //Compare current key to previous key
     $no=$no-1;  //If previous key is greater than current. Substract given number by one
     $arr=str_split($no); //Again split the remaining number, and do same until number donot set in ascending order
     $cnt=count($arr);
     $i=0;
    }
   }
  }
  $res .=$no;
  $res .=PHP_EOL; //Used as end of line
 }
 return $res;
}
$res = tidynum($fh);
echo $res;
?>
Content in input.txt
5
132
1000
7
621
489

Find more algorithm solution in PHP at http://www.fbchandra.com

Wednesday, 5 April 2017

Apps of the year award by facebook

Apps of the year award by facebook


Happy news for mobile apps developers.
Facebook has started a global program FbStart to motivate mobile app startups. Facebook jury will give 'Apps of the Year Awards' to most successful startup for native mobile apps. Startup will get $160,000 in prize.
FbStart helps startup to grow their business through various tool and money. They give prize every year to motivate mobile app startups.
FbStart consider apps under following categories on the basis of performance of apps.
Track Basis
Bootstarp: When an app launched recently and it does not have lots of traffic.
Accelerate: When an app is working very good and fast but looking to scale it.
Package
Social Good Apps: Apps used for Non-profits and NGOs who cares people.
Games: Apps used for games

Prizes
  1. Apps of the Year Awards (Five winners): $160,000 in prizes to five companies worldwide.
  2. Global App of the Year (One winner): $100,000 ($50,000 in cash and $50,000 in Facebook advertising credit). It also include mentorship from facebook team to grow business.
  3. Regional App of the Year (three winners): $15,000 per winner ($7,500 in cash and $7,500 in Facebook advertising credit).
  4. Social Good App of the Year (One winner): $15,000 ($7,500 in cash and $7,500 in Facebook advertising credit).
Eligibility
  1. Only FbStart member is eligible to participate in this competition. If you are not a FbStart member you can apply at https://developers.facebook.com/fbstart/apply
  2. All apps must have used Facebook's developer tools, otherwise it will not be considered.
  3. Only native IOS and andriod mobile apps can apply for it.
  4. Regional finalist has to submit a video of 60-90 seconds for judges to review.
Jury Member
Each and every entries will be judged by esteemed panel of mobile development experts, investors, startup founders, and Facebook.
They judge entries on the following criteria:
  1. Growth and engagement: Is the app growing quickly? Has the app entered new markets, or done a good job retaining new users? Does the app demonstrate potential for growth?
  2. Experience and design: Is the design optimized for the best user experience? Does it have a streamlined look and feel?
  3. Efficiency at scale: How does the app use Facebook or other third-party tools to make app development and iteration efficient?
  4. Leveraging Facebook Platform: Are Facebook Developer products an integral part of the app? Do they improve any of the above three areas?
Deadline
  1. Submisstion starts on March 30, 2017
  2. If you are not a FbStart member, you must apply for FbStart by April 15, 2017 in order to be considered.
  3. When you became FbStart member, you can submit an application for Apps of the year . Submission deadline is on May 1, 2017 at 12:00 PM PST.
For more details go to http://fbchandra.com