2020-09-01から1ヶ月間の記事一覧
haskellはlet .. in もしくはwhereによって変数の宣言ができる。 入れ子も可能。 BMI weight height = let heightSquare = height * height in weight * heightSquare BMI weight height = weight * heightSquare where heightSquare = height * height
半分列挙という概念を学んだ2 ^ 20 = 1048576通り試す必要があったとする。 それを2 ^ 10 = 1024 に分けることによって処理数が大幅に減る。例えば後半が二分探索でわかるなら 1024 * 10 = 10240通りですますことができる。 10240 1048576100倍ぐらいの差が…
昨日・真夜中 tkinterのインストールと簡単なプログラムの作成をした。 詰まった点 ・_tkinterというモジュールが見つからないというエラーが発生。 解決法 tcl-tkをインストール(されていたので最新に) PATHの設定 sourceもしくはターミナル の再起動で設…
data = [] File.open("q_10.txt") do |f| f.readlines.each do |row| data << row.split(',')[1].to_i end end N = 289 left = 1 right = data.max center = (left + right) / 2 loop do sum = 0 data.each do |i| sum += (i.to_f / center).ceil end if sum…
Qtの勉強をc++で使ってみようとしていたが今の自分には色々とややこしかったので、他の簡単なGUIを使える言語で作ろうと思った。 RustのGultinや、Pythonのtkinter、pyqtなどは以前に触ったことがあるがもっと簡単に使えたはずだ。 そもそもなぜわざわざQtを…
def combination(a, b) factorial(a) / (factorial(b) * factorial(a-b)) end def factorial(n) ret = 1 (2..n).each do |i| ret *= i end ret end comb1 = [] N = 50 (2..N - 2).each do |i| comb1 << combination(14, i) end ans = 0 (2..N - 2).each do |…
今は、アルゴリズム、データ構造、数学、設計、言語の仕様などのぱっとできることが好きでやっている。 しかしそれだけだとあまり良くない。 面倒なことは避けてしまう癖がある。 なので面倒なことを選んで1日1時間でいいから必ず続けるようにしようと思う。…
use std::fs::File; use std::io::prelude::*; fn main() -> std::io::Result<()> { let mut file = File::create("foo.txt"); file.write_all(b"Hello, world")?; OK(()) }
import System.IO main = do fileName <- getLine let content = readFile fileName putStrLn content [1 of 1] Compiling Main ( main.hs, main.o ) main.hs:6:14: error: • Couldn't match type ‘IO String’ with ‘[Char]’ Expected type: String Actual t…
fn main() { use std::io; let mut input = String::new(); io::stdin().read_line(&mut input); input.pop(); let mut n: i32 = input.parse().unwrap(); let mut res = 1; loop { res *= n; n -= 1; if n == 0 { break; } } println!("{}! = {}", input, r…
--echo.hs main = do input <- getLine putStrLn(input)stack ghc echo.hs ./echo hello >>hello
#include <stdio.h> int main(int argc, char *argv[]) { for (int i = 0; i < argc; i++) { printf("%s\n", argv[i]); } return 0; } gcc -o main main.c ./main hello world ! >>hello >>world >>!</stdio.h>