Skip to main content
added 12 characters in body
Source Link
Gareth
  • 11.4k
  • 1
  • 36
  • 85

Scala

Based on the revised question:

object G extends App
{
    def g(i:IntBigInt,j:IntBigInt)=
    {
        def q(a:IntBigInt,b:IntBigInt):String=
        {
            if(a==0)
                "Integer B is greater than A."
            else 
                if(b==0)
                    "Integer A is greater than B."
                else
                    q(a+1,b-1)
        }
        if(i!=j)q(i-j,i-j)else"A and B are equal"
    }
    val(a,b)=(readLine("A: ").toInt,readLine("B: ").toInt)
    println(g(a,b))
}

Scala

Based on the revised question:

object G extends App
{
    def g(i:Int,j:Int)=
    {
        def q(a:Int,b:Int):String=
        {
            if(a==0)
                "Integer B is greater than A."
            else 
                if(b==0)
                    "Integer A is greater than B."
                else
                    q(a+1,b-1)
        }
        if(i!=j)q(i-j,i-j)else"A and B are equal"
    }
    val(a,b)=(readLine("A: ").toInt,readLine("B: ").toInt)
    println(g(a,b))
}

Scala

Based on the revised question:

object G extends App
{
    def g(i:BigInt,j:BigInt)=
    {
        def q(a:BigInt,b:BigInt):String=
        {
            if(a==0)
                "Integer B is greater than A."
            else 
                if(b==0)
                    "Integer A is greater than B."
                else
                    q(a+1,b-1)
        }
        if(i!=j)q(i-j,i-j)else"A and B are equal"
    }
    val(a,b)=(readLine("A: ").toInt,readLine("B: ").toInt)
    println(g(a,b))
}
added 284 characters in body
Source Link
Gareth
  • 11.4k
  • 1
  • 36
  • 85

Scala, 108 129 characters

def g(i:Int,j:Int)={def q(a:Int,b:Int):Boolean={if(a==0)false else if(b==0)true else q(a+1,b-1)};q(i-j,i-j)}

Ungolfed:

def g(i:Int,j:Int)=
{
    def q(a:Int,b:Int):Boolean=
    {
        if(a==0)
            false
        else
            if(b==0)
                true
            else
                q(a+1,b-1)
    }
    q(i-j,i-j)
}

Returns true if the first value is greater than the second, otherwise returns false.
There's probably a better way than this.

Edit:
BasedBased on the revised question:

object G extends App
{
    def g(i:Int,j:Int)=
    {
        def q(a:Int,b:Int):String=
        {
            if(a==0)
                "Integer B is greater than A."
            else 
                if(b==0)
                    "Integer A is greater than B."
                else
                    q(a+1,b-1)
        }
        if(i!=j)q(i-j,i-j)else"A and B are equal"
    }
    val(a,b)=(readLine("A: ").toInt,readLine("B: ").toInt)
    println(g(a,b))
}

Scala, 108 129 characters

def g(i:Int,j:Int)={def q(a:Int,b:Int):Boolean={if(a==0)false else if(b==0)true else q(a+1,b-1)};q(i-j,i-j)}

Ungolfed:

def g(i:Int,j:Int)=
{
    def q(a:Int,b:Int):Boolean=
    {
        if(a==0)
            false
        else
            if(b==0)
                true
            else
                q(a+1,b-1)
    }
    q(i-j,i-j)
}

Returns true if the first value is greater than the second, otherwise returns false.
There's probably a better way than this.

Edit:
Based on the revised question:

object G extends App
{
    def g(i:Int,j:Int)=
    {
        def q(a:Int,b:Int):String=
        {
            if(a==0)
                "Integer B is greater than A."
            else 
                if(b==0)
                    "Integer A is greater than B."
                else
                    q(a+1,b-1)
        }
        if(i!=j)q(i-j,i-j)else"A and B are equal"
    }
    val(a,b)=(readLine("A: ").toInt,readLine("B: ").toInt)
    println(g(a,b))
}

Scala

Based on the revised question:

