MasonDSU

ActualMult

Feb 23rd, 2021
759
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. input: '1011*0011'
  2. blank: ' '
  3. start state: start
  4. table:
  5. #This copys the first factor before the equation
  6. #This lets us remember what it is
  7.   start:
  8.     0: {write: X, R: findAnswer}
  9.     1: {write: Y, R: findAnswer}
  10.  
  11.   padAnswer:
  12.     0: {write: X, R: findAnswer}
  13.     1: {write: Y, R: findAnswer}
  14.     '*': {L: to2ndFactor}
  15.   findAnswer:
  16.     [0,1,'*']: R
  17.     ' ': {write: '=', R: doPad}
  18.     '=': {R: doPad}
  19.   doPad:
  20.     [0,1]: R
  21.     ' ': {write: 0, R: padAgain}
  22.   padAgain:
  23.     ' ': {write: 0, L: backPad}
  24.   backPad:
  25.     [0,1,'*','=']: L
  26.     X: {write: 0, R: padAnswer}
  27.     Y: {write: 1, R: padAnswer}
  28.  
  29.  #do Subtraction
  30.   to2ndFactor:
  31.     [0,1,'*']: R
  32.     '=': {L: sub2ndFactor}
  33.   sub2ndFactor:
  34.     0: {write: 1, L}
  35.     1: {write: 0, L: toBeginning}
  36.     '*': {L: cleanL}
  37.    
  38.   #Copy 1st factor to End
  39.   toBeginning:
  40.     [0,1,'*']: L
  41.     ' ': {R: copyMult}
  42.   copyMult:
  43.     0: {write: X, R: copyMult0}
  44.     1: {write: Y, R: copyMult1}
  45.     '*': {R: toMult}
  46.  
  47.   copyMult0:
  48.     [0,1,'*','=']: R
  49.     ' ': {write: 'M', R: pasteMult0}
  50.     'M': {R: pasteMult0}
  51.   pasteMult0:
  52.     [0,1]: R
  53.     ' ': {write: 0, L: backMultCopy}
  54.   copyMult1:
  55.     [0,1,'*','=']: R
  56.     ' ': {write: 'M', R: pasteMult1}
  57.     'M': {R: pasteMult1}
  58.   pasteMult1:
  59.     [0,1]: R
  60.     ' ': {write: 1, L: backMultCopy}
  61.   backMultCopy:
  62.     [0,1,'*','=','M']: L
  63.     X: {write: 0, R: copyMult}
  64.     Y: {write: 1, R: copyMult}
  65.    
  66.   # Do an Addition (dec then inc)
  67.   toMult:
  68.     [0,1,'=',M]: R
  69.     ' ': {L: subMult}
  70.   subMult:
  71.     0: {write: 1, L}
  72.     1: {write: 0, L: toAnswer}
  73.     M: {R: cleanMult}
  74.   toAnswer:
  75.     [0,1]: L
  76.     'M': {L: addAnswer}
  77.   addAnswer:
  78.     0: {write: 1, R: toMult}
  79.     1: {write: 0, L}
  80.   cleanMult:
  81.     [0, 1]: {write: ' ', R}
  82.     ' ': {L: to2ndFactorL}
  83.   to2ndFactorL:
  84.     [0,1,' ',M]: L
  85.     '=': {L: sub2ndFactor}
  86.  
  87.   cleanL:
  88.     [0,1]: {write: ' ', L}
  89.     ' ': {R: cleanR}
  90.   cleanR:
  91.     [' ',0,1,'*']: {write: ' ', R}
  92.     '=': {write: ' ', R: cleanAnswer}
  93.   cleanAnswer:
  94.     0: {write: ' ', R}
  95.     1: {R: skipAnswer}
  96.     M: {write: 0, L: done}
  97.   skipAnswer:
  98.     [0,1]: R
  99.     M: {write: ' ', L: done}
  100.   done:
  101.    
  102.    
  103.    
RAW Paste Data