Post Reply 
Weekend Challenge Sharpened: Missing Positions in Champernowne's Constant
08-04-2015, 05:04 AM
Post: #5
RE: Weekend Challenge: Missing Positions in Gods' Triangle
(07-30-2015 04:53 PM)Gerald H Wrote:  Write a programme that on input of the index of a number, say C, that cannot appear as position of any integer returns C, eg

for index

1

the programme returns

11

as 11 is the lowest number not representing the start position of an integer.

The following does the trick:

Code:
«
  0 9 NDUPN DROP
  → c 
    Σi Σc ch
    num.ints.at.ch int.width.at.ch
    c.width.at.ch tot.c.width.at.ch 
    c.to.go ints.to.go
  «
    1 CF
    WHILE 1 FC? REPEAT
      ch ALOG 9 * 'num.ints.at.ch' STO
      ch 1 + 'int.width.at.ch' STO
      ch 'c.width.at.ch' STO
      num.ints.at.ch c.width.at.ch * 'tot.c.width.at.ch' STO
      IF Σc tot.c.width.at.ch + c ≥ THEN
        1 SF
      ELSE
        tot.c.width.at.ch 'Σc' STO+
        num.ints.at.ch int.width.at.ch * 'Σi' STO+
      END
      1 'ch' STO+   
    END
    c Σc - 'c.to.go' STO
    c.to.go c.width.at.ch / FLOOR 'ints.to.go' STO
    Σi
    ints.to.go int.width.at.ch *
    c.to.go c.width.at.ch MOD
    + +
  »
»

As requested, it returns 11 for an input of 1, 1089 for an input of 690, and, for example, 1124999998 for an input of 987654321.

[Here i refers to an index into God's Number, c refers to the "dead" digits of God's Number where no integer starts, and ch (characteristic) is the power of ten currently being addressed as we iterate from the "units" to the "tens" to the "hundreds" etc.. All local variables are initialised to zero except for the input value, c.]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Weekend Challenge: Missing Positions in Gods' Triangle - nlj - 08-04-2015 05:04 AM



User(s) browsing this thread: