How many -digit numbers are possible if the leftmost digit cannot be zero?

I’m trying to put together a clock multiplier, and it’s not going great. I’d ideally like to have a clock coming in on one script input, and output a multiple on a trigger out, and avoid manipulating metro, if that’s possible.

What I’ve come up so far sorta works but is not great:

1: # this just stores time between triggers, avg/smoothed
# basically per studies 4
X AVG T TIME
T TIME
TIME 0

2: # Fires the trigger, and calls itself again after a delay
TR.P 4
PARAM.SCALE 1 8 # For 1x - 8x multiplier
DEL / X PARAM: $ 2

Things I don’t love about this:

  • it’s not synced with the “clock” coming in. It pulses at a rough multiple of the incoming clock, but not necessarily ‘on the beat’.
  • because we’re using integer math here, it doesn’t actually always line up correctly. The multiples tend to drift a bit, usually a bit faster than the incoming clock.
  • it takes up 2 scripts (ideally it would squeeze into one)

Are there better solutions for this? Apart from TELEXo, which I see has M per-trigger out and also multipliers for that metro, which I assume would line up better. But, I’m curious how to do this in ‘vanilla’ Teletype.

Given a grid and an in-bounds y value. Every square in the grid is either sand 's', rock 'r', or

  def sand_worm(grid, y):
    x = 0
    while x < grid.width and grid.get(x, y) != 's':
      x += 1
    
    if x == grid.width:
      return grid

    # In all cases, set the found square to be None
    grid.set(x, y, None)
    
    if grid.in_bounds(x, y + 1) and grid.(x, y + 1) == None:
      grid.set(x, y + 1, 's')
0.

a. Write a while loop to search row y left-to-right to find the leftmost sand in it. The leftmost sand in a row is the one with the smallest x value.

If there is no sand in the row, return the grid unchanged, otherwise do step b.

b. We'll call the square where the leftmost sand is found the "found" square. In all cases, set the found square to be empty (

  def sand_worm(grid, y):
    x = 0
    while x < grid.width and grid.get(x, y) != 's':
      x += 1
    
    if x == grid.width:
      return grid

    # In all cases, set the found square to be None
    grid.set(x, y, None)
    
    if grid.in_bounds(x, y + 1) and grid.(x, y + 1) == None:
      grid.set(x, y + 1, 's')
0), so the sand disappears. If the square below the found square is empty, set it to contain sand ('s'), in effect moving the sand down.

In the example grid below, at row y=0, the leftmost sand is at 2. It cannot move down because a rock is in the way. At row y=1, the leftmost sand is at 3, and it can move down.

  def sand_worm(grid, y):
    x = 0
    while x < grid.width and grid.get(x, y) != 's':
      x += 1
    
    if x == grid.width:
      return grid

    # In all cases, set the found square to be None
    grid.set(x, y, None)
    
    if grid.in_bounds(x, y + 1) and grid.(x, y + 1) == None:
      grid.set(x, y + 1, 's')

2. Crypto (15 points)

This problem is similar to the Crypto homework. As a simplification, there will be no uppercase chars in this problem - the source, slug, and char will all contain lowercase chars, or chars like '$' which do not have an upper/lower case.

For this problem, there are two slug lists of the same length, and the source list is twice as long as each slug. Compute and return the encrypted form of a char as follows: if the char does not appear in the source list, return the char unchanged. If the char appears in the source list, consider the index where it appears. (a) If that index is a valid index into slug1, return the char at that index in slug1. (b) If the index is invalid (too large) for slug1, reduce the index by the slug1 length, yielding a smaller number. Return the char at that smaller index in slug2. In effect, depending on the index where the char is found in source, either slug1 or slug2 is used.

Say we have this len-4 source and 2 len-2 slugs:
source = ['a', 'b', 'c', 'd']

slug1 = ['q', 'r']
slug2 = ['x', 'y']

encryption:
'a' -> 'q'
'b' -> 'r'
'c' -> 'x'
'd' -> 'y'
  def encryption(source, slug1, slug2, char):
    if char in source:
        idx = source.index(char)
        if idx < len(slug1):
            return slug1[idx]
        else:
          new_idx = idx - len(slug1)
          return slug2[new_idx]
    return char

3. String (25 points)

The hottest new cryptocurrency is Yottercoin. A Yottercoin address is marked with a

  def sand_worm(grid, y):
    x = 0
    while x < grid.width and grid.get(x, y) != 's':
      x += 1
    
    if x == grid.width:
      return grid

    # In all cases, set the found square to be None
    grid.set(x, y, None)
    
    if grid.in_bounds(x, y + 1) and grid.(x, y + 1) == None:
      grid.set(x, y + 1, 's')
3 at its end. Before that there are always two digits. And before that is a series of zero or more of the three chars,
  def sand_worm(grid, y):
    x = 0
    while x < grid.width and grid.get(x, y) != 's':
      x += 1
    
    if x == grid.width:
      return grid

    # In all cases, set the found square to be None
    grid.set(x, y, None)
    
    if grid.in_bounds(x, y + 1) and grid.(x, y + 1) == None:
      grid.set(x, y + 1, 's')
4, which make up the address to be returned. Find and return the first Yottercoin address in s, or None if there is none. If there is a '.yot' in the string, you can assume there is a valid Yottercoin address in the string.

'xx oyot97.yot xx' -> 'oyot'
'.itoytoy22.yot33' -> 'toytoy'
'toytoy' -> None
  def yottercoin(s):
    yot_loc = s.find('.yot')
    if yot_loc == -1:
      return None
    
    # skip over the digits 
    start = yot_loc - 3
    while start >= 0 and (s[start] == 'y' or s[start] == 'o' or s[start] == 't'):
      start -= 1

    return [start+1:yot_loc-2]

4. Drawing (15 points)

Reminder: the canvas draw_line function:

canvas.draw_line(x1, y1, x2, y2) - draws a line from x1,y1 to x2,y2

This function takes in parameters

  def sand_worm(grid, y):
    x = 0
    while x < grid.width and grid.get(x, y) != 's':
      x += 1
    
    if x == grid.width:
      return grid

    # In all cases, set the found square to be None
    grid.set(x, y, None)
    
    if grid.in_bounds(x, y + 1) and grid.(x, y + 1) == None:
      grid.set(x, y + 1, 's')
5 like the Quilt homework, with an additional int parameter a.

Like the Quilt homework, the drawing should have its upper left pixel at left,top, and extending to cover width,height pixels. Draw a blue rectangle at the outer edge (the draw-rect line of code is provided below).

Leave a "margin" area of width a at the left and right sides of the drawing with no lines drawn in it. The parameter n will be an int, 2 or more. Draw a series of n lines from the top edge to the bottom edge. The first line should start at the top edge, next to the left margin area, and end at the bottom edge next to the right margin area. The last line should start at the top next to the right margin, ending at the bottom next to the left margin, with the other lines distributed evenly in between.

How computer represent real number in memory?

Computers use binary (base 2) number system, as they are made from binary digital components (known as transistors) operating in two states - on and off. In computing, we also use hexadecimal (base 16) or octal (base 8) number systems, as a compact form for representing binary numbers.

How many ways we represent number in computer?

There are two main ways to represent numbers: integer and floating point.