25
\$\begingroup\$

The Binary Sierpinski Triangle sequence is the sequence of numbers whose binary representations give the rows of the Binary Sierpinski Triangle, which is given by starting with a 1 in an infinite row of zeroes, then repeatedly replacing every pair of bits with the xor of those bits, like so:

f(0)= 1 =1
f(1)= 1 1 =3
f(2)= 1 0 1 =5
f(3)= 1 1 1 1 =15
f(4)= 1 0 0 0 1 =17

More digits are given at OEIS: https://oeis.org/A001317

Input: A non-negative integer n in any format you like. (Must work for all n up to 30.)

Output: The nth term (0-indexed) of the sequence as a decimal number.

This is so try give the shortest answer in bytes of which your language is capable. No answer will be accepted. Standard loopholes apply (e.g. no hard-coding the sequence), except that you may use a language created/modified after this challenge was posted. (Do avoid posting another solution in a language that has already been used unless your solution is shorter.)

Leaderboard

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes

/* Configuration */
var QUESTION_ID = 67497; // Obtain this from the url
// It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 47050; // This should be the user ID of the challenge author.
/* App */
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) {
 return "http://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}
function commentUrl(index, answers) {
 return "http://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}
function getAnswers() {
 jQuery.ajax({
 url: answersUrl(answer_page++),
 method: "get",
 dataType: "jsonp",
 crossDomain: true,
 success: function (data) {
 answers.push.apply(answers, data.items);
 answers_hash = [];
 answer_ids = [];
 data.items.forEach(function(a) {
 a.comments = [];
 var id = +a.share_link.match(/\d+/);
 answer_ids.push(id);
 answers_hash[id] = a;
 });
 if (!data.has_more) more_answers = false;
 comment_page = 1;
 getComments();
 }
 });
}
function getComments() {
 jQuery.ajax({
 url: commentUrl(comment_page++, answer_ids),
 method: "get",
 dataType: "jsonp",
 crossDomain: true,
 success: function (data) {
 data.items.forEach(function(c) {
 if (c.owner.user_id === OVERRIDE_USER)
 answers_hash[c.post_id].comments.push(c);
 });
 if (data.has_more) getComments();
 else if (more_answers) getAnswers();
 else process();
 }
 }); 
}
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
function getAuthorName(a) {
 return a.owner.display_name;
}
function process() {
 var valid = [];
 
 answers.forEach(function(a) {
 var body = a.body;
 a.comments.forEach(function(c) {
 if(OVERRIDE_REG.test(c.body))
 body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
 });
 
 var match = body.match(SCORE_REG);
 if (match)
 valid.push({
 user: getAuthorName(a),
 size: +match[2],
 language: match[1],
 link: a.share_link,
 });
 else console.log(body);
 });
 
 valid.sort(function (a, b) {
 var aB = a.size,
 bB = b.size;
 return aB - bB
 });
 var languages = {};
 var place = 1;
 var lastSize = null;
 var lastPlace = 1;
 valid.forEach(function (a) {
 if (a.size != lastSize)
 lastPlace = place;
 lastSize = a.size;
 ++place;
 
 var answer = jQuery("#answer-template").html();
 answer = answer.replace("{{PLACE}}", lastPlace + ".")
 .replace("{{NAME}}", a.user)
 .replace("{{LANGUAGE}}", a.language)
 .replace("{{SIZE}}", a.size)
 .replace("{{LINK}}", a.link);
 answer = jQuery(answer);
 jQuery("#answers").append(answer);
 var lang = a.language;
 lang = jQuery('<a>'+lang+'</a>').text();
 
 languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
 });
 var langs = [];
 for (var lang in languages)
 if (languages.hasOwnProperty(lang))
 langs.push(languages[lang]);
 langs.sort(function (a, b) {
 if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
 if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
 return 0;
 });
 for (var i = 0; i < langs.length; ++i)
 {
 var language = jQuery("#language-template").html();
 var lang = langs[i];
 language = language.replace("{{LANGUAGE}}", lang.lang)
 .replace("{{NAME}}", lang.user)
 .replace("{{SIZE}}", lang.size)
 .replace("{{LINK}}", lang.link);
 language = jQuery(language);
 jQuery("#languages").append(language);
 }
}
body { text-align: left !important}
#answer-list {
 padding: 10px;
 width: 290px;
 float: left;
}
#language-list {
 padding: 10px;
 width: 290px;
 float: left;
}
table thead {
 font-weight: bold;
}
table td {
 padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="language-list">
 <h2>Shortest Solution by Language</h2>
 <table class="language-list">
 <thead>
 <tr><td>Language</td><td>User</td><td>Score</td></tr>
 </thead>
 <tbody id="languages">
 </tbody>
 </table>
</div>
<div id="answer-list">
 <h2>Leaderboard</h2>
 <table class="answer-list">
 <thead>
 <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
 </thead>
 <tbody id="answers">
 </tbody>
 </table>
</div>
<table style="display: none">
 <tbody id="answer-template">
 <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
 </tbody>
</table>
<table style="display: none">
 <tbody id="language-template">
 <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
 </tbody>
</table>

asked Dec 23, 2015 at 13:36
\$\endgroup\$
5
  • 8
    \$\begingroup\$ I'm not a big fan of must not output a wrong answer for any n. This basically forces languages that do not use arbitrary precision integers by default to check if the input is small enough... \$\endgroup\$ Commented Dec 23, 2015 at 15:46
  • \$\begingroup\$ Please clarify if understood the rules correctly (see comments here and here) and if rounded output (e.g., 1.288490189e10 for input 33) counts as wrong. \$\endgroup\$ Commented Dec 23, 2015 at 19:25
  • \$\begingroup\$ "Must work for all n up to 30, and must not output a wrong answer for any n.". This is self-contradictory - surely "must not output a wrong answer" is the same as "Must work" ??? \$\endgroup\$ Commented Dec 23, 2015 at 19:49
  • 6
    \$\begingroup\$ Due to overwhelming popular opposition to the unreasonable and soul-crushing burden of input validation, this requirement has been removed. You may output whatever garbage you want for large n. Enjoy! \$\endgroup\$ Commented Dec 23, 2015 at 20:13
  • 2
    \$\begingroup\$ Rather than saying that the output shouldn't be wrong, I would recommend just saying that submissions have to support input up to the largest n for which nothing overflows. \$\endgroup\$ Commented Dec 23, 2015 at 20:17

29 Answers 29

14
\$\begingroup\$

05AB1E, (削除) 5 (削除ここまで) 4 bytes

I proudly present to you, 05AB1E. Although it is very short, it is probably very bad at long challenges.

Thanks to ETHproductions for shaving off 1 byte :)

