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.

Factorization diagrams in Haskell

103 pointsby Peterisover 12 years ago

6 comments

jonpover 12 years ago
Here's a JavaScript/HTML5/Canvas version.<p>You can view the first 100 diagrams in a grid or view the diagram for the N of your choice. There's also an option to view an alternative diagram where the drawing starts with the smallest prime instead of the smallest.<p><a href="http://jsfiddle.net/FEKX2/3/" rel="nofollow">http://jsfiddle.net/FEKX2/3/</a>
评论 #4621104 未加载
评论 #4620475 未加载
评论 #4620370 未加载
walrusover 12 years ago
Install dependencies:<p><pre><code> cabal install arithmoi cabal install diagrams </code></pre> Copy all the code from the blog post into a file (let's call it factor.hs). At the end of that file, add:<p><pre><code> main = defaultMain $ factorDiagram YOUR_NUMBER </code></pre> Then run:<p><pre><code> runhaskell factor.hs -o image.png -w 400</code></pre>
评论 #4620249 未加载
Bakkotover 12 years ago
&#62; Of course, this really only works well for numbers with prime factors drawn from the set {2, 3, 5, 7}.<p>So express the number as a sum of numbers with factors drawn from that set, and draw a several diagrams, one for each summand. A quick bit of Python confirms that every number under 14925 can be expressed as the sum of no more than three such numbers in the most obvious way possible (ie using a greedy algorithm).<p>For example, you might write 9999 as 9800 + 196 + 3, all of which have nice factorization diagrams.
评论 #4620871 未加载
评论 #4622686 未加载
评论 #4623955 未加载
yscover 12 years ago
Zero comments even though it's a nice read. I guess everyone suddenly got busy after reaching the paragraph "I wish I knew how to make a website where you could enter a number and have it show you the factorization diagram… maybe eventually." :)
评论 #4620176 未加载
cocoflunchyover 12 years ago
Here's my version: <a href="http://cocoflunchy.github.com/factorviewer/" rel="nofollow">http://cocoflunchy.github.com/factorviewer/</a> Not perfect at all... but it works.
评论 #4621151 未加载
the_cat_kittlesover 12 years ago
Wonderful. I'm glad you did this, it was entertaining to read