TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: an extremely simple program shows a 2D structure in the integers

24 pointsby sage_jochabout 11 years ago
This seems unlikely to be a &quot;new&quot; idea, but I stumbled into it by accident and thought it was cool. Java source code below:<p><pre><code> &#x2F;&#x2F; This class is in the public domain. public class Numbers { public static void main(String[] args) { int numRows = 256; int numColumns = 128; for (int row = 0; row &lt; numRows; row++) { StringBuilder rowOutput = new StringBuilder(); for (int column = 0; column &lt; numColumns; column++) { if ((row &amp; column) != 0) rowOutput.append(&quot;1&quot;); else rowOutput.append(&quot;0&quot;); } System.out.println( String.format(&quot;row&#x2F;col %s:\t%s&quot;, row, rowOutput.toString())); } } }</code></pre>

11 comments

psuterabout 11 years ago
This was on HN a couple of days ago:<p><pre><code> http:&#x2F;&#x2F;www.oftenpaper.net&#x2F;sierpinski.htm </code></pre> It points out that you can interpret the table as the relation &quot;is disjoint&quot; between the bitsets encoded in the row and col indices (CTRL+F for &quot;binary logic&quot;). Following links from there will take you to a rabbit hole of combinatorics that I will not claim to fully understand.<p>The whole page is a delight, though, and given your enjoyment for your discovery, you&#x27;ll certainly love browsing it.
duncan_bayneabout 11 years ago
Reminds me of Sierpinski triangles:<p><a href="http://en.wikipedia.org/wiki/Sierpinski_triangle" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Sierpinski_triangle</a><p>I&#x27;m sure someone with a greater intuition for mathematics than I have will be able to explain why.
评论 #7456815 未加载
modelessabout 11 years ago
Here&#x27;s a C version in less than 80 characters:<p><pre><code> main(c,r){for(r=32;r;)printf(++c&gt;31?c=!r--,&quot;\n&quot;:c&lt;r?&quot; &quot;:~c&amp;r?&quot; `&quot;:&quot; #&quot;);} </code></pre> I first learned of this phenomenon in my discrete math class, and we had a competition to see who would write the shortest program to draw a Sierpinski triangle. This version would certainly have won if I&#x27;d been clever enough to write it at the time, though even shorter versions are possible in other languages.
chchabout 11 years ago
<a href="http://faculty.msmary.edu/heinold/bitwise_and.pdf" rel="nofollow">http:&#x2F;&#x2F;faculty.msmary.edu&#x2F;heinold&#x2F;bitwise_and.pdf</a><p>seems to be a paper on this phenomenon, with<p><a href="http://faculty.msmary.edu/heinold/maa_pres2009-11-14.pdf" rel="nofollow">http:&#x2F;&#x2F;faculty.msmary.edu&#x2F;heinold&#x2F;maa_pres2009-11-14.pdf</a><p>being a similar work in presentation form.<p>I&#x27;ve never seen it before; I like it!
rjbworkabout 11 years ago
For any lazy C# folks:<p><pre><code> internal class Program { public static void Main() { int numRows = 256; int numColumns = 128; for (int row = 0; row &lt; numRows; row++) { StringBuilder rowOutput = new StringBuilder(); for (int column = 0; column &lt; numColumns; column++) { if ((row &amp; column) != 0) rowOutput.Append(&quot;1&quot;); else rowOutput.Append(&quot;0&quot;); } Console.WriteLine(&quot;row&#x2F;col {0}:\t{1}&quot;, row, rowOutput); } Console.Read(); } } </code></pre> Cool stuff, very interesting to see that triangle structure emerge.
评论 #7457423 未加载
zobaabout 11 years ago
Interesting, I&#x27;ve not seen this before. Here is a screenshot of some of the output: <a href="http://i.imgur.com/Ro2AA6u.jpg" rel="nofollow">http:&#x2F;&#x2F;i.imgur.com&#x2F;Ro2AA6u.jpg</a>
andrewflnrabout 11 years ago
That&#x27;s cool. You can expand the pattern, presumably arbitrarily, by setting the number of columns to 256 or 512 (or greater?), but on my little 1440px screen I had to redirect to a file and scroll it sideways in an editor to see the whole thing.
vittoreabout 11 years ago
You will probably like searches for rule NNN on wolfram alpha, like <a href="http://www.wolframalpha.com/input/?i=rule+101" rel="nofollow">http:&#x2F;&#x2F;www.wolframalpha.com&#x2F;input&#x2F;?i=rule+101</a>
LocalManabout 11 years ago
Back when they taught me the number line and the Cartesian plane, it all seemed smooth and straightforward.<p>In the years since, I&#x27;ve seen primes, rationals, irrationals, Mandelbrot, and all manner of weird structures popping up out of what seemed like nothing.<p>How did this happen? And who put all that stuff in there?
catmanjanabout 11 years ago
Sierpinski&#x27;s Triangles?
tunesmithabout 11 years ago
Is this the same as Rule 90?