HNHacker News
TopNewBestAskShowJobs

chengsun

218 karma · joined March 11, 2012

  https://<username>.uk
  _@<username>.uk
submissionscomments
chengsun··on Missed optimizations in C compilers
This optimisation is actually fully correct if int is 32-bits wide. This is because doubles have a 52-bit mantissa, which means that they can exactly represent all integers up to 2^53 in magnitude. However you are right that the optimisation would not be valid, had int been 64-bits in width.
chengsun··on The N-Queens completion problem is NP-hard
No, you're talking about a different problem: that of counting the total number of n-queens solutions. The original article is talking about the problem of deciding, given a partial placement of queens, whether it can be completed by adding further queens to form an n-queen solution.
chengsun··on TrackMania is NP-complete
This is only true assuming that P != NP, which is still an unsolved question.

Furthermore, NP-completeness only applies to decision problems. In this case the paper explores the problem of deciding whether or not there exists a path which will complete the track.

The upshot is, if there exists a polynomial-time algorithm to decide this question, then we can use this algorithm to solve all other NP decision problems in polynomial time.

chengsun··on Winning 1kb intro released at Assembly 2015
Also, a fantastic visual guide is the documentary film "Moleman 2" (2011). It's freely available to watch on YouTube; highly recommended: https://www.youtube.com/watch?v=iRkZcTg1JWU
chengsun··on Why It Pays to Be a Jerk
This is not true in general.

Consider two independent fair die rolls, with A and C being the outcomes. Let B be the sum of the outcomes. The higher A is, the higher B is likely to be, so A and B are positively correlated. So are B and C. However there is no correlation between A and C as they are independent.

chengsun··on VP9: Faster, better, buffer-free YouTube videos
Video codecs are good at compressing stills, so there's very little overhead in playing such a video when only the audio is desired.

That being said, YouTube does also encode audio-only versions of all their videos; they're not available from the web player though. You can use external software such as youtube-dl[1] to take advantage of it.

[1]: https://github.com/rg3/youtube-dl/ (using an invocation such as "youtube-dl -g -f bestaudio [url]" to retrieve the URL of an audio-only encode)

chengsun··on Revision demoparty live
Sundown is probably the most well-known one:

http://www.demoparty.net/sundown2015/

http://www.sundowndemoparty.net/ [not updated for 2015 yet]

chengsun··on Why Baidu Has Been Hijacked to Attack GitHub
Ah, that clears things up. Thanks for the info.
chengsun··on Why Baidu Has Been Hijacked to Attack GitHub
This was worded misleadingly. This is indeed a DDoS: code has been injected to load the Github pages in the background using XHR without the user's knowledge. The host page itself is not redirected (or visibly affected in any way[1]).

Furthermore, only people outside of China are affected by this -- Chinese citizens don't have this code injected.

[1]: Actually there is a mistake in the injected code that causes the result of the XHR request to be interpreted as JavaScript, and then executed. Hence GitHub has tried to mitigate the attack by replying 'alert("WARNING: malicious javascript detected on this domain")' to notify the user that this is happening.

chengsun··on Texgen.js – Lightweight Procedural Texture Generator
The source for each sample is all in index.html: https://github.com/mrdoob/texgen.js/blob/master/index.html
chengsun··on WebGL Water Simulator
Unfortunately the effects that you describe are nontrivial. The method of water simulation that is used here doesn't lend itself to simulating the effects of things like water tension or breaking waves. This is because the water surface is represented as a 2D height-map, representing the displacement from equilibrium (i.e. the z coordinate as a function of x and y). It's clear that it is not possible to represent water clinging to the sphere or dripping off it.

A particle-based system could simulate the effects you describe (by keeping track of the positions of some large number of water "molecules" and exchanging forces between each pair of particles), however the simulation would be far too costly to run in real-time on typical hardware today. It also has its downsides. With a height-map based representation it is trivial to calculate the normal to the surface of the water, which is necessary for the lighting effects, but with a particle system you would need to reconstruct the surface of the water in an additional step each frame, using something like the marching cubes algorithm.

chengsun··on Look at the humongous type that Hindley-Milner infers for this tiny program
Even so, O(4^n) != O(8^n); there is no constant k such that k * 4^n >= 8^n.
chengsun··on Sunfish: A simple but strong chess engine in 111 lines of Python
Óscar Toledo G. has notably written various tiny, strong and highly obfuscated chess engines in C (winning the IOCCC twice) and JavaScript (2nd place in the first JS1k). He's even written a 170 page book to serve as a reference to the 1326-byte "Nanochess" program, his strongest small chess engine.