$Fx^

Explanation:

$ # Pushes 1 and input
 F # Pops x, creates a for-loop in range(0, x)
 x # Pops x, pushes x and 2x
 ^ # Bitwise XOR on the last two elements
 # Implicit, ends the for-loop
 # Implicit, nothing has printed so the last element is printed automatically
answered Dec 23, 2015 at 14:22
\$\endgroup\$
7
  • \$\begingroup\$ You know, a good way to golf a byte off of many programs in a custom language is to make a trailing } be automatically inserted. Then this would be 4 bytes. :) \$\endgroup\$ Commented Dec 23, 2015 at 15:54
  • 1
    \$\begingroup\$ @ETHproductions Wait a minute, that already has been implemented :). Thanks for shaving off 1 byte haha. \$\endgroup\$ Commented Dec 23, 2015 at 15:58
  • 2
    \$\begingroup\$ There's a bug in this code. How do I know? It's beating Dennis. \$\endgroup\$ Commented Dec 23, 2015 at 20:43
  • 2
    \$\begingroup\$ @Ampora Not only is it beating Dennis, it's beating Dennis's custom golfing language. ;) \$\endgroup\$ Commented Dec 23, 2015 at 20:54
  • \$\begingroup\$ @Adnan Wow. You're on to something. \$\endgroup\$ Commented Dec 24, 2015 at 14:55
