TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

24 点作者 sage_joch大约 11 年前
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 条评论

psuter大约 11 年前
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_bayne大约 11 年前
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 未加载
modeless大约 11 年前
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.
chch大约 11 年前
<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!
rjbwork大约 11 年前
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 未加载
zoba大约 11 年前
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>
andrewflnr大约 11 年前
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.
vittore大约 11 年前
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>
LocalMan大约 11 年前
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?
catmanjan大约 11 年前
Sierpinski&#x27;s Triangles?
tunesmith大约 11 年前
Is this the same as Rule 90?