15,671,597 members
See more:
A positive integer like 183672 will be called an oddly orderly number if it follows following characteristics:-
1. The individual digits of the number are alternating as odd digit followed by an even digit,then followed by an odd digit and so on. That is the digits of the number from left to right alternate as odd-even.
2. Individual odd digits from left to right are in increasing order.
3. Individual even digits from left to right are in decreasing order.

OUTPUT: All positive integers in which the numbers are oddly orderly..
Posted
Updated 21-Oct-12 5:59am
v2
Richard MacCutchan 21-Oct-12 11:58am
OK, I give up, what's the answer?
CPallini 21-Oct-12 12:09pm
91 numbers, if I'm not wrong. :-)
[UPDATE]
I was wrong: now I've found 251 of them.
[/UPDATE]
Nelek 21-Oct-12 17:20pm
Liquid nitrogen
Perić Željko 22-Oct-12 10:24am
Interesting math problem, you did not declare range of numbers, where you search for the oddly numbers. Is it all positive numbers from 100000 to 999999 ?
maj000 22-Oct-12 11:16am
Presumably the range is 12 (or 1432 if you insist on at least 2 odd and even numbers for them to have an order) to 183654729.

## Solution 4

Because of my curiosity what CPallini thinks of my code here it is :

C# 4.0 .Net 4.0 IDE Sharp Develop 4.1

C#
```using System;
using System.IO;

namespace Oddly_orderly_numbers
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");

const int start = 12; // min value of oddly number

int end = 183654729; // max value of oddly number

int i = 0;//
int k = 0;//
int j = 0;//

int digit = 0;//

string odd = "";//
string even = "";//

string number = "";// String representation of number

bool is_oddly = false;//

for(i=start;i<end+1;i++)
{
//
// Test value relation
// betveen odd and even digits inside of number
//
number = Convert.ToString(i);
k = number.Length;
is_oddly = false;
if (k == 2)
{
is_oddly = true;
}
else
{
//
// test odd values
//
k = number.Length;
odd = "";
for (j=0;j<k;j+=2)
{
odd = odd + number.Substring(j,1);
}

k = odd.Length-1;
is_oddly = true;
for(j=0;j<k;j++)
{
if (odd[j]>=odd[j+1])
{
is_oddly=false;
j=k;
}
}

if (is_oddly)
{
//
// test even values
//
k = number.Length;
even = "";
for (j=1;j<k;j+=2)
{
even = even + number.Substring(j,1);
}

k = even.Length-1;
is_oddly = true;
for(j=0;j<k;j++)
{
if (even[j]<=even[j+1])
{
is_oddly=false;
j=k;
}
}
}
}

//
// Test odd - even position of digits inside of number
//
if (is_oddly)
{
number = Convert.ToString(i);
k = number.Length + 1;
is_oddly = false;
for(j=1;j<k;j++)
{
digit = Convert.ToInt32(number.Substring(j-1,1));
if (j%2!=0 && digit%2!=0)
{
is_oddly = true;
}
if (j%2==0 && digit%2==0)
{
is_oddly = true;
}
else if (j%2!=0 && digit%2==0)
{
is_oddly = false;
j = k;
}
else if (j%2==0 && digit%2!=0)
{
is_oddly = false;
j = k;
}

}
}

if(is_oddly)
{
StreamWriter sr = new StreamWriter("output.txt",true);

Console.WriteLine(number);
sr.WriteLine(number);

sr.Close();
}
}

Console.Write("Press any key to continue . . . ");
}
}
}```

Program is extremely slow but I like it and it gives correct result.
Also I would like to see fastest program for solving ODDLY problem,
for the range of let say min=12,max=9999999999. (1836547290)
Upper code would need several hours to solve this task.
So may this be the chalenge !

All the best,
Perić Željko

v3
CPallini 23-Oct-12 4:19am
Well, above all a program must be correct. And it looks yours is (have my 5).
I wouldn't use string<->number conversion but that's matter of taste.
Perić Željko 23-Oct-12 5:14am
Thanks to CPAllini for hi five. When 'string' type is in question, for some reason that I shall keep to my self , I decided not to use 'char' type any more except it is really,really,really... necessary. I shall always use 'string' type for non-numeric type of variables.
CPallini 23-Oct-12 6:51am
I wouldn't use char either. I would use just int.
Perić Željko 23-Oct-12 7:06am
Well such solution exists as 'Solution number three'.

## Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

## Solution 2

Sorry we don't write full code for you.
Just a suggestion: go recursive.

