Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Ollaya – Ollama for open-source, Jev-style decision models (ollaya.dev)
    82comments
  2. Revealing the details of how OpenAI agents hacked Hugging Face (swarmtraces.org)
    32comments
  3. Show HN: Jev Plays Pokémon Red (jev-pokemon.vercel.app)
    54comments
  4. What Even Is an OS Now? (sockpuppet.org)
    10comments
  5. Excel now supports multiple values in a single cell (techcommunity.microsoft.com)
    13comments
  6. Ask HN: Who's still keeping a DOS machine up because the business depends on it?
    23comments
  7. Platform-independent SIMD in Go (go.dev)
    129comments
  8. How we learned to stop worrying and love campus surveillance (fnl.mit.edu)
    18comments
  9. Git-bug: Distributed, offline-first bug tracker embedded in Git (github.com/git-bug)
    93comments
  10. Initial DIY Cleanroom Experimentation (jefftk.com)
    1comments
  11. Gravity seems holographic. What does that mean for reality? (quantamagazine.org)
    85comments
  12. Plan mode is dead (aymannadeem.com)
    30comments
  13. U.S. appeals court upholds designation of Anthropic as supply chain risk (cnbc.com)
    619comments
  14. First Principles Thinking (sunilsadasivan.com)
    91comments
  15. An airport cooled by natural ventilation (theguardian.com)
    7comments
  16. Show HN: Make math automatic with Mathy (gmays.com)
    10comments
  17. Remembering Johannes Doerfert (llvm.org)
    —discuss
  18. How video games inspire great UX (2019) (jenson.org)
    12comments
  19. Pentium II at 600Mhz with Voodoo 3 Emulated on 86Box with M6 Mac Mini (nyaa.sh)
    111comments
  20. Ink and Switch interactive homepage (inkandswitch.com)
    25comments
  21. Alan Kay: Shannon gave us a way of dealing with noisy channels [video] (youtube.com)
    22comments
  22. Bwbach, My Guardian Goblin (robertmay.photography)
    14comments
  23. What happens when you analyze your favorite college football team like the CIA? (cultivatelabs.com)
    14comments
  24. Show HN: I discovered roads in the US across > 1000 themes (pinedesk.biz)
    4comments
  25. Meta's Muse appears to use an OpenAI model labeled muse-special (mouse.dev)
    41comments
  26. Amiga Screens: A Primer (datagubbe.se)
    36comments
  27. Factorio that you can touch (factorio.com)
    86comments
  28. Show HN: Whiteboard (YC W26) – An open-source IDE for thoughtful software design (github.com/devdotfast)
    128comments
  29. Ask HN: Hypothesis: Cellular providers are deprioritizing voice calls?
    12comments
  30. Boards of Casio (ambionix.com)
    38comments

I wrote a ray tracer in Brainfuck

13 pointsby 12h agoepestr.com
3 comments
11h agoHN ↗

Isn't this just a ray tracer in python/c that spits out brainfuck? By this logic gcc writes all my programs in assembly lol

41m agoHN ↗

Well the proper analogy would be that you write your programs in assembly. I think the more impressive thing here isn't the ray tracer, but the C (or was it C++?) to brainf** transpiler. That would be equivalent to you writing both C code and the C compiler. Pretty impressive, but depending on the complexity of the program not as impressive as writing whatever it is in assembly directly. A raytracer would be PAIN to write directly in brainf** - I think I'd want to use fixed precision everywhere rather than emulated floating point. (on second glance, it does look like the author of the article is also using fixed precision arithmetic, but confusing the label for the layout of the number with the type of number representation itself?)

19m agoHN ↗

brainfuck is unpleasant to write directly - e.g. the language doesn't have variables, so you need to manually do the bookkeeping of which memory offset is storing what 'variable'. & if you need to refactor your program slightly, in a way that changes the memory layout, maybe you need to manually rework the absolute & relative offsets. So I can appreciate why the author didn't roll up their sleeves to directly write BF - that's neither a productive nor interesting exercise.

Interesting to see how the author decomposed the problem:

- C raytracer https://github.com/mTvare6/rayfuck/blob/master/ray.c

~~ LLM refactor of the C code ~~>

- SSA-style C raytracer code https://github.com/mTvare6/rayfuck/blob/master/ray_ssa.c

~~ c2dsl.py helper script (compiler) ~~>

- DSL raytracer https://github.com/mTvare6/rayfuck/blob/master/ray.dsl

~~ dsl2bf.py helper script (another compiler) ~~>

BF raytracer https://github.com/mTvare6/rayfuck/blob/master/ray.bf (~22 mb of unreadable nonsense)

The dsl2bf compiler has a bunch of examples of implementing slightly higher level abstractions atop BF primitives. E.g. "go" to move the pointer to a different offset, destructive & non-destructive copies, all the way up to things like division -- BF only natively offers unary addition/subtraction.

If we have a read of the code of the final compiler, dsl2bf.py, the abstractions used in that code are relatively simple: global variables, local variables, lists, dicts, for loops, function definitions & function calls. It is feasible to implement a simple compiler like dsl2bf in BF itself, with sufficient head scratching. Again, quite unpleasant to try it directly in BF, but a next step could be to implement the dsl2bf compiler in the DSL itself - extending it if necessary, then compiling it with itself to produce a dsl2bf compiler implemented in BF.