Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Golf a FRACTRAN interpreter

Parent

Golf a FRACTRAN interpreter

+8
−0

Description

From the Esolangs wiki,

In Fractran,

  • a program consists of a finite list of positive, rational numbers.
  • The input to a program is a positive integer n.
  • The list is then searched in order, for a rational number $p/q$ such that $n×p/q$ is an integer.
  • Then n is replaced by $n×p/q$ and the search is restarted from the beginning of the list.
  • The program halts when no such number $p/q$ can be found, and the final n becomes the output from the program.
  • Output the final value of $n$.

Your task is to implement an interpreter for this language.

Input

You are to take two inputs:

  • $n$, an integer
  • $A$, an array of fractions, which may be taken as a list of pairs, or in the rational datatype of your language.

Output

A single integer, the final value of $n$.

Test Cases

Formatted as

program
input
output
78/55, 5/3, 1/5, 11/2, 5/7
1096135733
328842888196762472689573703

3/2
1296
6561

455/33, 11/13, 1/11, 3/7, 11/2, 1/3
72
15625
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (4 comments)
Post
+1
−0

Ruby, 51 50 bytes

-1 from Razetime

->p,n{while i=p.find{(_1*n).to_f%1==0}
n*=i
end
n}

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

-1 changing to `n*=i` (1 comment)
-1 changing to `n*=i`
Razetime‭ wrote over 3 years ago

-1 changing to n*=i