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

Post History

75%
+4 −0
Challenges Golf a FRACTRAN interpreter

Brachylog, 16 bytes g₂;.z∋zbᵗ×ᵐ/ℤ↰|w Try it online! This is a function submission, which inputs n from the left and A from the right (as a list of two-element lists). Output is to standard out...

posted 3y ago by ais523‭

Answer
#1: Initial revision by user avatar ais523‭ · 2021-08-11T20:18:01Z (about 3 years ago)
# [Brachylog], 16 bytes

    g₂;.z∋zbᵗ×ᵐ/ℤ↰|w

[Try it online!][TIO-ks7xdgx9]

This is a function submission, which inputs *n* from the left and *A* from the right (as a list of two-element lists). Output is to standard output.

## Explanation

    g₂;.z∋zbᵗ×ᵐ/ℤ↰|w
    g₂                  place two list wrappers around the left input
      ;.                append the right input
        z               cycling zip; because the left input is length 1,
                          this pairs it with each element of the right input
         ∋              find {the first} element for which no assertions fail
    [at this point, the element looks like [[n], [num, denom]]
     for some pair [num, denom] in A]
          z             rearrange to [[n, num], [n, denom]]
           bᵗ           remove first of last pair ([[n, num], [denom]])
             ×ᵐ         take product of each inner list ([n×num, denom])
               /ℤ       divide; assert result (n×num÷denom) is an integer
                 ↰      recurse (loop back to start of program)
                  |     if all else fails (i.e. ∋ found no elements)
                   w    output the current value to standard output

[Brachylog]: https://github.com/JCumin/Brachylog
[TIO-ks7xdgx9]: https://tio.run/##SypKTM6ozMlPN/r/P/1RU5O1XtWjju6qpIdbpx@e/nDrBP1HLUsetW2oKf//39DA0szQ2NTc2Ph/dLS5hY6paaxOtKmOMZA01AGxDQ11jMBC5rGxAA "Brachylog – Try It Online"