aboutsummaryrefslogtreecommitdiff
path: root/challenge-077/andinus/README
blob: 9437e98f289d8242c393e40222174158315496e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
                            ━━━━━━━━━━━━━━━
                             CHALLENGE 077
                            ━━━━━━━━━━━━━━━


Table of Contents
─────────────────

1 Task 1 - Fibonacci Sum
.. 1.1 Perl





1 Task 1 - Fibonacci Sum
════════════════════════

  You are given a positive integer `$N'.

  Write a script to find the total number of Fibonacci Numbers required
  to get `$N' on addition. You are NOT allowed to repeat a number. Print
  0 if none found.

  *Note*: This solution is incomplete. Others have pushed complete
   solutions, look at those.


1.1 Perl
────────

  • Program: [file:perl/ch-1.pl]

  Make a list of all possible sums of `$input'.
  ┌────
  │ my @sums;
  │ foreach my $num (0 ... $input / 2) {
  │     my $diff = $input - $num;
  │     push @sums, [$diff, $num];
  │ }
  └────

  Loop over `@sums' & then print those sets which have both `$sums->[0]'
  & `$sums->[1]' in fibonacci series.
  ┌────
  │ sub is_fib { return Math::Fibonacci::isfibonacci(@_) }
  │
  │ foreach (@sums) {
  │     next unless is_fib($_->[0]) and is_fib($_->[1]);
  │     say "$_->[0] + $_->[1]";
  │ }
  └────