473,625 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rotated Number

24 New Member
I need help on a project i was assigned.

The digits 0, 1, and 8 look much the same if rotated 180 degrees on the page (turned upside down). Also, the digit 6 looks much like a 9, and vice versa, when rotated 180 degrees on the page. A multi-digit number may also look like itself when rotated on the page; for example 9966 and 10801 do, but 999 and 1234 do not.
You are to write a program to count how many numbers from a given interval look like themselves when rotated 180 degrees on the page. For example, in the interval [1..100] there are six : 1, 8, 11, 69, 88, and 96.

Your program should take as input two integers, m and n, which define the interval to be checked, 1 <= m <= n <= 32000. The output from your program is the number of rotatable numbers in the interval.

You may assume that all input is valid.
Sample Session User input is in italics.

Enter the lower bound of the interval:

1



Enter the upper bound of the interval:

100



The number of rotatable numbers is:

6
I need a way to recognize these numbers.

Any help is appreciated.
Nov 7 '07 #1
7 2175
YarrOfDoom
1,247 Recognized Expert Top Contributor
Use a for-loop to loop trough the numbers n to m.
For checking a number, convert it to a string using CString(number), then use another for-loop to loop trough every character of your number.
Say we call the position in the string of the current character a. Then first check if your character is one of the special cases (if not, you can abort the whole loop and check the next number). Second, check if the character at position StringMadeOutOf Number.length-(a-1) is the character you need (eg: 1 for 1, 6 for 9, 8 for 8, 9 for 6,...), if not, abort loop and you can check the next number. If the number gets trough the whole loop then it's one of the cases where it is the same if you turn it 180°.

Yarr
Nov 7 '07 #2
halo combat22
24 New Member
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     Dim n, m, i As Integer
  3.     Dim s As String
  4.     m = txtm.Text
  5.     n = txtn.Text
  6.     For i = m To n
  7.         For s = 1 To i - 1
  8.    'where does cString go?
  9. End Sub
  10.  
Where does cString go?
If it is a vb 2005 express thing i can't use it since i use vb6.
Nov 7 '07 #3
Killer42
8,435 Recognized Expert Expert
... Where does cString go?
If it is a vb 2005 express thing i can't use it since i use vb6.
I believe that is VB.Net code (something later than VB6, anyway). However, I don't think we can go into too much detail, as we have a definite policy of not answering homework/classwork assignments for you.

Suffice it to say that Cstring would (presumably) be converting a number into a string. You will need to make a real effort to solve the problem yourself. Show us what you write, and we'll see if we can help nudge you in the right direction.

See the posting guidelines.
Nov 8 '07 #4
YarrOfDoom
1,247 Recognized Expert Top Contributor
Oww wait, it's not CString(), but just Str(), I mixed up a little with CInt()...
Nov 8 '07 #5
halo combat22
24 New Member
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim s, sI, One, Two, Three, nCount As String
  3. Dim m, n, nLen As Integer
  4. Dim b As Boolean
  5. m = Text1.Text
  6. n = Text2.Text
  7. For i = m To n
  8.     sI = Str(i)
  9.     nLen = Len(sI)
  10.     For j = 1 To nLen
  11.         Three = Mid(sI, nLen, 1)
  12.         If Three = 2 Or Three = 3 Or Three = 4 Or Three = 5 Or Three = 7 Then
  13.         b = False
  14.         Else
  15.         b = True
  16.         End If
  17.         One = Mid(sI, 1, 1)
  18.         Two = Mid(sI, nLen, 1)
  19.         If (b = True And One = Two) Then
  20.             nCount = nCount + 1
  21.         End If
  22.  
  23.  
  24.  
  25.         MsgBox (nCount)
  26.  
  27.     Next
  28. Next
  29.  
  30. End Sub
  31.  
Well i got this far but it still hasn't worked? What is the problem?
Nov 9 '07 #6
YarrOfDoom
1,247 Recognized Expert Top Contributor
I should use "select case" instead of "if", and you shouldn't place the msgbox inside a loop.
Nov 10 '07 #7
Killer42
8,435 Recognized Expert Expert
...Well i got this far but it still hasn't worked? What is the problem?
Can you be more specific than "hasn't worked"?

Also, I think you will find it much easier if you first work out in detail the exact process you are going to use, before you try to write the code. That's where "pseudo-code" comes in very handy. For example...

Expand|Select|Wrap|Line Numbers
  1. For each number N in the range 1 to 100
  2.   For Each digit of N
  3.     If digit is 1 or 8 or 0 Then
  4.       Blah...
  5.     Else If digit is 6 or 9 Then
  6.       Blah...
  7.     Else
  8.       Blah...
  9.     End If
  10.   Loop
  11. Loop
Nov 12 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
8501
by: rzed | last post by:
I'm using PIL to generate some images which may be rotated at the user's option. When they are rotated, the original image is cropped in the new image (which is fine), and the corners are black (which is not, in this case). I can't find any documented way to change the default fill color (if that's what it is) for the corners, and PIL also doesn't seem to support a flood fill. I have created a flood fill in Python, which works but which...
2
9905
by: Gnurp Gnarp | last post by:
When the number of columns get large, it becomes increasingly difficult to view the results of a select in a small window (e.g. 80 line xterm) because of line wrapping. Can I have the results of the select query displayed rotated, e.g. like this: +------+------+------+------+ | | row0 | row1 | row2 | +------+------+------+------+ | col0 | 0 | 3 | 6 | | col1 | 1 | 4 | 7 |
6
61730
by: charsh | last post by:
Hi, I using the code below to draw a text in a pictureBox1. //Start--------------------------------------------------------------- private void button1_Click(object sender, System.EventArgs e) { Graphics g; g = pictureBox1.CreateGraphics(); g.FillRectangle(Brushes.White,0,0,160,160);
4
1937
by: Jamie Border | last post by:
Odd question: I have some Forms that I have to display rotated 90 degrees clockwise (don't ask! :-) Right now I'm doing it by hiding the Form offscreen, grabbing the DC, rotating it and blitting it onto another Form's DC (well actually a PictureBox). Currently I have to handle all event forwarding myself.
1
2169
by: kurt sune | last post by:
I am trying to do a rotated font. I get a handle alright which I convert to a font-object by Font2 = Font.FromHfont(handleFont) g.DrawString(Text-to draw, Font2, Brush, CurrentX, CurrentY) However the font doesnt get rotated. Anybody any tips? /k
2
5781
by: Tilo Pätzold | last post by:
Hi Everybody (especially Microsoft), we build EMF files with rotated text for export to office (powerpoint, word). It is planned that the text can be edited in the office document. Without the rotate transformation the text stays as a block and can be edited in the office document after ungrouping. But a rotated text leads to single charackters when ungrouping. The following sample code creates an emf file. The file can be dragged to...
0
1734
by: Khadim | last post by:
Hi, I am facing a problem in my application. I have an image on which there are many numbers present. I can find the pixel position of the center of those numbers. Now I have the names of those numbers in seperate file which I have to write to corresponding numbers. I rotate my image on 45 degrees with point to rotate 30 pixels on top left which shows my text on 45 degrees on top left. Writing this doesn't gives my much trouble.
5
64214
by: austincollins | last post by:
I have been searching for hours to find a solution to display text rotated at 90 degrees in firefox, and could not find one. css3 and IE has the css command "writing-mode: tb-rl;" but this does not work in firefox. i came to conclusion that SVG is the solution. I have been playing with SVG for few hours now and it is brilliant, you can do graphics and animation like flash but text and javascript based!. anyway check this out, this is one...
0
8259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8192
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8358
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7188
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.