我正在尝试使用 adc 转换器 (ads1115 )。
但是当我尝试运行示例脚本时;简单测试.py
我得到:
读取 ADS1x15 值,按 Ctrl-C 退出...
回溯(最近一次调用最后):文件“simpletest.py”,第 43 行,值 [i] = adc.read_adc(i, Gain=GAIN) 文件“build/bdist.linux-armv7l/egg/Adafruit_ADS1x15/ADS1x15. py”,第 192 行,在 read_adc 文件“build/bdist.linux-armv7l/egg/Adafruit_ADS1x15/ADS1x15.py”中,第 133 行,在 _read 文件“build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py”中,第 136 行,readList 文件“build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py”,第 216 行,read_i2c_block_data 类型错误:需要一个字符串
当我运行诊断命令:i2cdetect 时,我得到了这个
i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: …Run Code Online (Sandbox Code Playgroud) 记住你的第一次(在Haskell循环中)
我试图通过一些Hackerrank问题来教自己一点Haskell.
我正在研究的问题涉及读取坐标集(x1,y1)和(x2,y2)以及确定由这些坐标绘制的多边形的周长.
到目前为止,这是我的代码:
-- Calculate length of line given points x1,y2, x2,y2
calc_length:: Int -> Int -> Int -> Int -> Float
calc_length x1 y1 x2 y2 =
sqrt ( fromIntegral (height ^2 + width ^2) )
where height = abs( y2 - y1)
width = abs( x2 - x1)
main = do
x <- readLn :: IO Double
forM_ [1,2..(x / 2)] $ \lc -> do
line1 <- getLine
let wds1 = map (\str -> read str::Int) (words …Run Code Online (Sandbox Code Playgroud) 我是Haskell的新手,我正试图找出一种合理的方式来写地图(准备解决特定的欧拉项目问题)
我希望编写一个用记录填充Map的函数.但我无法让它发挥作用.
let似乎创造的,而不是局部变量
处理smap作为一个全球性的.
必须有一些方法来做到这一点.
我的代码:
import Data.Map (Map)
import qualified Data.Map as Map
smap = Map.fromList [("cocoa",23)]
newdata str n = do
let cpy = Map.insert str n smap
cpy
main = do
let smap = newdata "pennywise" 16
let smap = newdata "krusty" 18
Run Code Online (Sandbox Code Playgroud)
从评论更新:稍后我想计算一个直角三角形等于周长的方式.因此我认为Map是存储分布计数的好方法,例如p10 - > 5种方式,p15 - > 6种方式等.因此,当程序运行时,它会增加已发现的周长值.
这个问题是我提出的上一个问题的后续问题.我收到的答案表明我使用了Go math.Big库.在这个问题中,我使用了库,但不幸的是效果不大.
我正在尝试使用Binet公式来计算fib(100).我正在使用Go的Big.Float但没有成功.我精确到小数点后10位.请指教.
我试图避免循环/递归,因为我认为这些方法不能很好地扩展.因此,我试图利用比奈的公式
//当前输入增加时会产生不准确的结果.
package main
import (
"fmt"
"math/big"
"math"
"strconv"
)
func fib(n int) float64 {
var sroot5 = new(big.Float).SetPrec(200).SetFloat64(2.236067977499789696409173668731276235440618359611525724270897)
var phi = new(big.Float).SetPrec(200).SetFloat64(1.61803398874989484820458683436563811772030917980576286213544862)
var minusPhi = new(big.Float).SetPrec(200).SetFloat64(-0.61803398874989484820458683436563811772030917980576)
var fltP float64;
fltP, _ = phi.Float64()
var fltN float64;
fltN, _ = minusPhi.Float64()
var denom float64
denom, _ = sroot5.Float64()
// Magic fib formula (Binet) is:
// (Phi ^ n - (-phi ^ n)) / sqrt(5)
z := (math.Pow(fltP, float64(n)) - math.Pow(fltN, …Run Code Online (Sandbox Code Playgroud) 我想编写一个函数,有效地告诉我,当列表中的项目是在一个范围内的所有项目可分与否.问题是,我不知道在遇到false时立即停止列表理解.
allDivisByRng n start stop =
[n `mod` x == 0 | x <- [start, start+1 .. stop]]
Run Code Online (Sandbox Code Playgroud)
我已经尝试过,takeWhile但却无法做到我想做的事情.请指教.
allDivisByRng n start stop =
takeWhile( == True ) [ n `mod` x == 0 | x <- [start, start+1.. stop] ]
Run Code Online (Sandbox Code Playgroud)
当我跑步时,allDivisByRng 10 2 4我得到了一份真实的名单
其他一些样本运行
*Main> allDivisByRng 12 2 10
[True,True,True]
*Main> allDivisByRng 12 2 150
[True,True,True]
-- I want this to return false
*Main> allDivisByRng 2520 2 10
[True,True,True,True,True,True,True,True,True]
-- I want this to …Run Code Online (Sandbox Code Playgroud) 我无法调用函数来编译.所有评论的呼叫都是失败的尝试.请指教,那里有Haskels型系统有什么好的解释吗?
import Data.Numbers.Primes
import Data.List
--isInt:: Fractional a => a -> Bool
isInt x =
x == fromInteger (round x)
doForm :: (Integral int, Fractional int) => int -> int -> Bool
doForm cube n =
isPrime (divide - n)
where divide = cube / (n^2)
main =
-- print $ doForm (12^3 8)
-- print $ doForm (12^3::Integer 8::Integer )
-- print $ doForm ( fromIntegral 12^3 fromIntegral 8)
-- print $ doForm (toInteger 12^3 toInteger 8)
-- print …Run Code Online (Sandbox Code Playgroud)