12
\$\begingroup\$

Pari/GP, 27 bytes

n->lift(Mod(x+1,2)^n)%(x-2)

The function takes the \$n\$-th power of the polynomial \$x+1\$ in the ring \$\mathbb{F}_2[X]\$, lifts it to \$\mathbb{Z}[X]\$, and then evaluates it at \$x=2\$.

Try it online!

answered Dec 23, 2015 at 14:46
\$\endgroup\$
0
6
\$\begingroup\$

Jelly, 6 bytes

1Ḥ^3ドル¡

Try it online!

The binary version that works with this revision of the Jelly interpreter has the xxd dump

0000000: 31 a8 5e 24 8b 80 1.^$..

How it works

1Ḥ^3ドル¡ Input: n
1 Set the left argument to 1.
 Ḥ Multiple the left argument by two.
 ^ Hook; XOR it with its initial value.
 $ Create a monadic chain from the last two insructions.
 3¡ Call the chain n times, updating the left argument after each call.
answered Dec 23, 2015 at 14:16
\$\endgroup\$
0
5
\$\begingroup\$

Haskell, 44 bytes

import Data.Bits
f n=iterate((2*)>>=xor)1!!n

In the ((->) r) monad, (f >>= g) x equals g (f x) x.

answered Dec 23, 2015 at 18:21
\$\endgroup\$
3
  • \$\begingroup\$ I think you can anonymize the last line to (iterate((2*)>>=xor)1!!) \$\endgroup\$ Commented Dec 23, 2015 at 19:38
  • \$\begingroup\$ I tried that, but it doesn't work, for dreaded monomorphism restriction reasons. \$\endgroup\$ Commented Dec 24, 2015 at 0:33
  • \$\begingroup\$ However, that might apply as a legal expression, since the monomorphism restriction doesn't apply on expressions, but declarations. And expressions are considered legal answers, if I'm not mistaken. \$\endgroup\$ Commented May 21, 2016 at 20:33
4
\$\begingroup\$

Matlab, 45 bytes

Solution:

@(i)2.^[0:i]*diag(mod(fliplr(pascal(i+1)),2))

Test:

ans(10)
ans =
1285

Explanation: pascal constructs Pascal triangle, but it starts from 1, so input should be i+1. fliplr flips array from left to right. mod(_,2) takes remainder after division by 2. diag extracts main diagonal.Multiplication using 2.^[0:i] converts vector to decimal

I'm glad, @flawr that I found Matlab competitor here :)

answered Dec 23, 2015 at 18:55
\$\endgroup\$
1
  • \$\begingroup\$ Seems to work with Octave as well. \$\endgroup\$ Commented Dec 23, 2015 at 20:14
4
\$\begingroup\$

JavaScript (ES6), 23 bytes

f=x=>x?(y=f(x-1))^y*2:1

Based on the first formula on the OEIS page. If you don't mind the code taking almost forever to finish for an input of 30, we can shave off a byte:

f=x=>x?f(--x)^f(x)*2:1

Here's a non-recursive version, using a for loop in an eval: (32 bytes)

x=>eval("for(a=1;x--;a^=a*2);a")
answered Dec 23, 2015 at 14:41
\$\endgroup\$
5
  • \$\begingroup\$ The rules, as currently written, invalidate this answer, since f(35) returns 15. Also, fork bomb alert: I had to force-close Chromium to stop f(30) (original revision) from running. :P \$\endgroup\$ Commented Dec 23, 2015 at 15:59
  • 1
    \$\begingroup\$ @Dennis Wait, so if I can't output any wrong value, what am I supposed to do with inputs higher than 30? \$\endgroup\$ Commented Dec 23, 2015 at 16:04
  • \$\begingroup\$ I'm not sure (and I hope the rule gets changed), but something like f=x=>x?(y=f(x-(x<31)))^y*2:1 would work. \$\endgroup\$ Commented Dec 23, 2015 at 16:09
  • \$\begingroup\$ @Dennis Ah, recurse infinitely = no output. I'll fix this when I get back to my computer. I hope that rule gets changed as well. \$\endgroup\$ Commented Dec 23, 2015 at 16:11
  • \$\begingroup\$ The rule has been removed from the question. \$\endgroup\$ Commented Dec 23, 2015 at 20:13
