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

80%
+6 −0
Challenges Golf a FRACTRAN interpreter

APL (Dyalog Unicode), 33 bytes {×x←⊃(2⌷⍵)(÷⍨(/⍨)0=|)⍺×1⌷⍵:x∇⍵⋄⍺} Try it online! The first case doesn't work because it gets really big, but the other two do. The input is taken on the left a...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#2: Post edited by user avatar user‭ · 2021-05-05T16:10:53Z (over 3 years ago)
  • # [APL (Dyalog Unicode)], 33 bytes
  • <!-- language-all: lang-apl -->
  • {×x←⊃(2⌷⍵)(÷⍨(/⍨)0=|)⍺×1⌷⍵:x∇⍵⋄⍺}
  • [Try it online!][TIO-ko9a95i1]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-ko9a95i1]: https://tio.run/##JYwxbsJAEEV7n@KXtkQUdjfLYiRuwQVAxGsnSEayEVjgCgQhyUp0rmhS5QCJIqX1TeYiZmyaeaM/8/50uXiYF9NFapsmouNlW1cbBr3vfUmff@R@A79mfPuPPIL@eBeQ@68rcT@ONvR2YtLHgeOyaWzbwWtE7uzLzqTzV1sjyf0wS88TMhwggoTgSEF6npGweNIaSvUgBEQLXnpQMF0i20Cx2w8HQmmjFBtmCHbY4pvuvhgG5K6YxEmGl1WWwz7nGfI0xSyxSOavWMfFDQ "APL (Dyalog Unicode) – Try It Online"
  • The first case doesn't work because it gets really big, but the other two do. The input is taken on the left and the fractions are taken as a table on the right.
  • # [APL (Dyalog Unicode)], 33 bytes
  • <!-- language-all: lang-apl -->
  • {×x←⊃(2⌷⍵)(÷⍨(/⍨)0=|)⍺×1⌷⍵:x∇⍵⋄⍺}
  • [Try it online!][TIO-ko9a95i1]
  • [APL (Dyalog Unicode)]: https://www.dyalog.com/
  • [TIO-ko9a95i1]: https://tio.run/##JYwxbsJAEEV7n@KXtkQUdjfLYiRuwQVAxGsnSEayEVjgCgQhyUp0rmhS5QCJIqX1TeYiZmyaeaM/8/50uXiYF9NFapsmouNlW1cbBr3vfUmff@R@A79mfPuPPIL@eBeQ@68rcT@ONvR2YtLHgeOyaWzbwWtE7uzLzqTzV1sjyf0wS88TMhwggoTgSEF6npGweNIaSvUgBEQLXnpQMF0i20Cx2w8HQmmjFBtmCHbY4pvuvhgG5K6YxEmGl1WWwz7nGfI0xSyxSOavWMfFDQ "APL (Dyalog Unicode) – Try It Online"
  • The first case doesn't work because it gets really big, but the other two do. The input is taken on the left and the fractions are taken as a table on the right.
  • ```
  • {×x←⊃(2⌷⍵)(÷⍨(/⍨)0=|)⍺×1⌷⍵:x∇⍵⋄⍺}
  • ⍺× ⍝ n multiplied by
  • 1⌷⍵ ⍝ The first row of the right argument (every p)
  • (2⌷⍵) ⍝ Second row of right arg (all q's)
  • | ⍝ All n×p modulo q
  • 0= ⍝ Check which ones are 0 (rational)
  • ÷⍨ ⍝ Make another vector of 'n×p÷q's
  • /⍨ ⍝ And keep the ones that were rational
  • ⊃ ⍝ Pick the first (0 if empty)
  • x← ⍝ Assign to x
  • × ⍝ Sign of x
  • ⍺ ⍝ If sign is 0, return n
  • x∇⍵ ⍝ Otherwise, call again with x as new n
  • ```
#1: Initial revision by user avatar user‭ · 2021-05-04T00:18:38Z (over 3 years ago)
# [APL (Dyalog Unicode)], 33 bytes

<!-- language-all: lang-apl -->

    {×x←⊃(2⌷⍵)(÷⍨(/⍨)0=|)⍺×1⌷⍵:x∇⍵⋄⍺}

[Try it online!][TIO-ko9a95i1]

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-ko9a95i1]: https://tio.run/##JYwxbsJAEEV7n@KXtkQUdjfLYiRuwQVAxGsnSEayEVjgCgQhyUp0rmhS5QCJIqX1TeYiZmyaeaM/8/50uXiYF9NFapsmouNlW1cbBr3vfUmff@R@A79mfPuPPIL@eBeQ@68rcT@ONvR2YtLHgeOyaWzbwWtE7uzLzqTzV1sjyf0wS88TMhwggoTgSEF6npGweNIaSvUgBEQLXnpQMF0i20Cx2w8HQmmjFBtmCHbY4pvuvhgG5K6YxEmGl1WWwz7nGfI0xSyxSOavWMfFDQ "APL (Dyalog Unicode) – Try It Online"

The first case doesn't work because it gets really big, but the other two do. The input is taken on the left and the fractions are taken as a table on the right.