<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3861200916183859809</id><updated>2024-09-12T01:50:59.326+05:30</updated><title type='text'>Perl Quiz</title><subtitle type='html'>Blog on Perl</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default?start-index=26&amp;max-results=25'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>82</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-7712559012573620972</id><published>2015-02-12T22:19:00.001+05:30</published><updated>2015-02-12T22:19:30.764+05:30</updated><title type='text'>Quiz 81: Print prime numbers upto N where 1&lt;=N&lt;=1000000</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given a positive integer N, print all prime numbers upto N&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;positive integer N&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium; line-height: 20.6875px;&quot;&gt;prime numbers from 0 to N in new line&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; white-space: nowrap;&quot;&gt;1&amp;lt;=N&amp;lt;=1000000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;20&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;7&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;11&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;17&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;19&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Prime numbers upto 20&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use strict;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use warnings;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp(my $n=&amp;lt;&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($n&amp;gt;1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;2\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my @arr=(2);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for (my $i=3; $i&amp;lt;=$n;$i+=2) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; my $isprime = 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; my $c = sqrt($i) + 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; foreach my $p (@arr) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ($p &amp;gt;= $c) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; last;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ($i % $p == 0) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $isprime = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; last;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; if ($isprime == 1) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;$i\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;push(@arr, $i);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
This algorithms is fastest method to print prime numbers upto 1000000&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/7712559012573620972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2015/02/quiz-81-print-prime-numbers-upto-n.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/7712559012573620972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/7712559012573620972'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2015/02/quiz-81-print-prime-numbers-upto-n.html' title='Quiz 81: Print prime numbers upto N where 1&lt;=N&lt;=1000000'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-5635432100205777456</id><published>2015-02-03T11:11:00.000+05:30</published><updated>2015-02-03T11:11:11.151+05:30</updated><title type='text'>Quiz 80: Remove leading zeros from an array of positive integers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given an array of positive integers, display an array after removing all the leading zeros from original array.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;array having elements&amp;nbsp;separated&amp;nbsp;by &quot;space&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium; line-height: 20.6875px;&quot;&gt;array having elements&amp;nbsp;separated&amp;nbsp;by &quot;space&quot; after removing leading zeros&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;Each element of array is &amp;lt; 1000000&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;007 70 01022 0000000001 00200 20000 0012300&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 24px;&quot;&gt;7 70 1022 1 200 20000 12300&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Simple, removed all zeros before first non-zero character&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use strict;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use warnings;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp(my $line=&amp;lt;&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my @arr=split(&quot; &quot;,$line);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=map{$_%1000000}@arr;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;@arr&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Use mod of maximum value ie 1000000 in our case.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/5635432100205777456/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2015/02/quiz-80-remove-leading-zeros-from-array.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5635432100205777456'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5635432100205777456'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2015/02/quiz-80-remove-leading-zeros-from-array.html' title='Quiz 80: Remove leading zeros from an array of positive integers'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-3299036468167769470</id><published>2015-02-01T19:57:00.001+05:30</published><updated>2015-02-01T19:57:58.167+05:30</updated><title type='text'>Quiz 79: Print a square matrix in anti-clockwise direction</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given a positive integer(n), print square matrix(n x n) in anticlockwise direction.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Check sample input/output for better understanding&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;N=a positive integer&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;square matrix in anti-clockwise direction&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;1 12 11 10&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;2 13 16 9&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;3 14 15 8&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;4 5 6 7&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;in a matrix, 4 x 4, starting printing numbers from 1 in anticlockwise direction ie down,right,up,left.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use strict;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use warnings;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $n=&amp;lt;STDIN&amp;gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $m=$n;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my @arr=();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $ans=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $row=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $col=$n-1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $i=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $j=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;while($n&amp;gt;=1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for($i=$row;$i&amp;lt;=$col;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$arr[$i][$row]=$ans;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$ans++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for($i=$row+1;$i&amp;lt;=$col;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$arr[$col][$i]=$ans;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$ans++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for($i=$col-1;$i&amp;gt;=$row;$i--)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$arr[$i][$col]=$ans;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$ans++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for($i=$col-1;$i&amp;gt;=$row+1;$i--)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$arr[$row][$i]=$ans;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$ans++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$n=$n-2;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$row=$row+1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$col=$col-1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($i=0;$i&amp;lt;$m;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for($j=0;$j&amp;lt;$m;$j++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;print &quot;$arr[$i][$j] &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
On completing 1 full anticlockwise cycle, the dimension of matrix will change by 2, so i used $n=$n-2&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/3299036468167769470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2015/02/quiz-79-print-square-matrix-in-anti.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3299036468167769470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3299036468167769470'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2015/02/quiz-79-print-square-matrix-in-anti.html' title='Quiz 79: Print a square matrix in anti-clockwise direction'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-3696013789231749069</id><published>2015-01-22T20:44:00.001+05:30</published><updated>2015-01-22T20:44:26.908+05:30</updated><title type='text'>Quiz 78: Smallest positive integer not in list</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given an array of positive numbers. Find the smallest positive integer which is not present in list&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;T=number of test cases&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Array(integers&amp;nbsp;separated&amp;nbsp;by space in new line for each test case)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;smallest positive integer in each line for each test case&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;1 6 4 2 5 3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;1 6 5 4 3 7&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;2 3 4 5 6 7&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;7&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;For case 1, smallest positive&amp;nbsp;integer&amp;nbsp;not in list is 7, 1-6 are present, so ans is 7.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use strict;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use warnings;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp(my $t=&amp;lt;&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for(my $j=0;$j&amp;lt;$t;$j++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp(my $line=&amp;lt;&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my @arr=split(&quot; &quot;,$line);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=sort{$a&amp;lt;=&amp;gt;$b}@arr;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $i=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $c=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@arr)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if($_==$i)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if($_+1!=$i+1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;my $tmp=$i;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;$tmp++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;print &quot;$tmp\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;$c++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;last;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;print &quot;$i\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$c++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;last;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$i++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($c==0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;$i\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Use sort function so that question could be solved in very less iterations&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/3696013789231749069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-78-smallest-positive-integer-not.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3696013789231749069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3696013789231749069'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-78-smallest-positive-integer-not.html' title='Quiz 78: Smallest positive integer not in list'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-5184544916399935269</id><published>2015-01-11T16:56:00.001+05:30</published><updated>2015-01-12T20:15:26.776+05:30</updated><title type='text'>Quiz 77: Shortest path of directed Graph</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given distances between different vertices, find the shortest path from vertex i to vertex j&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;N ie no of direct path from one vertex to another&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Next N lines have format- vertexA vertexB distance&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;vertexI vertexJ&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;shortest path&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;length of shortest path&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;11&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;a b 5&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;c a 5&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;a d 10&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;e c 12&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;d f 13&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;f d 1&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;a e 2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;e a 4&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;f e 2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;e f 1&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;b d 3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;a d&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;a e f d&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl2hdTp4OvPVHw1caZxNXruYiVRXa-4PbLjqQf5uPxgPbzPWUs1C5Fhmu48wNXYINTSFQg1PIIRhKLw9HQrEDWyimJG2Wnl-wf7CrS7symRaWeHeGnTT7FM1voh8YMlKoUObtp69wNlVXu/s1600/g.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl2hdTp4OvPVHw1caZxNXruYiVRXa-4PbLjqQf5uPxgPbzPWUs1C5Fhmu48wNXYINTSFQg1PIIRhKLw9HQrEDWyimJG2Wnl-wf7CrS7symRaWeHeGnTT7FM1voh8YMlKoUObtp69wNlVXu/s1600/g.jpg&quot; height=&quot;295&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;shortest path from a to d is a-e-f-d&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use warnings;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use strict;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;use Graph;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use Graph::Directed;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;my $g = &#39;Graph::Directed&#39;-&amp;gt;new;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;chomp(my $n=&amp;lt;&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for(my $i=0;$i&amp;lt;$n;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $tmp=&amp;lt;&amp;gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my @arr=split(&quot; &quot;,$tmp);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$g-&amp;gt;add_weighted_edges(@arr);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my $APSP = $g-&amp;gt;APSP_Floyd_Warshall;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;chomp(my $in=&amp;lt;&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;(my $u,my $v)=split(&quot; &quot;,$in);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; my $w = $APSP-&amp;gt;path_length($u, $v);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ($w) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; my @p = $APSP-&amp;gt;path_vertices($u, $v);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;foreach(@p)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;print &quot;$_ &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;print &quot;\n$w&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Use module Graph for such problems&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/5184544916399935269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-77-shortest-path-of-directed-graph.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5184544916399935269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5184544916399935269'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-77-shortest-path-of-directed-graph.html' title='Quiz 77: Shortest path of directed Graph'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl2hdTp4OvPVHw1caZxNXruYiVRXa-4PbLjqQf5uPxgPbzPWUs1C5Fhmu48wNXYINTSFQg1PIIRhKLw9HQrEDWyimJG2Wnl-wf7CrS7symRaWeHeGnTT7FM1voh8YMlKoUObtp69wNlVXu/s72-c/g.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-5220818102355687283</id><published>2015-01-07T16:14:00.001+05:30</published><updated>2015-01-11T16:57:24.165+05:30</updated><title type='text'>Quiz 76: Find all continuous substrings of all lengths</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;h3&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given a string, you have to&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;all continuous substrings of different lengths&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Ex for abc, print a,ab,abc,b,bc,c&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;h3&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;A String&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/h3&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;h3&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Different substrings in each line&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18.2000007629395px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;h3&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;perl&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;h3&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;p&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;pe&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;per&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;perl&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;e&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;er&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;erl&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;r&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;rl&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;l&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;h3&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;all&amp;nbsp;continuous&amp;nbsp;substrings of length 1 to 4&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
Solution:&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;use strict;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;use warnings;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;chomp(my $a=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;for (my $i=0; $i&amp;lt;=length($a);$i++)&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt; &lt;/span&gt;for (my $j = $i+1;$j&amp;lt;=length($a);$j++)&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;  &lt;/span&gt;print substr($a, $i, $j - $i) .&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&quot;\n&quot;;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot; /&gt;
&lt;/h3&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;h3&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Georgia, Helvetica, Arial, sans-serif; font-size: 13px; font-weight: normal; line-height: 18.2000007629395px;&quot;&gt;
Length can give length of string directly&lt;/div&gt;
&lt;/h3&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/5220818102355687283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-76-find-all-continuous-substrings.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5220818102355687283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5220818102355687283'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-76-find-all-continuous-substrings.html' title='Quiz 76: Find all continuous substrings of all lengths'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-5359402502815674462</id><published>2015-01-04T12:49:00.002+05:30</published><updated>2015-01-04T12:49:56.484+05:30</updated><title type='text'>Quiz 75: Change array to have unique elements only</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given an array, you have to print another array containing only unique elements ie removing duplicate elements&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Array-&amp;gt;Each element separated&amp;nbsp;by space&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Unique Array-&amp;gt;Each element separated by space&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1 3 4 2 3 5 7 7 7 4 9 0 0 2&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;1 3 4 2 5 7 9 0&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium; line-height: 20.6875px;&quot;&gt;removed duplicate elements from original array&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use strict;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;use warnings;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;sub unique {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; my %found;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; grep !$found{$_}++, @_;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp(my $in=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my @array = split(&quot; &quot;,$in);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@array = unique(@array);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@array)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;$_ &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Learn use of Hash and Grep&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/5359402502815674462/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-75-change-array-to-have-unique.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5359402502815674462'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5359402502815674462'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-75-change-array-to-have-unique.html' title='Quiz 75: Change array to have unique elements only'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-5364250983964065334</id><published>2015-01-01T20:41:00.000+05:30</published><updated>2015-01-01T20:41:00.273+05:30</updated><title type='text'>Quiz 74: Rearranging elements of list</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Input is a list containing N numbers from 1 to N in random order.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Rearrange the list in such a way that &quot;position of ith element is the value of ith element of list.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;ie for 4 1 2 3:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;new position of 4 should be value of 4th element ie 3rd&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium; line-height: 20.6875px;&quot;&gt;new position of 1 should be value of 1st element ie 4th&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium; line-height: 20.6875px;&quot;&gt;new position of 2 should be value of 2nd element ie 1st.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium; line-height: 20.6875px;&quot;&gt;new position of 3 should be value of 3rd element ie 2nd.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;So new&amp;nbsp;arrangement&amp;nbsp;would be 2 3 4 1&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: medium; line-height: 20.6875px;&quot;&gt;list containing N numbers from 1 to N in random order&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;list after&amp;nbsp;rearrangement&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;5 6 1 8 3 7 2 4&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;3 7 5 8 1 2 6 4&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explained in problem statement&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($input=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=split(&quot; &quot;,$input);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@arr)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$arr1[$arr[$_-1]-1]=$_;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@arr1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;$_ &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Remember that in perl , array index starts with 0&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/5364250983964065334/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-74-rearranging-elements-of-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5364250983964065334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/5364250983964065334'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2015/01/quiz-74-rearranging-elements-of-list.html' title='Quiz 74: Rearranging elements of list'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-6384890770986876897</id><published>2014-12-31T12:23:00.002+05:30</published><updated>2014-12-31T12:23:18.124+05:30</updated><title type='text'>Quiz 73: Find the max occurrence of a sum in a series</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given an array of N numbers, you have to make all possible sub-arrays having exactly 3 Numbers. Generate sum of each sub-array. Some &quot;Sum&quot; may occur for more than 1 times. Print the Sum which occured maximum number of times and Print the number of times that sum occured. If more than 1 sum occured for max number of times, print the largest sum&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;N-length of array&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;N lines having array elements&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.6875px;&quot;&gt;Maximum occurance of any sum is $num times and largest such sum is $sum&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;n&amp;gt;3&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;6&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 20.6875px;&quot;&gt;Maximum occurance of any sum is 2 times and largest such sum is 12&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(1,5,6)=12 and (4,5,3)=12. All rest sum occurs for 1 time only&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($x=0;$x&amp;lt;$n;$x++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;chomp($tmp=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;push(@arr,$tmp);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;%hash;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$max=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$num=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$check=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($i=0;$i&amp;lt;$n-2;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;for($j=$i+1;$j&amp;lt;$n-1;$j++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;for($k=$j+1;$k&amp;lt;$n;$k++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;#print &quot;$arr[$i] $arr[$j] $arr[$k]\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;$sum=$arr[$i]+$arr[$j]+$arr[$k];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if($check==0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if($sum&amp;gt;$max){$max=$sum;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;if($hash{$sum})&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;$check++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;$hash{$sum}++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if($num&amp;lt;=$hash{$sum})&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;$num=$hash{$sum};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;$max=$sum;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;$hash{$sum}=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;Maximum occurance of any sum is $num times and largest such sum is $max&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Take care of condition when each sum occur only 1 time&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/6384890770986876897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-73-find-max-occurrence-of-sum-in.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/6384890770986876897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/6384890770986876897'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-73-find-max-occurrence-of-sum-in.html' title='Quiz 73: Find the max occurrence of a sum in a series'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-9207545140561994736</id><published>2014-12-31T10:46:00.000+05:30</published><updated>2014-12-31T10:46:16.460+05:30</updated><title type='text'>Quiz 72: Flip the bits</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given a&amp;nbsp;decimal number, convert it to binary. Flip the bits ie change 0 to 1 and 1 to 0 and then convert back to decimal.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Decimal Number&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;line-height: 18pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Decimal Number after making changes&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;none&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;5&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
2&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;5 in binary is 101, after flipping bits-010 which in decimal is 2.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;#function to convert binary to decimal&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;sub con {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; return unpack(&quot;N&quot;, pack(&quot;B32&quot;, substr(&quot;0&quot; x 32 . shift, -32)));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$binary = sprintf (&quot;%b&quot;,$n);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;#print &quot;$binary\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=split(//,$binary);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@arr)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if($_ == 0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$_ = 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$_ = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$flip=join(&quot;&quot;,@arr);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;#print &quot;$flip\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$ans=con($flip);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print $ans;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Learn conversion of Decimal to Binary and vice versa.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/9207545140561994736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-72-flip-bits.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/9207545140561994736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/9207545140561994736'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-72-flip-bits.html' title='Quiz 72: Flip the bits'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-1497710597459390712</id><published>2014-12-29T21:29:00.000+05:30</published><updated>2014-12-29T21:29:05.651+05:30</updated><title type='text'>Quiz 71: Print all combinations of a sentence</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;Given a&amp;nbsp;sentence&amp;nbsp;like &quot;i love perl&quot;, print all&amp;nbsp;sentences&amp;nbsp;that can be formed using all words from original&amp;nbsp;sentence.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;A Sentence where words are seprated by single space&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;line-height: 18pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 20.6875px;&quot;&gt;All combinations in different lines&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;none&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;I love perl&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
I love perl&lt;br /&gt;
I perl love&lt;br /&gt;
perl I love&lt;br /&gt;
perl love I&lt;br /&gt;
love I perl&lt;br /&gt;
love perl I&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;sentence have 3 words , so 6 different combinations&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($line=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@array=split(&quot; &quot;,$line);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;sub fact {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp;my $tmp = shift;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp;return 1 if $tmp &amp;lt; 2;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp;return $tmp*fact($tmp-1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;my %seen;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$len=@array;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$count = fact($len);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$nr &amp;nbsp;= 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;while( $nr &amp;lt; $count ) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; $var = 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; @arr;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; while( $var ) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for( my $i = 0; $i &amp;lt; $len; ++$i ) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $arr[$i] = $array[ rand $len ];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; my %unique;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; my $unique = 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for my $c ( @arr ) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if( ++$unique{$c} &amp;gt; 1 ) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $unique = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if( $unique == 1 ) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $var = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; if( exists $seen{ &quot;@arr&quot; } ) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; next;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; else {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; local $&quot; = &quot;\t&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach(@arr)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;$_ &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; ++$seen{&quot;@arr&quot;};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; ++$nr;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Use factorial to find number of combinations&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/1497710597459390712/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-71-print-all-combinations-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/1497710597459390712'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/1497710597459390712'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-71-print-all-combinations-of.html' title='Quiz 71: Print all combinations of a sentence'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-2602519876213707274</id><published>2014-12-09T12:32:00.002+05:30</published><updated>2014-12-09T12:32:51.560+05:30</updated><title type='text'>Quiz 70: Find the secret code</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Input is in form of FNAME LNAME AGE, where FNAME and LNAME are uppercase and AGE is numerical.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Secret code is a string which contains first letter of FNAME, first 4 letters of LNAME and reverse of age.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;It is guaranteed that LNAME have length atleast 4&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 20.7000007629395px;&quot;&gt;FNAME LNAME AGE&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 20.7000007629395px;&quot;&gt;SECRET NAME&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;PRIYANKA CHOPRA 31&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;PCHOP13&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;P-CHOP-13&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($str=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$str=~ /([A-Z])[A-Z]+\s([A-Z]{4})[A-z]+\s&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;(\d+)/;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print $1.$2.reverse($3);&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
{4}used to capture 4 characters&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/2602519876213707274/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-70-find-secret-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/2602519876213707274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/2602519876213707274'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-70-find-secret-code.html' title='Quiz 70: Find the secret code'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-4001350179181609841</id><published>2014-12-04T14:41:00.000+05:30</published><updated>2014-12-04T14:41:30.813+05:30</updated><title type='text'>Quiz 69: Order of getting Priyanka&#39;s autograph</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;N people are standing in a line to take autograph from famous actress &quot;Priyanka&quot;. People can be&amp;nbsp;classified&amp;nbsp;to boy, girl, man and woman. Priyanka decided that 1st she will give autograph to 1st girl in the line, then next girl and so on. Then she will follow this rule for woman, then boy and then man.Given input in form of &quot;name classification&quot;, print the names in order of getting autograph.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N lines in format &quot;name classification&quot;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 20.7000007629395px;&quot;&gt;N lines having names&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;10&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;saurabh boy&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;shikha girl&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;satyam boy&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;kanchan girl&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;sameer man&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;sonali woman&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;shree man&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;neelabh boy&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;sony girl&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;karishma woman&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;shikha&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;kanchan&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;sony&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;sonali&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;karishma&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;saurabh&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;satyam&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;neelabh&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;sameer&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;shree&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;girls&amp;nbsp;followed&amp;nbsp;by women and so on&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($i=0;$i&amp;lt;$n;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($line=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;($a,$b)=split(&quot; &quot;,$line);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($b eq &#39;girl&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;push(@g,$a);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;elsif($b eq &#39;boy&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;push(@b,$a);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;elsif($b eq &#39;man&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;push(@m,$a);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;push(@w,$a);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@g){print &quot;$_\n&quot;;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@w){print &quot;$_\n&quot;;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@b){print &quot;$_\n&quot;;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@m){print &quot;$_\n&quot;;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
push names to different classifications&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/4001350179181609841/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-69-order-of-getting-priyankas.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/4001350179181609841'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/4001350179181609841'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-69-order-of-getting-priyankas.html' title='Quiz 69: Order of getting Priyanka&#39;s autograph'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-1716902882562480037</id><published>2014-12-04T12:04:00.000+05:30</published><updated>2014-12-04T12:04:30.417+05:30</updated><title type='text'>Quiz 68: Convert to uppercase and lowercase</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Given a Word consisting of both uppercase and lowercase aplhabets. Convert the whole string to either uppercase or lowercase such that number of alphabets which require conversions in minimum ie &#39;Hello&#39; should be&amp;nbsp;changed&amp;nbsp;to &#39;hello&#39; and &#39;HELlo&#39; should be changed to &#39;HELLO&#39;. If equal possibilty to convert to uppercase or lowercase, then change to lowercase.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;String str&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 20.7000007629395px;&quot;&gt;Uppercase str/Lowercase str&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;elePHAnTs&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
elephants&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;more lowercase&amp;nbsp;alphabets&amp;nbsp;in original string, so convert to lowercase&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($str=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;while($str=~ /[A-Z]/g)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$u++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$l=length($str)-$u;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($l&amp;gt;=$u)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;\L$str&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
use \U or \L to convert string to uppercase/lowercase&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/1716902882562480037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-68-convert-to-uppercase-and.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/1716902882562480037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/1716902882562480037'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-68-convert-to-uppercase-and.html' title='Quiz 68: Convert to uppercase and lowercase'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-3072156269344365596</id><published>2014-12-04T11:29:00.002+05:30</published><updated>2014-12-04T11:29:38.675+05:30</updated><title type='text'>Quiz 67: typing namaste</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Shikhi just learned typing. She still types many&amp;nbsp;unnecessary alphabets.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;She wants to type &quot;namaste&quot;, but end up typing sting str. Print &quot;YES&quot; if &quot;namaste&quot; can be obtained by deleting &amp;nbsp;some alphabets from string str, else print &quot;NO&quot;. Example, &quot;YES&quot; for &quot;asnamastiie&quot;, &quot;NO&quot; for &quot;namteass&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;String str&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 20.7000007629395px;&quot;&gt;YES/NO&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;aeiounqwsamqwsdaiutstqqwwseqjal&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
YES&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Red color for namaste-&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;aeiou&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;qws&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;am&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;qwsd&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;a&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;iut&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;st&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;qqwws&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;e&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: 18px; line-height: 24px;&quot;&gt;qjal&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($str=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($str=~ /n.*a.*m.*a.*s.*t.*e.*/)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;YES&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;NO&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Simple regex use case&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/3072156269344365596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-67-typing-namaste.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3072156269344365596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3072156269344365596'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-67-typing-namaste.html' title='Quiz 67: typing namaste'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-4162235322346702521</id><published>2014-12-03T15:08:00.000+05:30</published><updated>2014-12-03T15:08:03.024+05:30</updated><title type='text'>Quiz 66: Find if number is special number</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Given a number N. N is considered special if for any positive integer i, N=(i*(i+1))/2. Print &quot;YES&quot; if N is special number, else print &quot;NO&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 20.7000007629395px;&quot;&gt;YES/NO&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;210&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
YES&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;for i=20,(20*21)/2=210. So 210 is special number&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$c=sqrt((8*$n)+1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($c == int($c))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;YES&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;NO&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Solving maths equation, you can narrow down to check if 8N+1 is a perfect square.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/4162235322346702521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-66-find-if-number-is-special-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/4162235322346702521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/4162235322346702521'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-66-find-if-number-is-special-number.html' title='Quiz 66: Find if number is special number'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-8512921987835091443</id><published>2014-12-03T14:53:00.001+05:30</published><updated>2014-12-03T14:53:10.416+05:30</updated><title type='text'>Quiz 65: Find index of boy holding the ball</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;There are N boys playing a game. They form a circle and have index from 1 to N clockwise. At the start, boy-1 is holding the ball. He says 1 and gives next person. next person says 2 and gives ball to next to next ie 2nd boy to him and so on. Games ends after N-1 passes. Print N-1 indexes showing index of boy holding the ball&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 20.7000007629395px;&quot;&gt;N-1 indexes showing index of boy holding the ball&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;11&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
2 4 7 11 5 11 7 4 2 1&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1+1=2,2+2=4,4+3=7,7+4=11,11+5=16-11=5 and so on&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$c=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($i=1;$i&amp;lt;$n;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$c=$c+$i;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$c=$c%$n;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($c==0){$c=$n;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;$c &quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Take care of condition when ball is with last person to reset counter to 1.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/8512921987835091443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-65-find-index-of-boy-holding-ball.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/8512921987835091443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/8512921987835091443'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-65-find-index-of-boy-holding-ball.html' title='Quiz 65: Find index of boy holding the ball'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-4949089650298040593</id><published>2014-12-03T14:17:00.001+05:30</published><updated>2014-12-03T14:17:42.431+05:30</updated><title type='text'>Quiz 64: Message from newspaper content</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Sarita have a newspaper cutting. She wants to make a new message by cutting&amp;nbsp;alphabets&amp;nbsp;from newspaper and paste them on a board. For spaces, she may just leave some space in her board, no need to cut from newspaper. She should take care of Uppercase and Lowercase. Obviously an alphabet taken from newspaper once could not be used again. Given content of newspaper cutting and message, print &quot;YES&quot; or &quot;NO&quot; whether message can be written from newspaper cutting.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;newspaper content&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Message content&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;YES/NO&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;my favorite animals are Cat,Lion and Frog&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;i love to Code and Code&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
NO&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;C appears only 1 times in Newspaper and 2 times in Message.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($h=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$h=~ s/ //g;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($s=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$s=~ s/ //g;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=split(//,$s);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$len=@arr;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach($i=0;$i&amp;lt;$len;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($h =~ /$arr[$i]/)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$h=~ s/$arr[$i]//;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;NO&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;exit;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;YES&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Exit the code as soon as 1st not matching condition is met.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/4949089650298040593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-64-message-from-newspaper-content.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/4949089650298040593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/4949089650298040593'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-64-message-from-newspaper-content.html' title='Quiz 64: Message from newspaper content'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-3898462095298399272</id><published>2014-12-03T12:39:00.001+05:30</published><updated>2014-12-03T12:39:21.920+05:30</updated><title type='text'>Quiz 63: Find the winning team</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;In a cricket tournament, N matches were played. Sunil just have a data about winner of match i. The team with maximum number of wins is the winner of the tournament. Find the winner team. It is guaranteed that there is only 1 winner team.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;N lines having a winner if ith match&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;name of winner team&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;kkr&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;kkr&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;dd&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;mi&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;cs&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;dd&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;dd&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;cs&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;mi&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;rr&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
dd&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;dd won 3 games which is highest&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;%hash;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$max=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for(1..$n)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;chomp($tmp=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if($hash{$tmp})&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$hash{$tmp}++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if($hash{$tmp}&amp;gt;$max)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;$max=$hash{$tmp};&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;$ans=$tmp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$hash{$tmp}=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if($max==1){$ans=$tmp;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print $ans;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Maintain Hash and increment value to find maximum wins&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/3898462095298399272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-63-find-winning-team.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3898462095298399272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3898462095298399272'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-63-find-winning-team.html' title='Quiz 63: Find the winning team'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-483142069323901870</id><published>2014-12-02T17:05:00.000+05:30</published><updated>2014-12-02T17:05:19.831+05:30</updated><title type='text'>Quiz 62: Find the height of tallest tower</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Cheeku have N wooden blocks of height 1cm and different widths. She can place 2 or wooden blocks over each other a form a tower if width of blocks are same. Find the height of height tower which can be made and number of total tower formed using all the wooden blocks.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 18pt;&quot;&gt;width of blocks&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;separated&lt;/span&gt;&lt;span style=&quot;font-size: 18px; line-height: 18pt;&quot;&gt;&amp;nbsp;by spaces&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;height of highest tower(space)Total number of towers&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;8 1 2 3 1 1 2 2 3 5&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
3 5&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Tower width,Height= (8,1)(1,3)(2,3)(3,2)(5,1), so max height is 3 and number of towers are 5.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($line=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=split(&quot; &quot;,$line);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;%hash=();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$max=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$ans=$n;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@arr)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if($hash{$_})&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$hash{$_}++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$ans--;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if($hash{$_}&amp;gt;$max){$max=$hash{$_};}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;$hash{$_}=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;$max $ans&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Maintain Hash and increment value to find max height.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/483142069323901870/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-62-find-height-of-tallest-tower.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/483142069323901870'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/483142069323901870'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-62-find-height-of-tallest-tower.html' title='Quiz 62: Find the height of tallest tower'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-3172291958049718378</id><published>2014-12-02T12:43:00.000+05:30</published><updated>2014-12-02T12:43:54.572+05:30</updated><title type='text'>Quiz 61: Find number of matching pairs of brackets</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3 style=&quot;color: #39424e; line-height: 24px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;h3 style=&quot;color: #39424e; line-height: 24px; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Problem:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Given a sequence containing only &#39;(&#39; and &#39;)&#39; , find number of matching &#39;()&#39;. Example in ((()())), number of matching pairs are 4. In ()())))(), number of matching pairs are 3.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sequence&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;Number of Matching pairs&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;()(()()))))((()()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Pairs marked in different colors are&amp;nbsp;&lt;span style=&quot;font-size: medium; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: orange;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: yellow;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-size: medium; line-height: 24px;&quot;&gt;)))((&lt;/span&gt;&lt;span style=&quot;font-size: medium; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: cyan;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: medium; line-height: 24px;&quot;&gt;&lt;span style=&quot;color: magenta;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=split(//,$n);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$c=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$ans=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@arr)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($_ eq &#39;(&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$c++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($_ eq &#39;)&#39; and $c&amp;gt;0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$c--;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$ans++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print $ans;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
First find &#39;(&#39; and then matching &#39;)&#39;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/3172291958049718378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-61-find-number-of-matching-pairs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3172291958049718378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/3172291958049718378'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-61-find-number-of-matching-pairs.html' title='Quiz 61: Find number of matching pairs of brackets'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-8652640543524789693</id><published>2014-12-01T15:34:00.001+05:30</published><updated>2014-12-01T21:38:06.788+05:30</updated><title type='text'>Quiz 60: Make the shortest numbers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Given a number, find the smallest possible number using the digits of original number without any leading 0&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Number&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;Smallest possible number&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;70205008&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;20000578&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;meets the problem statement&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($a=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=split(//,$a);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=sort(@arr);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$len=@arr;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$j=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($i=0;$i&amp;lt;$len;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($arr[$i]==0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$j++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;last;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($j&amp;gt;0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$arr[0]=$arr[$j];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$arr[$j]=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print @arr;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Sort array and then count number of &amp;nbsp;leading zeros and code accordingly&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/8652640543524789693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-60-make-shortest-numbers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/8652640543524789693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/8652640543524789693'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-60-make-shortest-numbers.html' title='Quiz 60: Make the shortest numbers'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-656652542682712817</id><published>2014-12-01T14:50:00.003+05:30</published><updated>2014-12-01T14:50:54.616+05:30</updated><title type='text'>Quiz 59: Is the matrix symmetric</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Given a NxN Matrix(N is odd). Each block contains a letter from A-Z. Find whether matrix is&amp;nbsp;symmetric&amp;nbsp;with respect to central block. Central block for 3x3 matrix is (1,1), index starting from 0.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Next N lines containing content of each row.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;YES/NO- whether matrix is symetric or not&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;N is always odd&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;ABFWW&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;TTTOP&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;ASDSA&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;POTTT&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;WWFBA&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;YES&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;It is symmetric wrt to D(2,2) , example (0,0)=(4,4)=A&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($n=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$str;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($i=0;$i&amp;lt;$n;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($tmp=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$str=$str.$tmp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($str eq reverse($str))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;YES&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;print &quot;NO&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
No need to make N arrays and then compare, use string&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/656652542682712817/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-59-is-matrix-symmetric.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/656652542682712817'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/656652542682712817'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-59-is-matrix-symmetric.html' title='Quiz 59: Is the matrix symmetric'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-8146440717250906968</id><published>2014-12-01T12:54:00.002+05:30</published><updated>2014-12-01T12:54:51.363+05:30</updated><title type='text'>Quiz 58: Make the sequence increasing</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Given a sequence, you have to make the sequence increasing by adding a number d any number of times. like if d is 2 and sequence is 5 1, then adding 2 for 3 times will make sequence 5 7 which is in increasing order. Number of moves for this example was 3. Find minimum number of moves required to make the sequence increasing.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N D(total numbers and number D to be added)&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 18pt;&quot;&gt;sequence(each number&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;separated&lt;/span&gt;&lt;span style=&quot;font-size: 18px; line-height: 18pt;&quot;&gt;&amp;nbsp;by space)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3 style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 24px;&quot;&gt;Minimum&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: 18px; line-height: 18pt;&quot;&gt;&amp;nbsp;number of moves&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;6 3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;1 5 2 22 21 2&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;11&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;new sequence would be 1,5,8(2+3*2),22,24(21+3*1),26(2+3*8), so total=2+1+8=11&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($line1=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;($n,$d)=split(&quot; &quot;,$line1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($line2=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=split(&quot; &quot;,$line2);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$ans=0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($i=0;$i&amp;lt;$n-1;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($arr[$i]&amp;gt;=$arr[$i+1])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$dif=$arr[$i]-$arr[$i+1];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$num=int($dif/$d)+1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$ans=$ans+$num;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;$arr[$i+1]=$arr[$i+1]+($num*$d);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print $ans;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
Update array elements and continue comparing&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/8146440717250906968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-58-make-sequence-increasing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/8146440717250906968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/8146440717250906968'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-58-make-sequence-increasing.html' title='Quiz 58: Make the sequence increasing'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3861200916183859809.post-1559930270049737188</id><published>2014-12-01T11:39:00.000+05:30</published><updated>2014-12-01T11:39:12.966+05:30</updated><title type='text'>Quiz 57: Dice game</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Problem:&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 18px; line-height: 20.7000007629395px;&quot;&gt;Rohit, Neelabh and Priya are planning a holiday trip together, but all of them wants to go to different destinations.They decided to roll a regular dice and the person having highest score wins and all will go to his/her destination for holiday. First Rohit and Neelabh play their dice. Priya now wants to calculate chances of her win. If Priya got maximum score and it is a tie with neelabh or Rohit then too Priya will win. Print in form m/n where m and n cannot be furthur divided ie 3/6 should be 1/2&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Input Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;T=number of test cases&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;A B(score of Rohit and Neelabh)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;h3&gt;
&lt;strong style=&quot;font-family: Verdana, sans-serif; font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Output Format:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;N lines containing probability&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #39424e; font-size: 18px; line-height: 18pt; margin: 0in 0in 0.0001pt; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;nobr style=&quot;-webkit-transition: none; border-width: 0px; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; padding: 0px; transition: none; vertical-align: 0px;&quot;&gt;&lt;/nobr&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; color: #39424e; font-size: 18px; margin: 0in 0in 0.0001pt; outline: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;strong style=&quot;font-style: inherit; font-variant: inherit; line-height: inherit; outline: 0px;&quot;&gt;Constraints:&lt;/strong&gt;&lt;span class=&quot;apple-converted-space&quot; style=&quot;line-height: 18pt;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #39424e;&quot;&gt;&lt;span style=&quot;white-space: nowrap;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Input&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;1 1&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;2 1&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;2 3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;4 2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;4 5&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;6 3&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Sample Output:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;1/1&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;5/6&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;2/3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;1/2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;1/3&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #39424e; font-family: Verdana, sans-serif; font-size: medium;&quot;&gt;&lt;span style=&quot;line-height: 24px;&quot;&gt;1/6&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Explanations:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;for case 1. whatever output Priya gets she will win. So ans is 6/6 ie 1/1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
Solution:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($t=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for($i=0;$i&amp;lt;$t;$i++)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;chomp($in=&amp;lt;STDIN&amp;gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$in=~ / /;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$a=$`;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;$b=$&#39;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if($a&amp;lt;$b){$a=$b;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;@arr=(&#39;0/0&#39;,&#39;1/1&#39;,&#39;5/6&#39;,&#39;2/3&#39;,&#39;1/2&#39;,&#39;1/3&#39;,&#39;1/6&#39;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;push(@out,$arr[$a]);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;foreach(@out)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;print &quot;$_\n&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;div&gt;
&lt;h3&gt;
Tips:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
better to use arrays if number of output are limited.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://perlquiz.blogspot.com/feeds/1559930270049737188/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-57-dice-game.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/1559930270049737188'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3861200916183859809/posts/default/1559930270049737188'/><link rel='alternate' type='text/html' href='http://perlquiz.blogspot.com/2014/12/quiz-57-dice-game.html' title='Quiz 57: Dice game'/><author><name>saurabh2k26</name><uri>http://www.blogger.com/profile/00524123124401905843</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>