3
\$\begingroup\$

Matlab, (削除) 77 (削除ここまで) 70 bytes

This function calculates the n-th row of the Pascal triangle via repeated convolution with [1,1] (a.k.a. binomial expansion or repeated multiplication with a binomial), and calculates the number from that.

function r=c(n);k=1;for i=1:n;k=conv(k,[1,1]);end;r=2.^(0:n)*mod(k,2)'
answered Dec 23, 2015 at 13:54
\$\endgroup\$
3
\$\begingroup\$

CJam, 10 bytes

1ri{_2*^}*

Test it here.

Simple iterative solution using bitwise XOR.

answered Dec 23, 2015 at 14:24
\$\endgroup\$
3
\$\begingroup\$

Ruby, 26 bytes

anonymous function with iteration.

->n{a=1;n.times{a^=a*2};a}

this recursive function is one byte shorter, but as it needs to be named to be able to refer to itself, it ends up one byte longer.

f=->n{n<1?1:(s=f[n-1])^s*2}
answered Dec 23, 2015 at 14:30
\$\endgroup\$
3
\$\begingroup\$

Ruby, 25 bytes

->n{eval"n^=2*"*n+?1*n=1}

Shorter than the other answers on here so far. It constructs this string:

n^=2*n^=2*n^=2*n^=2*1

Then it sets n=1 (this actually happens while the string is being made) and evaluates the above string, returning the result.

answered Dec 25, 2015 at 8:02
\$\endgroup\$
2
  • \$\begingroup\$ Does that *n=1 actually save anything over m=1;"m^=2*"*n+?1 \$\endgroup\$ Commented Dec 25, 2015 at 8:13
  • \$\begingroup\$ No, but doing it with just one variable is very showy :) \$\endgroup\$ Commented Dec 25, 2015 at 8:14
3
\$\begingroup\$

Samau, 4 bytes

Now Samau has built-in functions for XOR multiplication and XOR power.

▌3$n

Hex dump (Samau uses CP737 encoding):

dd 33 24 fc

Explanation:

▌ read a number
 3 push 3
 $ swap
 n take the XOR power
answered Dec 24, 2015 at 13:40
\$\endgroup\$
3
  • \$\begingroup\$ Could this be reduced to 3 bytes by swapping the first two commands and eliminating the swap? \$\endgroup\$ Commented Jan 22, 2016 at 20:33
  • \$\begingroup\$ @quintopia No. Samau automatically pushes the input onto the stack as a string , and reads a number from the string. If we swap the first two commands, it would try to read a number from 3, which is not a string. \$\endgroup\$ Commented Jan 23, 2016 at 4:48
  • \$\begingroup\$ why doesn't samau try to eval the string when possible? \$\endgroup\$ Commented Jan 23, 2016 at 5:06
2
\$\begingroup\$

Pure Bash (no external utilities), 37

Bash integers are 64-bit signed, so this works for inputs up to and including 62:

for((x=1;i++<1ドル;x^=x*2)){
:
}
echo $x
answered Dec 23, 2015 at 17:40
\$\endgroup\$
0
2
\$\begingroup\$

Python 2.7.6, (削除) 38 (削除ここまで) 33 bytes

Thanks to Dennis for shaving off a few bytes!

x=1
exec'x^=x*2;'*input()
print x
answered Dec 23, 2015 at 18:03
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to Programming Puzzles & Code Golf! exec'x^=x*2;'*input() saves a few bytes over the for approach. \$\endgroup\$ Commented Dec 23, 2015 at 18:20
  • \$\begingroup\$ This beats my Python entry, which I'll just leave here for posterity: f=lambda n:f(n-1)^2*f(n-1)if n>0 else 1 \$\endgroup\$ Commented Dec 23, 2015 at 22:33
