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

50%
+0 −0
Challenges Add two negabinary integers

Ruby, 75 bytes ->t,u{g=->a{a.reduce{-2*_1+_2}};('%b'%(g[t]+g[u]+(y=43690)^y)).to_i.digits} Try it online! Uses latest ruby features, so tio link will look different. Takes two digit a...

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

Answer
#3: Post edited by user avatar Razetime‭ · 2021-07-09T16:01:36Z (over 3 years ago)
  • # [Ruby], 66 bytes
  • <!-- language-all: lang-ruby -->
  • ->t,u{g=->a{a.reduce{-2*_1+_2}};eval '%b'%(g[t]+g[u]+(y=43690)^y)}
  • [Try it online!][TIO-kqw1a56f]
  • [Ruby]: https://www.ruby-lang.org/
  • [TIO-kqw1a56f]: https://tio.run/##KypNqvyfZvtf165Ep7Q63VbXLrE6Ua8oNaU0ObW6pkKnskbXSKtCu7K21jq1LDFHQV01SV1VIz26JFY7Pbo0Vluj0tbE2MzSQDOuUrP2f4FCWnS0YaxOtEFsLBecY4jC0THUQcgCmcjyEK6OAVANsqAOHEMNgPGBBv0HAA
  • Uses latest ruby features, so tio link will look different.
  • Takes two digit arrays, and returns a string which represents the negabinary integer.
  • Borrows from a conversion technique used [here.](https://codegolf.stackexchange.com/a/113589/80214)
  • # [Ruby], 75 bytes
  • <!-- language-all: lang-ruby -->
  • ->t,u{g=->a{a.reduce{-2*_1+_2}};('%b'%(g[t]+g[u]+(y=43690)^y)).to_i.digits}
  • [Try it online!][TIO-kqwj007a]
  • [Ruby]: https://www.ruby-lang.org/
  • [TIO-kqwj007a]: https://tio.run/##KypNqvyfZvtf165Ep7Q63VbXLrE6Ua8oNaU0ObW6pkKnskbXSKtCu7K21lpDXTVJXVUjPbokVjs9ujRWW6PS1sTYzNJAM65SU1OvJD8@Uy8lMz2zpLj2f4FCWnS0YaxOtEFsLBecY4jC0THUQcgCmcjyEK6OAVANsqAOHEMNgPGBBv0HAA "Ruby – Try It Online"
  • Uses latest ruby features, so tio link will look different.
  • Takes two digit arrays, and returns an array which represents the negabinary integer.
  • Borrows from a conversion technique used [here.](https://codegolf.stackexchange.com/a/113589/80214)
#2: Post edited by user avatar Razetime‭ · 2021-07-09T15:59:43Z (over 3 years ago)
  • # [Ruby], 61 bytes
  • <!-- language-all: lang-ruby -->
  • ->t,u{g=->a{a.reduce{-2*_1+_2}};'%b'%(g[t]+g[u]+(y=43690)^y)}
  • [Try it online!][TIO-kqw1a56f]
  • [Ruby]: https://www.ruby-lang.org/
  • [TIO-kqw1a56f]: https://tio.run/##KypNqvyfZvtf165Ep7Q63VbXLrE6Ua8oNaU0ObW6pkKnskbXSKtCu7K21lpdNUldVSM9uiRWOz26NFZbo9LWxNjM0kAzrlKz9n@BQlp0tGGsTrRBbCwXnGOIwtEx1EHIApnI8hCujgFQDbKgDhxDDYDxgQb9BwA "Ruby – Try It Online"
  • Uses latest ruby features, so tio link will look different.
  • Takes two digit arrays, and returns a string which represents the negabinary integer.
  • Borrows from a conversion technique used [here.](https://codegolf.stackexchange.com/a/113589/80214)
  • # [Ruby], 66 bytes
  • <!-- language-all: lang-ruby -->
  • ->t,u{g=->a{a.reduce{-2*_1+_2}};eval '%b'%(g[t]+g[u]+(y=43690)^y)}
  • [Try it online!][TIO-kqw1a56f]
  • [Ruby]: https://www.ruby-lang.org/
  • [TIO-kqw1a56f]: https://tio.run/##KypNqvyfZvtf165Ep7Q63VbXLrE6Ua8oNaU0ObW6pkKnskbXSKtCu7K21jq1LDFHQV01SV1VIz26JFY7Pbo0Vluj0tbE2MzSQDOuUrP2f4FCWnS0YaxOtEFsLBecY4jC0THUQcgCmcjyEK6OAVANsqAOHEMNgPGBBv0HAA
  • Uses latest ruby features, so tio link will look different.
  • Takes two digit arrays, and returns a string which represents the negabinary integer.
  • Borrows from a conversion technique used [here.](https://codegolf.stackexchange.com/a/113589/80214)
#1: Initial revision by user avatar Razetime‭ · 2021-07-09T07:48:05Z (over 3 years ago)
# [Ruby], 61 bytes

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

    ->t,u{g=->a{a.reduce{-2*_1+_2}};'%b'%(g[t]+g[u]+(y=43690)^y)}

[Try it online!][TIO-kqw1a56f]

[Ruby]: https://www.ruby-lang.org/
[TIO-kqw1a56f]: https://tio.run/##KypNqvyfZvtf165Ep7Q63VbXLrE6Ua8oNaU0ObW6pkKnskbXSKtCu7K21lpdNUldVSM9uiRWOz26NFZbo9LWxNjM0kAzrlKz9n@BQlp0tGGsTrRBbCwXnGOIwtEx1EHIApnI8hCujgFQDbKgDhxDDYDxgQb9BwA "Ruby – Try It Online"

Uses latest ruby features, so tio link will look different.

Takes two digit arrays, and returns a string which represents the negabinary integer.

Borrows from a  conversion technique used [here.](https://codegolf.stackexchange.com/a/113589/80214)