CE Home
Navigation
Go Back   CrazyEngineers Forum > CE : General Discussions > CE - Quiz | Puzzles | Mathematics
Notices


Advertisements
Reply
 
LinkBack (1) Thread Tools Display Modes

  #11 (permalink)
Old 26th September 2008, 05:32 PM
CE - Apprentice
 
prakash.athani's Avatar
 
Join Date: 30th June 2008
I'm a Crazy Computer Science & IT Engineer
Posts: 48
Default Re: Tough Puzzle: The Parrot Sequence - crack it!

Here is the program for Parrot sequence. I tried it in Java.

Last edited by prakash.athani; 26th September 2008 at 05:49 PM.
prakash.athani is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #12 (permalink)
Old 26th September 2008, 05:45 PM
CE - Apprentice
 
prakash.athani's Avatar
 
Join Date: 30th June 2008
I'm a Crazy Computer Science & IT Engineer
Posts: 48
Default Re: Tough Puzzle: The Parrot Sequence - crack it!

Code:
 
//An attempt in Java to produce parrot sequence
//Works for fair inputs.
//For larger serieses the int in the program should be replaced by long
 
import java.io.*;
 
class ParrotSequence{
 
           //This is main. Here we give initial number to parrot Paco.Also our choice if we want to continue.
 
           public static void main(String args[]) throws IOException {
 
                      int n,choice,result; 
                      DataInputStream din=new DataInputStream(System.in);
                      System.out.println("Give initial number to parrot Paco :");
                      n=Integer.parseInt(din.readLine());
 
                      do {
                                result=count(n); 
                                System.out.println("Paco's reply :"+result);
                                System.out.println("Do you want to give Paco's count back to Paco?(1/0) :");
                                choice=Integer.parseInt(din.readLine());
                                if(choice==1) {
                                        n=result;
                                }
                       }while(choice==1);
 
            }//End of main()
 
 
 
            // I am sure Paco won't count in the following way. But following count produces Paco's count
 
            static int count(int num) {
                       int rev=reverse(num);
                       int result=0,temporaryResult=0,newDigit=0,currentDigit=0,count=0;
                       currentDigit=rev%10; 
 
                       while(rev>0) {
                                newDigit=rev%10; 
 
                                if(currentDigit==newDigit) {
                                          switch(newDigit) {
                                                   case 1:
                                                   case 2:
                                                   case 3:
                                                   case 4:
                                                   case 5:
                                                   case 6:
                                                   case 7:
                                                   case 8:
                                                   case 9:
                                                   case 0:count=count+1;break;
                                          }
                                          currentDigit=newDigit;
                                          rev=rev/10;
                                 }
                                else {
                                          temporaryResult=count*10+currentDigit;
                                          result=result*100+temporaryResult;
                                          currentDigit=newDigit;
                                          count=0; 
                                 }
                      }
                      temporaryResult=count*10+newDigit;
                      result=result*100+temporaryResult; 
                      return(result); 
            }
 
 
 
           // This function returns the reverse of any number passed to it 
 
           static int reverse(int number) {
                     
                     int reverse=0,remainder;
 
                     while(number>0) {
                            remainder=number%10;
                            reverse=reverse*10+remainder;
                            number=number/10;
                     }
 
                     return reverse;
           }
 
 
}//End of class ParrotSequence

Last edited by prakash.athani; 20th October 2008 at 04:02 PM. Reason: To do indenting in the program
prakash.athani is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)
Old 26th September 2008, 07:17 PM
CE - Editor
 
xheavenlyx's Avatar
 
Join Date: 2nd October 2006
Location: Dubai, UAE
I'm a Crazy Electronics Hacker & Engineer
Posts: 573
Default Re: Tough Puzzle: The Parrot Sequence - crack it!

Here is the one I tried. Its written on Python.

It was basically made as a demo for future Crazyengineers software distributions. Contains Installation with CE logo, desktop Icon, Start menu item etc.

Download it from: cecode - Google Code
Name of Program is: CE_ParrotProgie.exe
__________________
Contact: varun(att)crazyengineers(d0t)com.
CLICK HERE FOR MY BLOG ( Robotics, Hardware Hacks and more)
xheavenlyx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)
Old 30th September 2008, 11:58 AM
CE - Apprentice
 
prakash.athani's Avatar
 
Join Date: 30th June 2008
I'm a Crazy Computer Science & IT Engineer
Posts: 48
Default Re: Tough Puzzle: The Parrot Sequence - crack it!

Code:
 
//Parrot sequence in C
 
#include<stdio.h>
#include<conio.h>
 
int main() {
 
    long count(long);
 
    long n,result;
    int choice;
    clrscr();
 
    printf("Give the initial number to parrot PACO(Default:1) :");
    scanf("%d",&n);
 
    do {
           result=count(n);
           printf("PACO's count :%ld\n",result);
           printf("Do you want to continue ?(1/0) :");
           scanf("%d",&choice);
           if(choice==1)
                 n=result;
    }while(choice==1);
 
    getch();
    return 0;
}
 
 
long count(long n) {
 
    long reverse(long);
 
    long result=0,rev=reverse(n);
    int currentDigit=0,newDigit=0,temporaryResult=0,count=0;
 
    currentDigit=rev%10;
 
    while(rev>0) {
          newDigit=rev%10;
 
          if(newDigit==currentDigit) {
                switch(newDigit) {
                         case 1:
                         case 2:
                         case 3:
                         case 4:
                         case 5:
                         case 6:
                         case 7:
                         case 8:
                         case 9:
                         case 0:count=count+1;break;
                }
                currentDigit=newDigit;
                rev=rev/10;
          }
          else{
                temporaryResult=count*10+currentDigit;
                result=result*100+temporaryResult;
                currentDigit=newDigit;
                count=0;
          }
    }
    temporaryResult=count*10+newDigit;
    result=result*100+temporaryResult;
    return(result);
}
 
 
long reverse(long n) {
 
    int remainder;
    long reverse=0;
 
    while(n>0) {
           remainder=n%10;
           reverse=reverse*10+remainder;
           n=n/10;
    }
 
    return(reverse);
}

Last edited by prakash.athani; 20th October 2008 at 04:08 PM. Reason: To do indenting in the program
prakash.athani is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)
Old 25th October 2008, 11:43 PM
CE - Editor
 
xheavenlyx's Avatar
 
Join Date: 2nd October 2006
Location: Dubai, UAE
I'm a Crazy Electronics Hacker & Engineer
Posts: 573
Default Re: Tough Puzzle: The Parrot Sequence - crack it!

wow, C and Java. have to read it though
__________________
Contact: varun(att)crazyengineers(d0t)com.
CLICK HERE FOR MY BLOG ( Robotics, Hardware Hacks and more)
xheavenlyx is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.crazyengineers.com/forum/ce-quiz-puzzles-mathematics/2081-tough-puzzle-parrot-sequence-crack.html
Posted By For Type Date
Uniting Engineers Across The World ! This thread Refback 16th April 2008 12:13 PM


All times are GMT +5.5. The time now is 08:26 AM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.

Advertisements