2
\$\begingroup\$

Pyth, 7 bytes

uxyGGQ1

Try it online: Demonstration

Explanation:

u Q1 apply the following statement input-times to G=1:
 xyGG update G with (2*G xor G)
answered Dec 25, 2015 at 9:45
\$\endgroup\$
2
\$\begingroup\$

MATL, 15 bytes

Similar to @flawr's answer:

i:1w"TToX+]2\XB

EDIT (May 20, 2016) Try it online! with X+ replaced by Y+ to conform to version 18.0.0 of the language.

Example

>> matl i:1w"TToX+]2\XB
> 5
51

Explanation

i % input 
: % vector of values 1, 2, ... to previous input 
1 % number literal 
w % swap elements in stack 
" % for 
 TTo % vector [1 1]
 X+ % convolution 
] % end 
2\ % modulo 2
XB % convert from binary to decimal 
answered Dec 24, 2015 at 11:46
\$\endgroup\$
2
\$\begingroup\$

Perl 5, 23 bytes

$.^=2*$.for 1..<>;say$.

Try it online!

answered Jan 20, 2018 at 0:04
\$\endgroup\$
2
\$\begingroup\$

MIPS, 28 bytes

Input in $a0, output in $v0.

0x00400004 0x24020001 li $v0, 1
0x00400008 0x10800005 loop: beqz $a0, exit
0x0040000c 0x00024021 move $t0, $v0
0x00400010 0x00021040 sll $v0, $v0, 1
0x00400014 0x00481026 xor $v0, $v0, $t0
0x00400018 0x2084ffff addi $a0, $a0, -1
0x0040001c 0x08100002 j loop
answered Dec 23, 2015 at 17:06
\$\endgroup\$
2
\$\begingroup\$

TI-BASIC (TI-83 Plus), (削除) 34 (削除ここまで) (削除) 25 (削除ここまで) 24 bytes

