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

60%
+1 −0
Challenges Fibonacci without consecutive digits

Pyth, 25 23 bytes @f-1aM.:jT;2u+Gs>2GyQU2 Try it online! First, we generate the Fibonacci numbers: u+Gs>2GyQU2 U2 range(2), the list [0, 1] u Apply the follow...

posted 9mo ago by isaacg‭  ·  edited 9mo ago by isaacg‭

Answer
#2: Post edited by user avatar isaacg‭ · 2024-03-01T17:12:57Z (9 months ago)
Found a shorter way to generate fibonacci numbers.
  • # [Pyth], 25 bytes
  • @f-1aM.:jT;2hM.u,eNsNyQU2
  • [Try it online!][TIO-lt8wf7zj]
  • First, we generate the Fibonacci numbers:
  • hM.u,eNsNyQU2
  • U2 range(2), the list [0, 1]
  • .u Apply the following function iteratively,
  • saving all results.
  • ,eNsN [end(N), sum(N)], where N is the previous list
  • yQ Twice the input number of repetitions
  • hM Take the first entry of each pair.
  • I think there might be a shorter way to do this part, perhaps by using `u` rather than `.u`?
  • Next, we check for consecutive digits.
  • @f-1aM.:jT;2
  • f Filter on the following function
  • jT; Take the base ten representation of the number.
  • ; accesses T's value in the external scope.
  • .: 2 Take all pairs of digits.
  • aM Map pairs to their absolute difference.
  • -1 Check if 1 is not among the differences.
  • @ Index the filter result at the input position.
  • [Pyth]: https://github.com/isaacg1/pyth
  • [TIO-lt8wf7zj]: https://tio.run/##K6gsyfj/3yFN1zDRV88qK8TaKMNXr1Qn1a/YrzIw1Oj/fyMDAA "Pyth – Try It Online"
  • # [Pyth], <s>25</s> 23 bytes
  • @f-1aM.:jT;2u+Gs>2GyQU2
  • [Try it online!][TIO-lt8wtkyl]
  • First, we generate the Fibonacci numbers:
  • u+Gs>2GyQU2
  • U2 range(2), the list [0, 1]
  • u Apply the following function iteratively,
  • returning the final result.
  • +G Add to the end of the current list
  • s>2G The sum of the last two elements of the current list
  • yQ Repeat for twice the input number of repetitions
  • Next, we check for consecutive digits.
  • @f-1aM.:jT;2
  • f Filter on the following function
  • jT; Take the base ten representation of the number.
  • ; accesses T's value in the external scope.
  • .: 2 Take all pairs of digits.
  • aM Map pairs to their absolute difference.
  • -1 Check if 1 is not among the differences.
  • @ Index the filter result at the input position.
  • [Pyth]: https://github.com/isaacg1/pyth
  • [TIO-lt8wtkyl]: https://tio.run/##K6gsyfj/3yFN1zDRV88qK8TaqFTbvdjOyL0yMNTo/38jAwA "Pyth – Try It Online"
#1: Initial revision by user avatar isaacg‭ · 2024-03-01T17:05:46Z (9 months ago)
# [Pyth], 25 bytes

    @f-1aM.:jT;2hM.u,eNsNyQU2

[Try it online!][TIO-lt8wf7zj]

First, we generate the Fibonacci numbers:

    hM.u,eNsNyQU2
               U2    range(2), the list [0, 1]
      .u             Apply the following function iteratively,
                     saving all results.
        ,eNsN        [end(N), sum(N)], where N is the previous list
             yQ      Twice the input number of repetitions
    hM               Take the first entry of each pair.

I think there might be a shorter way to do this part, perhaps by using `u` rather than `.u`?

Next, we check for consecutive digits.

    @f-1aM.:jT;2
     f              Filter on the following function
            jT;     Take the base ten representation of the number.
                    ; accesses T's value in the external scope.
          .:   2    Take all pairs of digits.
        aM          Map pairs to their absolute difference.
      -1            Check if 1 is not among the differences.
    @               Index the filter result at the input position.

[Pyth]: https://github.com/isaacg1/pyth
[TIO-lt8wf7zj]: https://tio.run/##K6gsyfj/3yFN1zDRV88qK8TaKMNXr1Qn1a/YrzIw1Oj/fyMDAA "Pyth – Try It Online"