Skip to main content
added 422 characters in body
Source Link
Doorknob
  • 72.1k
  • 20
  • 146
  • 393

Ruby, 118 114 (array output) or 138 134 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|a.combination(n).select{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

Change gets to $*[0] if you want command line arguments (>fibadd 100), +1 character though.

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|a.combination(n).select{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample runruns:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 c:\a\ruby>fibadd 1000 13+987 5+8+987 13+377+610 2+3+8+987 5+8+377+610 13+144+233+610 2+3+8+377+610 5+8+144+233+610 13+55+89+233+610 2+3+8+144+233+610 5+8+55+89+233+610 13+21+34+89+233+610 2+3+8+55+89+233+610 5+8+21+34+89+233+610 2+3+8+21+34+89+233+610 c:\a\ruby>obfcaps 12804 2+5+21+233+1597+10946 2+5+8+13+233+1597+10946 2+5+21+89+144+1597+10946 2+5+21+233+610+987+10946 2+5+21+233+1597+4181+6765 2+5+8+13+89+144+1597+10946 2+5+8+13+233+610+987+10946 2+5+8+13+233+1597+4181+6765 2+5+21+34+55+144+1597+10946 2+5+21+89+144+610+987+10946 2+5+21+89+144+1597+4181+6765 2+5+21+233+610+987+4181+6765 2+5+8+13+34+55+144+1597+10946 2+5+8+13+89+144+610+987+10946  2+5+8+13+89+144+1597+4181+6765 2+5+8+13+233+610+987+4181+6765 2+5+21+34+55+144+610+987+10946 2+5+21+34+55+144+1597+4181+6765 2+5+21+89+144+233+377+987+10946 2+5+21+89+144+610+987+4181+6765 2+5+21+233+610+987+1597+2584+6765 2+5+8+13+34+55+144+610+987+10946 2+5+8+13+34+55+144+1597+4181+6765 2+5+8+13+89+144+233+377+987+10946 2+5+8+13+89+144+610+987+4181+6765 2+5+8+13+233+610+987+1597+2584+6765 2+5+21+34+55+144+233+377+987+10946 2+5+21+34+55+144+610+987+4181+6765 2+5+21+89+144+233+377+987+4181+6765 2+5+21+89+144+610+987+1597+2584+6765 2+5+8+13+34+55+144+233+377+987+10946 2+5+8+13+34+55+144+610+987+4181+6765 2+5+8+13+89+144+233+377+987+4181+6765 2+5+8+13+89+144+610+987+1597+2584+6765 2+5+21+34+55+144+233+377+987+4181+6765 2+5+21+34+55+144+610+987+1597+2584+6765 2+5+21+89+144+233+377+987+1597+2584+6765 2+5+8+13+34+55+144+233+377+987+4181+6765 2+5+8+13+34+55+144+610+987+1597+2584+6765 2+5+8+13+89+144+233+377+987+1597+2584+6765 2+5+21+34+55+144+233+377+987+1597+2584+6765 2+5+8+13+34+55+144+233+377+987+1597+2584+6765 

That last one (12804) only took about 3 seconds!

Ruby, 118 114 (array output) or 138 134 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|a.combination(n).select{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

Change gets to $*[0] if you want command line arguments (>fibadd 100), +1 character though.

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|a.combination(n).select{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample run:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 

Ruby, 118 114 (array output) or 138 134 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|a.combination(n).select{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

Change gets to $*[0] if you want command line arguments (>fibadd 100), +1 character though.

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|a.combination(n).select{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample runs:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 c:\a\ruby>fibadd 1000 13+987 5+8+987 13+377+610 2+3+8+987 5+8+377+610 13+144+233+610 2+3+8+377+610 5+8+144+233+610 13+55+89+233+610 2+3+8+144+233+610 5+8+55+89+233+610 13+21+34+89+233+610 2+3+8+55+89+233+610 5+8+21+34+89+233+610 2+3+8+21+34+89+233+610 c:\a\ruby>obfcaps 12804 2+5+21+233+1597+10946 2+5+8+13+233+1597+10946 2+5+21+89+144+1597+10946 2+5+21+233+610+987+10946 2+5+21+233+1597+4181+6765 2+5+8+13+89+144+1597+10946 2+5+8+13+233+610+987+10946 2+5+8+13+233+1597+4181+6765 2+5+21+34+55+144+1597+10946 2+5+21+89+144+610+987+10946 2+5+21+89+144+1597+4181+6765 2+5+21+233+610+987+4181+6765 2+5+8+13+34+55+144+1597+10946 2+5+8+13+89+144+610+987+10946  2+5+8+13+89+144+1597+4181+6765 2+5+8+13+233+610+987+4181+6765 2+5+21+34+55+144+610+987+10946 2+5+21+34+55+144+1597+4181+6765 2+5+21+89+144+233+377+987+10946 2+5+21+89+144+610+987+4181+6765 2+5+21+233+610+987+1597+2584+6765 2+5+8+13+34+55+144+610+987+10946 2+5+8+13+34+55+144+1597+4181+6765 2+5+8+13+89+144+233+377+987+10946 2+5+8+13+89+144+610+987+4181+6765 2+5+8+13+233+610+987+1597+2584+6765 2+5+21+34+55+144+233+377+987+10946 2+5+21+34+55+144+610+987+4181+6765 2+5+21+89+144+233+377+987+4181+6765 2+5+21+89+144+610+987+1597+2584+6765 2+5+8+13+34+55+144+233+377+987+10946 2+5+8+13+34+55+144+610+987+4181+6765 2+5+8+13+89+144+233+377+987+4181+6765 2+5+8+13+89+144+610+987+1597+2584+6765 2+5+21+34+55+144+233+377+987+4181+6765 2+5+21+34+55+144+610+987+1597+2584+6765 2+5+21+89+144+233+377+987+1597+2584+6765 2+5+8+13+34+55+144+233+377+987+4181+6765 2+5+8+13+34+55+144+610+987+1597+2584+6765 2+5+8+13+89+144+233+377+987+1597+2584+6765 2+5+21+34+55+144+233+377+987+1597+2584+6765 2+5+8+13+34+55+144+233+377+987+1597+2584+6765 

That last one (12804) only took about 3 seconds!

added 14 characters in body
Source Link
Doorknob
  • 72.1k
  • 20
  • 146
  • 393

Ruby, 118118 114 (array output) or 138138 134 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|[*a|n|a.combination(n)].keep_ifselect{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

Change gets to $*[0] if you want command line arguments (>fibadd 100), +1 character though.

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|[*a|n|a.combination(n)].keep_ifselect{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample run:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 

Ruby, 118 (array output) or 138 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|[*a.combination(n)].keep_if{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

Change gets to $*[0] if you want command line arguments (>fibadd 100), +1 character though.

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|[*a.combination(n)].keep_if{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample run:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 

Ruby, 118 114 (array output) or 138 134 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|a.combination(n).select{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

Change gets to $*[0] if you want command line arguments (>fibadd 100), +1 character though.

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|a.combination(n).select{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample run:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 
[Edit removed during grace period]; added 101 characters in body
Source Link
Doorknob
  • 72.1k
  • 20
  • 146
  • 393

Ruby, 118 (array output) or 138 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|[*a.combination(n)].keep_if{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

Change gets to $*[0] if you want command line arguments (>fibadd 100), +1 character though.

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|[*a.combination(n)].keep_if{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample run:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 

Ruby, 118 (array output) or 138 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|[*a.combination(n)].keep_if{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|[*a.combination(n)].keep_if{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample run:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 

Ruby, 118 (array output) or 138 (correct output)

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i p (1..a.size).flat_map{|n|[*a.combination(n)].keep_if{|o|o.inject(:+)==i}} 

Sample run:

c:\a\ruby>fibadd 100 [[3, 8, 89], [1, 2, 8, 89], [3, 8, 34, 55], [1, 2, 3, 5, 89], [1, 2, 8, 34, 55], [3, 8, 13, 21, 55], [1, 2, 3, 5, 34, 55], [1, 2, 8, 13, 21, 55], [1, 2, 3, 5, 13, 21, 55]] 

Change gets to $*[0] if you want command line arguments (>fibadd 100), +1 character though.

With the correct output:

i=gets.to_i a=[x=y=1] a+=[y=x+x=y]until y>i $><<(1..a.size).flat_map{|n|[*a.combination(n)].keep_if{|o|o.inject(:+)==i}}.map{|o|o*?+}*' ' 

Sample run:

c:\a\ruby>fibadd 100 3+8+89 1+2+8+89 3+8+34+55 1+2+3+5+89 1+2+8+34+55 3+8+13+21+55 1+2+3+5+34+55 1+2+8+13+21+55 1+2+3+5+13+21+55 
Source Link
Doorknob
  • 72.1k
  • 20
  • 146
  • 393
Loading