object G extends App
{
    def g(i:Int,j:Int)=
    {
        def q(a:Int,b:Int):String=
        {
            if(a==0)
                "Integer B is greater than A."
            else 
                if(b==0)
                    "Integer A is greater than B."
                else
                    q(a+1,b-1)
        }
        if(i!=j)q(i-j,i-j)else"A and B are equal"
    }
    val(a,b)=(readLine("A: ").toInt,readLine("B: ").toInt)
    println(g(a,b))
}
added 284 characters in body
Source Link
Gareth
  • 11.4k
  • 1
  • 36
  • 85

Scala, 108 129 characters

def g(i:Int,j:Int)={def q(a:Int,b:Int):Boolean={if(a==0)false else if(b==0)true else q(a+1,b-1)};q(i-j,i-j)}

Ungolfed:

def g(i:Int,j:Int)=
{
    def q(a:Int,b:Int):Boolean=
    {
        if(a==0)
            false
        else
            if(b==0)
                true
            else
                q(a+1,b-1)
    }
    q(i-j,i-j)
}

Returns true if the first value is greater than the second, otherwise returns false.
There's probably a better way than this.

Edit:
Modified to take input from user (167 characters, takes two numbers followed by newlines from stdin as input)Based on the revised question:

object G extends App
{
    def g(i:Int,j:Int)=
    {
        def q(a:Int,b:Int):Boolean=String=
        {
            if(a==0)false
                "Integer B is greater than A."
            else 
                if(b==0)true
                    "Integer A is greater than B."
                else
                    q(a+1,b-1)
        };var 
 i=io.Source.stdin.getLines.toArray;q       if(i(0!=j).toIntq(i-j,i-j)else"A and B are equal"
    }
    val(1a,b)=(readLine("A: ").toInt,ireadLine(0"B: ").toInt-i)
    println(1g(a,b).toInt) 
}

Scala, 108 129 characters

def g(i:Int,j:Int)={def q(a:Int,b:Int):Boolean={if(a==0)false else if(b==0)true else q(a+1,b-1)};q(i-j,i-j)}

Ungolfed:

def g(i:Int,j:Int)=
{
    def q(a:Int,b:Int):Boolean=
    {
        if(a==0)
            false
        else
            if(b==0)
                true
            else
                q(a+1,b-1)
    }
    q(i-j,i-j)
}

Returns true if the first value is greater than the second, otherwise returns false.
There's probably a better way than this.

Edit:
Modified to take input from user (167 characters, takes two numbers followed by newlines from stdin as input):

def g()={def q(a:Int,b:Int):Boolean={if(a==0)false else if(b==0)true else q(a+1,b-1)};var i=io.Source.stdin.getLines.toArray;q(i(0).toInt-i(1).toInt,i(0).toInt-i(1).toInt)}

Scala, 108 129 characters

def g(i:Int,j:Int)={def q(a:Int,b:Int):Boolean={if(a==0)false else if(b==0)true else q(a+1,b-1)};q(i-j,i-j)}

Ungolfed:

def g(i:Int,j:Int)=
{
    def q(a:Int,b:Int):Boolean=
    {
        if(a==0)
            false
        else
            if(b==0)
                true
            else
                q(a+1,b-1)
    }
    q(i-j,i-j)
}

Returns true if the first value is greater than the second, otherwise returns false.
There's probably a better way than this.

Edit:
Based on the revised question:

object G extends App
{
    def g(i:Int,j:Int)=
    {
        def q(a:Int,b:Int):String=
        {
            if(a==0)
                "Integer B is greater than A."
            else 
                if(b==0)
                    "Integer A is greater than B."
                else
                    q(a+1,b-1)
        } 
        if(i!=j)q(i-j,i-j)else"A and B are equal"
    }
    val(a,b)=(readLine("A: ").toInt,readLine("B: ").toInt)
    println(g(a,b)) 
}
added 309 characters in body
Source Link
Gareth
  • 11.4k
  • 1
  • 36
  • 85
Loading
The if else in the outer function was redundant
Source Link
Gareth
  • 11.4k
  • 1
  • 36
  • 85
Loading
Source Link
Gareth
  • 11.4k
  • 1
  • 36
  • 85
Loading