Sponsored Content
Top Forums Programming Programming Challenges - A List Post 302120584 by matrixmadhan on Thursday 7th of June 2007 06:59:49 AM
Old 06-07-2007
Quote:
Originally Posted by blowtorch
Challenge: DRAM

Difficulty: Easy to Medium in C, Easy in perl/python

As the problem says, the value of the palindrome may exceed your system's defined integer size in C/C++.
Here is my shot! Smilie

Code:
#include <stdio.h>

int reverseCheck(unsigned long);

int main()
{
  unsigned long number = 2468;
  unsigned long tmp = 0;

  while ( tmp != number ) {
    tmp = reverseCheck(number);
    if( tmp == number ) {
      tmp = number;
    }
    else {
      number += tmp;
    }
  }

  printf("Number:%d\n", number);

  return 0;
}

int reverseCheck(unsigned long number) {
  unsigned int i;
  unsigned long num;
  unsigned long sum;

  for( num = number, i=1; num / 10; i *= 10, num /= 10 );
  for( sum = 0; number > 0; sum += (number % 10) * i, number /= 10, i /= 10);

  return sum;
}

 

3 More Discussions You Might Find Interesting

1. AIX

AIX 6.1 IDSLDAP Installation Challenges

Please bare with me, since I am new to AIX and LDAP. I am attempting to install idsldap server on our AIX 6.1 NIM server. I installed the following packages: root@nim(/)# lslpp -l|grep ldap db2_08_01.ldap 8.1.1.80 COMMITTED DB2 LDAP Support idsldap.clt64bit61.rte 6.1.0.17 COMMITTED... (6 Replies)
Discussion started by: ecollins
6 Replies

2. UNIX for Advanced & Expert Users

Challenges in finding and copying the block

Hi, I have a below challenging task where iam unable to find the block and copy the same into a file. I tried my luck,howver iam unable to reach the first and second step..Can anyone help me with a clue or with the commands so that i can give a try. 1. search the <number>9966993366</number>... (2 Replies)
Discussion started by: cskumar
2 Replies

3. Shell Programming and Scripting

Korn shell script - SQL statement challenges

Hi scripting experts. I have some coding challenges that I'm hoping you can help me out. I have one file#1 that contains the following sql statement that spans over multiple lines: sql Select /*+ use_has(a,b) */ * from customer a, customer_address b where a.id = b.id... (1 Reply)
Discussion started by: pchang
1 Replies
Helpers for manipulating Linux libnuma unsigned long masks(3)Hardware Locality (hwlocHelpers for manipulating Linux libnuma unsigned long masks(3)

NAME
Helpers for manipulating Linux libnuma unsigned long masks - Functions static inline int hwloc_cpuset_to_linux_libnuma_ulongs (hwloc_topology_t topology, hwloc_const_cpuset_t cpuset, unsigned long *mask, unsigned long *maxnode) static inline int hwloc_nodeset_to_linux_libnuma_ulongs (hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, unsigned long *mask, unsigned long *maxnode) static inline int hwloc_cpuset_from_linux_libnuma_ulongs (hwloc_topology_t topology, hwloc_cpuset_t cpuset, const unsigned long *mask, unsigned long maxnode) static inline int hwloc_nodeset_from_linux_libnuma_ulongs (hwloc_topology_t topology, hwloc_nodeset_t nodeset, const unsigned long *mask, unsigned long maxnode) Detailed Description Function Documentation static inline int hwloc_cpuset_from_linux_libnuma_ulongs (hwloc_topology_ttopology, hwloc_cpuset_tcpuset, const unsigned long *mask, unsigned longmaxnode) [static] Convert the array of unsigned long mask into hwloc CPU set. mask is a array of unsigned long that will be read. maxnode contains the maximal node number that may be read in mask. This function may be used after calling get_mempolicy or any other function that takes an array of unsigned long as output parameter (and possibly a maximal node number as input parameter). static inline int hwloc_cpuset_to_linux_libnuma_ulongs (hwloc_topology_ttopology, hwloc_const_cpuset_tcpuset, unsigned long *mask, unsigned long *maxnode) [static] Convert hwloc CPU set cpuset into the array of unsigned long mask. mask is the array of unsigned long that will be filled. maxnode contains the maximal node number that may be stored in mask. maxnode will be set to the maximal node number that was found, plus one. This function may be used before calling set_mempolicy, mbind, migrate_pages or any other function that takes an array of unsigned long and a maximal node number as input parameter. static inline int hwloc_nodeset_from_linux_libnuma_ulongs (hwloc_topology_ttopology, hwloc_nodeset_tnodeset, const unsigned long *mask, unsigned longmaxnode) [static] Convert the array of unsigned long mask into hwloc NUMA node set. mask is a array of unsigned long that will be read. maxnode contains the maximal node number that may be read in mask. This function may be used after calling get_mempolicy or any other function that takes an array of unsigned long as output parameter (and possibly a maximal node number as input parameter). static inline int hwloc_nodeset_to_linux_libnuma_ulongs (hwloc_topology_ttopology, hwloc_const_nodeset_tnodeset, unsigned long *mask, unsigned long *maxnode) [static] Convert hwloc NUMA node set nodeset into the array of unsigned long mask. mask is the array of unsigned long that will be filled. maxnode contains the maximal node number that may be stored in mask. maxnode will be set to the maximal node number that was found, plus one. This function may be used before calling set_mempolicy, mbind, migrate_pages or any other function that takes an array of unsigned long and a maximal node number as input parameter. Author Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code. Version 1.7 Sun Apr 7 2013 Helpers for manipulating Linux libnuma unsigned long masks(3)
All times are GMT -4. The time now is 12:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy