QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
  << Previous Topic | Next Topic >>Return to Index  

7-segment symmetry

January 20 2012 at 1:43 PM
lawgin  (no login)

11 * 602 = 6622

If you do the above multiplication on a hand held calculator with a 7-segment display while holding the calculator upside down, it looks like this:

11 * 209 = 2299

which is also correct.

Can you find two 3 digit numbers with this property, that is, the multiplication will be correct even when the display is viewed upside down?

All numbers are base 10.
Leading zeros are not allowed.


 
 Respond to this message   
AuthorReply

(Login MCalkins)
Moderator

Unless something is wrong, I can find 19.

January 20 2012, 2:19 PM 

I'm not sure if I completely understand the rules, or that this code is bug free.
Even if there aren't any bugs, it probably isn't optimal.

Regards,
Michael

'public domain, jan 2012, michael calkins
DECLARE FUNCTION flip$ (a AS STRING)
DIM a AS LONG
DIM b AS LONG
DIM c AS LONG
DIM d AS STRING
DIM e AS STRING
DIM f AS LONG

CLS
FOR a = 100 TO 999
 IF a MOD 10 THEN
  FOR b = 100 TO 999
   IF b MOD 10 THEN
    c = a * b
    IF c MOD 10 THEN
     d = flip(LTRIM$(STR$(a)))
     IF LEN(d) THEN
      e = flip(LTRIM$(STR$(b)))
      IF LEN(e) THEN
       f = VAL(d) * VAL(e)
       IF f MOD 10 THEN
        IF flip(LTRIM$(STR$(c))) = LTRIM$(STR$(f)) THEN
         PRINT a; "*"; b; "="; c, d; "*"; e; "="; f
        END IF
       END IF
      END IF
     END IF
    END IF
   END IF
  NEXT
 END IF
NEXT
END

FUNCTION flip$ (a AS STRING)
 DIM t AS STRING
 DIM i AS INTEGER
 DIM c AS INTEGER
 t = SPACE$(LEN(a))
 FOR i = 1 TO LEN(a)
  c = ASC(MID$(a, i, 1))
  SELECT CASE c
  CASE &H36: c = &H39
  CASE &H39: c = &H36
  CASE &H33, &H34, &H37: flip = "": EXIT FUNCTION
  END SELECT
  MID$(t, LEN(t) + 1 - i) = CHR$(c)
 NEXT i
 flip = t
END FUNCTION

 
 Respond to this message   
lawgin
(no login)

Man, you are fast

January 20 2012, 3:58 PM 

It seems I just posted this about an hour ago. We both arrived at basically the same answers independently. The only difference is that I would consider there to be only 10 correct answers since the other 9 are formed simply by swapping the positions of the 3 digit numbers.


FOR a = 101 TO 999
a$ = LTRIM$(STR$(a))
IF INSTR(a$, "3") OR INSTR(a$, "4") OR INSTR(a$, "7") THEN GOTO skip1
FOR b = a TO 999
b$ = LTRIM$(STR$(b))
IF INSTR(b$, "3") OR INSTR(b$, "4") OR INSTR(b$, "7") THEN GOTO skip2
c = a * b
c$ = LTRIM$(STR$(c))
IF INSTR(c$, "3") OR INSTR(c$, "4") OR INSTR(c$, "7") THEN GOTO skip2

FOR n = LEN(c$) TO 1 STEP -1
n$ = MID$(c$, n, 1)
SELECT CASE n$
CASE "6"
cr$ = cr$ + "9"
CASE "9"
cr$ = cr$ + "6"
CASE ELSE
cr$ = cr$ + n$
END SELECT
NEXT n
cr = VAL(cr$)

FOR n = LEN(a$) TO 1 STEP -1
n$ = MID$(a$, n, 1)
SELECT CASE n$
CASE "6"
ar$ = ar$ + "9"
CASE "9"
ar$ = ar$ + "6"
CASE ELSE
ar$ = ar$ + n$
END SELECT
NEXT n
ar = VAL(ar$)

FOR n = LEN(b$) TO 1 STEP -1
n$ = MID$(b$, n, 1)
SELECT CASE n$
CASE "6"
br$ = br$ + "9"
CASE "9"
br$ = br$ + "6"
CASE ELSE
br$ = br$ + n$
END SELECT
NEXT n
br = VAL(br$)

IF (a MOD 10 > 0) AND (b MOD 10 > 0) AND (c MOD 10 > 0) THEN
IF ar * br = cr THEN PRINT a; "*"; b; "="; c
END IF
cr$ = "": ar$ = "": br$ = ""
skip2:
NEXT b
skip1:
NEXT a
END







 
 Respond to this message   

(Login MCalkins)
Moderator

* and I've a been a bit of a challenge hog... :-P

January 24 2012, 1:36 PM 



    
This message has been edited by MCalkins on Jan 24, 2012 1:36 PM


 
 Respond to this message   
Current Topic - 7-segment symmetry
  << Previous Topic | Next Topic >>Return to Index