http://www.nanochess.org/chess.html

chengsun··on Lossless audio compression with libpng
Don't forget https://www.scenemusic.net/demovibes/ - demoscene streaming music radio
chengsun··on Simulation class: 2D wave equations (in browser)
The trick is to perform damping around the edges in a hidden border around the heightmap. Say you wanted to simulate a 500x500 heightmap. You would actually calculate the results for a 700x700 heightmap, (which contains a hidden border of width 100 around each edge). The hidden edges are slowly damped away by multiplying by a factor interpolated between 1 (on the inner edge of the visible part of the heightmap) 0 (on the very outside of the heightmap).

This works remarkably well; you can see this approach in action in http://www.falstad.com/ripple/ for instance. Source code is included on the page.

chengsun··on How to talk to an open source project as a large scale or interesting user
Good point, but I believe you mean "pidgin of a language"!
chengsun··on Evolutionary algorithm to find Quake III's fast inverse square hack with Python
On the flip side of the coin, there's ries, which takes a number and finds a mathematical expression that approximates it: http://mrob.com/pub/ries/
chengsun··on Evolutionary algorithm to find Quake III's fast inverse square hack with Python
Řrřola (a famous demoscene coder [1]) found a far better constant than the original (a 2.7-fold accuracy improvement) by using an optimisation algorithm over all three constants present in the original inverse square hack.

His algorithm and the result (along with a plot of relative error) can be found on his blog [2].

[1]: See, for example, this 256-byte raycaster https://www.youtube.com/watch?v=R35UuntQQF8

[2]: http://rrrola.wz.cz/inv_sqrt.html

chengsun··on Brick. Webfonts that look good
You'll need to allow brick.im if you have NoScript, because NoScript blocks web fonts.
chengsun··on JSVM
Shameless plug: a while back I wrote an assembler-and-VM for a similarly hypothetical assembly language that I was studying in class. Just for kicks, I wondered if I could fit the entire thing into 1KB of JavaScript, whilst including features as step by step execution, a "debugging GUI" (as much as you could expect from 1KB!) featuring the stack, register contents and program counter, plus the assembler on top which performs full syntax/opcode argument checking.

The result (which I'm pretty pleased with) is here: http://chengsun.github.io/ocremutiny.html

chengsun··on 8BitBoy – A Flash-based Amiga Modplayer
Online radio dedicated to demoscene music: https://www.scenemusic.net/demovibes/
chengsun··on 8BitBoy – A Flash-based Amiga Modplayer
Yep, see gasman's JSModPlayer: http://jsspeccy.zxdemo.org/jsmodplayer/
chengsun··on Show HN: Online SID-Player with spectrum viewer
It was introduced in Firefox 5 [1]. You can change it in about:config by tweaking "dom.min_background_timeout_value" to a lower value (in milliseconds).

[1]: https://bugzilla.mozilla.org/show_bug.cgi?id=633421

chengsun··on Show HN: Online SID-Player with spectrum viewer
Also check out this JavaScript Amiga MOD player by gasman:

http://jsspeccy.zxdemo.org/jsmodplayer/

chengsun··on Show HN: Online SID-Player with spectrum viewer
This is probably because Firefox (and Chrome) clamps the setTimeout interval of background tabs to 1 second to improve performance.
chengsun··on Snake Game in 30 lines of JavaScript
Not to be unappreciative of this cool demo, but here's a snake game I wrote a while ago that clocks in at 41 "commented lines" of code, and minifies to under 1KB of code whilst including setting up the DOM and CSS (which is counted separately here), and features such as pausing and aging food:

http://chengsun.github.io/snake.html

chengsun··on Fourier Toy
You can change the phase by holding ctrl-shift and dragging the circle. If you want a negative value just use the absolute magnitude with the component in antiphase.
chengsun··on Fourier Toy
The nth circle from the right is n times the speed of the first circle.
chengsun··on What's new for developers in Android 4.4 KitKat
It is, but Nestle have allowed Google to use the name, as part of a mutual promotion.
chengsun··on This seem legit...
If you repeatedly test another password, the prompt changes. Quite hilarious.

Also, the terms and conditions are fake too.

"If you read all the legalese up to this point (or just got there by random scrolling), you probably have noticed that this document is complete nonsense. [...] First, chapter 10 of Mary Shelley's /Frankenstein/. Second, a copy of some treaty."

Page 1 of 2Next →