Perić Željko 22-Oct-12 15:24pm
My suggestion do not do it in C
CPallini 22-Oct-12 16:49pm
Why not?
BTW output of the C program:
[removed wrong output]
Perić Željko 22-Oct-12 17:16pm
What shall I conclude from output of C program;
And what BTW is ?
CPallini 22-Oct-12 17:23pm
You may establish if it is correct or not.
If it is correct then it might be a point in favour of 'using C programming language'.
BTW is the acronym of By The Way.
Perić Željko 22-Oct-12 17:51pm
Thanks for clarification of BTW, I really didn't know that, and I see some illogical sequence shown in output row. Here is my output so if you have time and energy to test program that way...program was written in C# .Net 4.0 as console application... output: 12 14 16 18 30 32 34 36 38 50 52 54 56 58 70 72 74 76 78 90 92 94 96 98 103 105 107 109 123 125 127 129 143 145 147 149 163 165 167 169 183 185 187 189 305 307 309 325 327 329 345 347 349 365 367 369 385 387 389 507 509 527 529 547 549 567 569 587 589 709 729 749 769 789 1230 1250 1270 1290 1430 1432 1450 1452 1470 1472 1490 1492 1630 1632 1634 1650 1652 1654 1670 1672 1674 1690 1692 1694 1830 1832 1834 1836 1850 1852 1854 1856 1870 1872 1874 1876 1890 1892 1894 1896 3250 3270 3290 3450 3452 3470 3472 3490 3492 3650 3652 3654 3670 3672 3674 3690 3692 3694 3850 3852 3854 3856 3870 3872 3874 3876 3890 3892 3894 3896 5270 5290 5470 5472 5490 5492 5670 5672 5674 5690 5692 5694 5870 5872 5874 5876 5890 5892 5894 5896 7290 7490 7492 7690 7692 7694 7890 7892 7894 7896 12305 12307 12309 12507 12509 12709 14305 14307 14309 14325 14327 14329 14507 14509 14527 14529 14709 14729 16305 16307 16309 16325 16327 16329 16345 16347 16349 16507 16509 16527 16529 16547 16549 16709 16729 16749 18305 18307 18309 18325 18327 18329 18345 18347 18349 18365 18367 18369 18507 18509 18527 18529 18547 18549 18567 18569 18709 18729 18749 18769 32507 32509 32709 34507 34509 34527 34529 34709 34729 36507 36509 36527 36529 36547 36549 36709 36729 36749 38507 38509 38527 38529 38547 38549 38567 38569 38709 38729 38749 38769 52709 54709 54729 56709 56729 56749 58709 58729 58749 58769 143250 143270 143290 145270 145290 147290 163250 163270 163290 163450 163452 163470 163472 163490 163492 165270 165290 165470 165472 165490 165492 167290 167490 167492 183250 183270 183290 183450 183452 183470 183472 183490 183492 183650 183652 183654 183670 183672 183674 183690 183692 183694 185270 185290 185470 185472 185490 185492 185670 185672 185674 185690 185692 185694 187290 187490 187492 187690 187692 187694 345270 345290 347290 365270 365290 365470 365472 365490 365492 367290 367490 367492 385270 385290 385470 385472 385490 385492 385670 385672 385674 385690 385692 385694 387290 387490 387492 387690 387692 387694 547290 567290 567490 567492 587290 587490 587492 587690 587692 587694 1432507 1432509 1432709 1452709 1632507 1632509 1632709 1634507 1634509 1634527 1634529 1634709 1634729 1652709 1654709 1654729 1832507 1832509 1832709 1834507 1834509 1834527 1834529 1834709 1834729 1836507 1836509 1836527 1836529 1836547 1836549 1836709 1836729 1836749 1852709 1854709 1854729 1856709 1856729 1856749 3452709 3652709 3654709 3654729 3852709 3854709 3854729 3856709 3856729 3856749 16345270 16345290 16347290 16547290 18345270 18345290 18347290 18365270 18365290 18365470 18365472 18365490 18365492 18367290 18367490 18367492 18547290 18567290 18567490 18567492 36547290 38547290 38567290 38567490 38567492 163452709 183452709 183652709 183654709 183654729
program is slow because I am still beginner in C# coding. Code of program is shown as solution number 4, even if the question was for C.

## Solution 3

C#
```#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e,f,g,h,i;float j,k=0;
for(i=1;i<32508;i++)
{  if(i<10)
{
printf("%d  ",i);
k++;
}
else if(i<100)
{
a=i/10;b=i%10;
if(a%2==0&&b%2!=0)
{
printf("%d  ",i);
k++;
}
if(b%2==0&&a%2!=0)
{
printf("%d  ",i);
k++;
}
}
else if(i<1000)
{ a=i%10;b=i/100;c=i%100;d=c/10;
if(d%2==0&&b%2!=0&&a%2!=0&&a>b)
{
printf("%d  ",i);
k++;
}
if(d%2!=0&&b%2==0&&a%2==0&&b>a)
{
printf("%d  ",i);
k++;
}
}
else if(i<10000)
{
a=i%10;b=i/1000;c=i%1000;d=c/100;e=c%100;f=e/10;
if(b%2!=0&&f%2!=0&&d%2==0&&a%2==0&&f>b&&d>a)
{
printf("%d  ",i);
k++;
}
if(b%2==0&&f%2==0&&d%2!=0&&a%2!=0&&b>f&&a>d)
{
printf("%d  ",i);
k++;
}
}
else
{
a=i%10;b=i/10000;c=i%10000;d=c/1000;e=c%1000;f=e/100;g=e%100;h=g/10;
if(b%2!=0&&f%2!=0&&a%2!=0&&d%2==0&&h%2==0&&a>f&&f>b&&d>h)
{
printf("%d  ",i);
k++;
}
if(b%2==0&&f%2==0&&a%2==0&&d%2!=0&&h%2!=0&&b>f&&f>a&&h>d)
{
printf("%d  ",i);
k++;
}
}
}
j=(k/32767)*100;
printf("\n\n\nPERCENTAGE IS= %f\%",j);
getch();

}```

CPallini 21-Oct-12 16:03pm
It doesn't look right.
Perić Željko 22-Oct-12 15:17pm
Program above works fine up to value 99999 as it is written to do. I have tested it as console app in C#, and last value printed is 87694 . Only if it is not important that first digit must be odd, in that case code is even simpler. My five to Rai.
CPallini 22-Oct-12 16:42pm
First digit must be odd, as per requirements.