Input N
seq(A,A,0,N
sum(2^Ansnot(not(fPart(N nCr Ans/2

uses this cool formula: \$\sum_{a=0}^{n}([\binom{n}{a}\mod2]2^a)\$ (apologies, i'm still learning LaTeX)

answered May 16 at 13:32
\$\endgroup\$
1
\$\begingroup\$

Mathematica, (削除) 40 (削除ここまで) 24 bytes

Nest[BitXor[#,2#]&,1,#]&
answered Dec 23, 2015 at 13:58
\$\endgroup\$
1
\$\begingroup\$

k4, 26 bytes

{x{2/:~(=). 0b\:'1 2*x}/1}

0b\: converts a number to a boolean vector (i.e. bitstring), XOR is implemented as "not equal", 2/: converts a bitstring back to a number by treating it as a polynomial to evaluate, and x f/y with x an integer is f applied to y first, and then to its successive outputs x times.

Sample run:

 {x{2/:~(=). 0b\:'1 2*x}/1}'!5 
1 3 5 15 17
answered Dec 23, 2015 at 18:05
\$\endgroup\$
1
\$\begingroup\$

Ruby, (削除) 31 (削除ここまで) 26 bytes

EDIT: Changed to a different language entirely! All golfing suggestions welcome!

This program bitwise XORs the previous element of the sequence with twice itself, i.e. f(n) = f(n-1) ^ 2*f(n-1).

->n{v=1;n.times{v^=2*v};v}
answered Dec 25, 2015 at 5:22
\$\endgroup\$
0
1
\$\begingroup\$

brainfuck, 87 bytes

,[>>[>]++<[[->+>+<<]>-->[-<<+>>]<[>+<-[>-<-]]>+<<<]>>>[[-<+>]>]<<[<]<-]>>[<[->++<]>>]<+

Try it online!

Assumes infinite sized cells (otherwise it can’t get past 7, which is conveniently 255). The Pascal’s triangle mod 2 method is actually much longer because of the costly mod 2 operation, while XOR is much easier to implement.

answered Jan 20, 2018 at 5:39
\$\endgroup\$
1
\$\begingroup\$

Stax, 5 bytes

±s┤ε─

Run and debug online!

Port of the Jelly answer.

Uses ASCII representation to explain:

ODcH|^
O Put 1 under top of stack
 D Repeat for times specified by input
 cH|^ Xor the number with itself doubled
 Implicit output
answered Mar 12, 2018 at 11:25
\$\endgroup\$
1
\$\begingroup\$

Japt, 8 bytes

Remove to use 1-indexing.

È^XÑ}g1ì

Try it

answered May 7 at 10:38
\$\endgroup\$
1
\$\begingroup\$

C (gcc), 28 bytes

k;f(n){k=n--?f(n)^2*f(n):1;}

Try it online!

Much original. So innovation. TIO pls don't IP ban for unleashing hell upon your servers.

This is mostly a direct port of ETHProductions's Javascript answer.

32 bytes

k;f(n){for(k=1;n--;k^=k*2);k=k;}

Port of the same person's non-recursive answer.

46 bytes

i,k;f(n){for(i=k=0;i<=n;)k=k*2|!(i++&~n);k=k;}

My original code and idea for solving this. Widely inefficient on bytes compared to the other 2 answers but I thought the code still looked cool.

answered May 16 at 6:30
\$\endgroup\$
0
\$\begingroup\$

APL, 31 bytes

{({2⊥⊃~1 2=.{(64⍴2)×ばつ⍵}⍵}⍣⍵)1}

This is almost certainly awful code, but I'm a complete APL newb. I expect anyone with any skill could get rid of all the D-functions and shorten it considerably. The logic is more or less the same as my k4 answer -- multiply by 1 or 2, convert to bits with , XOR using not equals, convert back to a number with , wrap the whole thing in a function and ask for a specific number of iterations using . I have no idea why the result coming out of the inner product is enclosed, but cleans that up.

answered Dec 23, 2015 at 19:21
\$\endgroup\$
2
  • \$\begingroup\$ You should be able to save a byte by changing ~1 2=. to 1 2≠. \$\endgroup\$ Commented Jul 3, 2017 at 13:12
  • \$\begingroup\$ And, which APL system is this on? If it's on Dyalog, you should be able to make it {({2⊥⊃1 2≠.((64⍴2)⊤×)⍵}⍣⍵)1} [28 bytes] \$\endgroup\$ Commented Jul 3, 2017 at 13:14
0
\$\begingroup\$

Seriously, 12 bytes

2,╣`2@%`Mεj¿

Hex Dump:

322cb960324025604dee6aa8

Try it online

Since Seriously does not include any means of doing a bitwise xor, this solution takes the challenge completely literally, directly computing the given row of the triangle. This method gives correct answers up to n=1029 (after which there is not enough memory to compute the given row of Pascal's triangle).

Explanation:

 , get input
 ╣ push the nth row of pascal's triangle
 `2@%`M take each element of the row mod 2
 εj join all the binary digits into a string
2 ¿ interpret it as a base 2 number
answered Dec 23, 2015 at 13:36
\$\endgroup\$
0
\$\begingroup\$

Pyt, (削除) 40 (削除ここまで) 10 bytes

Đ0⇹Řć2%ǰ2Ĩ

Explanation:

Observing that the Binary Sierpinski Triangle is equivalent to Pascal's Triangle mod 2,

 Implicit input
Đ Duplicate input
 0⇹Ř Push [0,1,2,...,input]
 ć2% Calculate the input-th row of Pascal's Triangle mod 2
 ǰ Join elements of the array into a string
 2Ĩ Interpret as a binary number
 Implicit print

Try it online!

answered Jan 8, 2018 at 4:53
\$\endgroup\$
0
\$\begingroup\$

J-uby, 21 bytes

:**&(:^%(:*&2))|~:^&1

Attempt This Online!

Explanation

:** & (:^ % (:* & 2)) | ~:^ & 1
 :^ % (:* & 2) # n^(2*n)
:** & ( ) | # ...applied input times
 ~:^ & 1 # ...with n starting at 1
answered May 7 at 2:00
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.