Talk:Factor
Polyglot Truth-machine in Factor and Brainfoctal
Nice zero-dimensional language; I like this!
Here is a zero-dimensional polyglot Truth-machine, since there aren't many 0d languages to combine:
1980162504590663524427895128832287108919003518751113534748489908152745653289288576638392714501426799307977736019325527189300780074184832951279861236626358272
It works in Brainfoctal. It should work in Factor providing 32292485201835924806750672382452954522291
is really prime. Sympy tells me it is, and it factorises the number pretty quickly. I have not yet made a Python interpreter to run it, but the conversion to bf works.
The Factor Java interpreter appears to not provide output within infinite loops, and it seems to hang indefinitely trying to factorise this number.
1980162504590663524427895128832287108919003518751113534748489908152745653289288576638392714501426799307977736019325527189300780074184832951279861236626358272 // 2**18 // 32292485201835924806750672382452954522291 = 233915737501853959241591127266540514014498928384925170744745371936977107366667491950094954248611898080571424768
Is a Factor truth-machine, which does work in the Java interpreter, for at least a 0 input. 32292485201835924806750672382452954522291 % 11 = 1
is a right shift which should be the extra command missing from the smaller version above (does not affect output). I think that goes some way to illustrate the program will work as intended when the factorisation completes.
A very basic polyglot which is easy to verify (created to test the polyglotting process for these two languages):
3924032640
This outputs character \x01
in either language.
Salpynx (talk) 04:52, 8 July 2020 (UTC)
Response
Thank you for your contributions! Unfortunately, it seems as though you tested my interpreter while I was still working out some bugs. My interpreter now outputs in infinite loops, and the last two programs you provided now work. Also, it seems as though everything hangs while trying to factor the first number, which is weird because my interpreter easily factors the brainfuck interpreter seen on the Github page.
Bangyen (talk) 05:35, 9 July 2020 (UTC)
Ignored Characters
When I stated that characters other than 0123456789
should be ignored, I meant that programs such as 3924comment032640
should still run; however, I appreciate the clarification that residue values other than 12345678
are ignored too.
Bangyen (talk) 06:23, 9 July 2020 (UTC)
Python Interpreter
Due to the fact that I don't know Ruby, I developed my own Factor interpreter and conversion between Factor to brainfuck in Python.
Well, who needs Java or Ruby when you have Python?
import sys def bf2factor(brainfuck): '''Conversion from brainfuck to factor''' f='0><+-.,[]' c=2 n=1 def composite(x): i=2 while i*i<=x: if x%i==0: return True i+=1 return False for i in brainfuck: if i not in f: continue num=f.index(i) while composite(c) or c%11!=num: c+=1 n*=c return n def factor2bf(factor): '''Conversion from factor to brainfuck''' f='0><+-.,[]' fac=2 brainfuck='' while factor!=1: while factor%fac!=0: fac+=1 factor//=fac if fac%11<9: brainfuck+=f[fac%11] return brainfuck def bf(code): '''Brainfuck''' s1=[] s2=[] matches={} tape=[0]*1000100 for i,j in enumerate(code): if j=='[': s1.append(i) if j==']': m=s1.pop() matches[m]=i matches[i]=m cp=0 p=100 # I added cells that are on the left of origin so that it runs the polyglot truth machine correctly while cp<len(code): if code[cp]=='+': tape[p]=(tape[p]+1)%256 if code[cp]=='-': tape[p]=(tape[p]-1)%256 if code[cp]==',': tape[p]=ord(sys.stdin.read(1))%256 if code[cp]=='.': print(chr(tape[p]),end='') if code[cp]=='<': p-=1 if code[cp]=='>': p+=1 if code[cp]=='[': if not tape[p]: cp=matches[cp] if code[cp]==']': if tape[p]: cp=matches[cp] cp+=1 def interpret(factor): bf(factor2bf(factor)) program=int(input()) interpret(program)