LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-14-2008, 09:06 AM   #16
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65

Not only did ErV provide you a solid algorithm, I actually wrote out a [rather inefficient] script for you!

What's more, this is not a bad forum for a beginner, but this is a bad forum for a lazy beginner. You have shown absolutely no effort in your trials to get help, henceforth no one is providing much in the way of effort to help you.
 
Old 11-05-2008, 03:27 AM   #17
bcahelper
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
Thumbs up Simplest Solution

There are several technique by which you can solve this. I found a simplest one. I know you are an IGNOU student, finding solution of your assignment.
 
Old 11-05-2008, 03:27 AM   #18
bcahelper
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
I found a easy understandable solution for you. You can check this.

Code:
    echo "Enter Number 1:-"
    read a

    echo "Enter Number 2:-"
    read b

    echo "Enter Number 3:-"
    read c

    gcd=1

    if [ $a -ge $b ]
    then
    s=$a
    else
    s=$b
    fi

    if [ $s -ge $c ]
    then
    t=$s
    else
    t=$c
    fi

    i=1
    while [ $i -le $t ]
    do
    d=`expr $a % $i`
    e=`expr $b % $i`
    f=`expr $c % $i`

    if [ $d -eq 0 -a $e -eq 0 -a $f -eq 0 ]
    then
    gcd=$i
    fi
    i=`expr $i + 1`
    done

    echo "The GCD of $a,$b and $c is $gcd"
This solution is taken from http://bcahelper.blogspot.com Hope this help you.
 
Old 08-15-2009, 04:41 AM   #19
kvmreddy
LQ Newbie
 
Registered: Aug 2009
Posts: 15

Rep: Reputation: 3
gcd of three numbers

check bellow link to find gcd of more than two numbers
http://bashscript.blogspot.com/2009/...o-numbers.html
 
Old 08-15-2009, 05:50 AM   #20
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Here's one that works with any number of command-line arguments:

Code:
#!/bin/bash

python -c 'print reduce((lambda a, b: max(i for i in xrange(1, min(a, b) + 1)
if all(not any(("i" * n).split("i" * i)) for n in (a, b)))), map(int,
__import__("sys").argv[1:]))' $*
 
Old 08-15-2009, 06:00 AM   #21
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by Dan04 View Post
Here's one that works with any number of command-line arguments:

Code:
#!/bin/bash

python -c 'print reduce((lambda a, b: max(i for i in xrange(1, min(a, b) + 1)
if all(not any(("i" * n).split("i" * i)) for n in (a, b)))), map(int,
__import__("sys").argv[1:]))' $*
And those people are telling us that Perl code is unreadable .

...

No, I'm not saying Perl one-liner would be more readable. But, still, in Perl it would just be '@ARGV', not "__import__("sys").argv".
 
Old 08-15-2009, 06:20 AM   #22
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Smile

Quote:
Originally Posted by Sergei Steshenko View Post
And those people are telling us that Perl code is unreadable .

...

No, I'm not saying Perl one-liner would be more readable. But, still, in Perl it would just be '@ARGV', not "__import__("sys").argv".
Yeah, I really think sys.argv should have been a builtin. If I didn't care about having a true one-liner, I'd do:

Code:
from sys import *; print reduce((lambda a, b: max(i for i in xrange(1,
min(a, b) + 1) if all(not any(("i" * n).split("i" * i)) for n in (a,
b)))), map(int, argv[1:]))
Obviously with "import *" instead of just "import argv" so I get a massive number of "Unused import" warnings (and a score of -270) in pylint.

But what do you think of my touch of using str.split to factor an integer? I tried to do it with a regular expression, but couldn't get it to work right.
 
  


Reply

Tags
script, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the greatest software ever ? marozsas Linux - News 1 08-20-2006 08:37 AM
BOGUS.common.04y -> /home/common/Mailbox jayakrishnan Linux - Networking 0 11-19-2005 04:48 AM
the greatest site thanko LQ Suggestions & Feedback 3 12-28-2004 09:16 AM
GCD Algo. Help dontcare Programming 2 10-16-2004 09:50 PM
Isn't Linux the greatest! perry General 8 06-12-2004 03:26 AM


All times are GMT -5. The time now is 10:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration