Skip to main content
fixed grammar
Source Link
Ali Alavi
  • 281
  • 1
  • 4

C++

/* 
A one-liner RECUrsive reveRSE function. Observe that the reverse of ana 32-bit unsigned int
can overflow the type (eg recurse (4294967295) = 5927694924 > UINT_MAX), thus the 
return type of the function should be a 64-bit int. 

Usage: recurse(n)
*/
    
int64_t recurse(uint32_t n, int64_t reverse=0L)
{
    return n ? recurse(n/10, n - (n/10)*10 + reverse * 10) : reverse;
}

C++

/* 
A one-liner RECUrsive reveRSE function. Observe that the reverse of an 32-bit unsigned int
can overflow the type (eg recurse (4294967295) = 5927694924 > UINT_MAX), thus the 
return type of the function should be a 64-bit int. 

Usage: recurse(n)
*/
    
int64_t recurse(uint32_t n, int64_t reverse=0L)
{
    return n ? recurse(n/10, n - (n/10)*10 + reverse * 10) : reverse;
}

C++

/* 
A one-liner RECUrsive reveRSE function. Observe that the reverse of a 32-bit unsigned int
can overflow the type (eg recurse (4294967295) = 5927694924 > UINT_MAX), thus the 
return type of the function should be a 64-bit int. 

Usage: recurse(n)
*/
    
int64_t recurse(uint32_t n, int64_t reverse=0L)
{
    return n ? recurse(n/10, n - (n/10)*10 + reverse * 10) : reverse;
}
used ?: instead of if
Source Link
Ali Alavi
  • 281
  • 1
  • 4

C++

/* 
A two one-liner RECUrsive reveRSE function. Observe that the reverse of an 32-bit unsigned int
can overflow the type (eg recurse (4294967295) = 5927694924 > UINT_MAX), thus the 
return type of the function should be a 64-bit int. 

Usage: recurse(n)
*/
    
int64_t recurse(uint32_t n, int64_t reverse=0L)
{
    ifreturn (n) return? recurse(n/10, n - (n/10)*10 + reverse * 10);
    return: reverse;
}

C++

/* 
A two liner RECUrsive reveRSE function. Observe that the reverse of an 32-bit unsigned int
can overflow the type (eg recurse (4294967295) = 5927694924 > UINT_MAX), thus the 
return type of the function should be a 64-bit int. 

Usage: recurse(n)
*/
    
int64_t recurse(uint32_t n, int64_t reverse=0L)
{
    if (n) return recurse(n/10, n - (n/10)*10 + reverse * 10);
    return reverse;
}

C++

/* 
A one-liner RECUrsive reveRSE function. Observe that the reverse of an 32-bit unsigned int
can overflow the type (eg recurse (4294967295) = 5927694924 > UINT_MAX), thus the 
return type of the function should be a 64-bit int. 

Usage: recurse(n)
*/
    
int64_t recurse(uint32_t n, int64_t reverse=0L)
{
    return n ? recurse(n/10, n - (n/10)*10 + reverse * 10) : reverse;
}
Source Link
Ali Alavi
  • 281
  • 1
  • 4

C++

/* 
A two liner RECUrsive reveRSE function. Observe that the reverse of an 32-bit unsigned int
can overflow the type (eg recurse (4294967295) = 5927694924 > UINT_MAX), thus the 
return type of the function should be a 64-bit int. 

Usage: recurse(n)
*/
    
int64_t recurse(uint32_t n, int64_t reverse=0L)
{
    if (n) return recurse(n/10, n - (n/10)*10 + reverse * 10);
    return reverse;
}