随笔分类 -  haskell

摘要:原文地址(需要FQ)Solving systems of linear equationsinHaskellHaskell isn’t normally used for things like this, but it’s quite possible to solve systems of linear equations with Haskell.There are already several libraries for doing this, and other more advanced matrix manipulating. But here, I’m going to st 阅读全文
posted @ 2012-06-29 16:32 劳工 阅读(450) 评论(0) 推荐(0)
摘要:孩子要上3年级了,里面涉及分数的部分,先准备一下。haskell中涉及分数的模块是Ratio。RatioSynopsisDocumentationdata Ratio aRational numbers, with numerator and denominator of some Integral type.InstancesTypeable1 RatioIntegral a => Enum (Ratio a)Eq a => Eq (Ratio a)Integral a => Fractional (Ratio a)Integral a => Num (Ratio a 阅读全文
posted @ 2012-06-29 14:26 劳工 阅读(521) 评论(0) 推荐(0)
摘要:版本一:这个是最初的版本,刚刚学习haskell,存在以下几个问题。只能在ghci交互环境中运行,然后复制粘贴到文件当中。随机数的生成有点生硬,因为是从网络上抓下来的代码。Haskell语言: Codee#2681501 -- file: make_math.hs02 -- 出n道两个参数的加减法03 -- 使用方法: gs n x y04 -- n 表示需要多少道题05 -- x 表示最小值06 -- y 表示最大值07 -- 比如 gs 10 100 999 表示出10道 加减法08 09 import System.Random10 import System.IO.... 阅读全文
posted @ 2012-06-12 15:08 劳工 阅读(205) 评论(0) 推荐(0)
摘要:最近老师总是让出一些计算题,于是用haskell写了一个。-- file: make_math2.hs-- 出n道三个参数的加法-- 452 + 990 + 130=1572-- 使用方法: gs n x y-- n 表示需要多少道题-- x 表示最小值-- y 表示最大值-- 比如 gs 10 100 999 表示出10道 加法-- gs'会过滤掉被10整除的数字,这样难一点import System.Randomimport System.IO.UnsafedrawInt :: Int -... 阅读全文
posted @ 2012-06-07 21:24 劳工 阅读(449) 评论(0) 推荐(0)
摘要:一道奥数题,1999年,一个青年说,今年我的生日已过了,我现在的年龄正好是我出生年份的四个数字之和。这个青年是哪年出生的?-- file : AS.hs-- 奥数计算calculateA :: [Integer]calculateA = [ years |a<-[1..9],b<-[0..9],c<-[0..9],d<-[0..9],let years=a*1000+b*100+c*10+d,years<1999,(1999-years)==(a+b+c+d)]Prelude> :l AS.hs [1 of 1] Compiling Main ( AS.hs 阅读全文
posted @ 2012-06-07 09:50 劳工 阅读(189) 评论(0) 推荐(0)