プログラミングのお題スレ Part18
■ このスレッドは過去ログ倉庫に格納されています
0001デフォルトの名無しさん
垢版 |
2020/07/14(火) 13:53:46.47ID:jW5p6F/e
プログラミングのお題スレです。

【出題と回答例】
1 名前:デフォルトの名無しさん
  お題:お題本文

2 名前:デフォルトの名無しさん
  >>1 使用言語
  回答本文
  結果がある場合はそれも

【ソースコードが長くなったら】 (オンラインでコードを実行できる)
https://ideone.com/
http://codepad.org/
http://compileonline.com/
http://rextester.com/runcode
https://runnable.com/
https://code.hackerearth.com/
http://melpon.org/wandbox
https://paiza.io/

宿題は宿題スレがあるのでそちらへ。

※前スレ
プログラミングのお題スレ Part17
https://mevius.5ch.net/test/read.cgi/tech/1584031367/
0801デフォルトの名無しさん
垢版 |
2020/10/29(木) 15:09:10.20ID:dNWGwdex
Haskellみたいな純粋関数だとそもそも標準ライブラリだけだと“状態”を作るのも難しいんだよな
同じ表現は永遠に同じ答えを返すからスタックの“状態”を変化させるというのがそもそもできない
それをなんとかするのに“モナド”というのがあるんだけど状態を処理する“ステートモナド”は標準ライブラリではないんだよな
ほとんど“準標準”だけど
0802デフォルトの名無しさん
垢版 |
2020/10/29(木) 16:24:06.73ID:95aSRVZj
State モナドを“準標準”と認めてもらえるなら簡単
Haskell

import Control.Monad.State

pop :: State [a] a
pop = do
a <- get
modify tail
return $ head a

push :: a -> State [a] ()
push x = do
modify ((x :))
return ()

test = do
push 1
push 2
push 3
a <- pop
b <- pop
c <- pop
return ([a,b,c])

main = print $ evalState test []
---
出力
[3,2,1]
0803◆QZaw55cn4c
垢版 |
2020/10/29(木) 19:01:42.56ID:7aED6VYA
>>787
双方向リストの方が、後々いろいろ流用できてありがたいんですけど、それでも端方向リストでインプリしないといけないのですか?
0804デフォルトの名無しさん
垢版 |
2020/10/29(木) 19:02:59.18ID:c1P6mcgH
持て余すくらいなら「なるべく使わない」とか評価基準を示すだけにしとけばいいのに
0808デフォルトの名無しさん
垢版 |
2020/10/29(木) 20:59:03.61ID:zgfLAX1f
>>787
push,popってリストじゃなくてスタックの機能じゃ?
リストにさせるなら、先頭に追加してく方が速くて楽なのに。
push xs a = a:xs
pop (x:xs) = (xs,x)
反転させたいなら最後の最後にすべきだよ。

Haskell

― 使用例用main関数
main = do pushlist <- (return.push (Cons 1 (Cons 2 Null))) 3
(poplst, popval) <- (return.pop) pushlist
print pushlist
print popval
print poplst

― ここからお題のコード(整数に限定じゃないとダメならdataのList a/Cons aのaをIntに)
data List a = Null | Cons a (List a) deriving (Show)

push xs a = xs +++ (Cons a Null)

pop xs = (myinit xs, mylast xs)

Null +++ ys = ys
(Cons x xs) +++ ys = Cons x (xs +++ ys)

myinit (Cons x Null) = Null
myinit (Cons x xs) = Cons x (myinit xs)

mylast (Cons x Null) = x
mylast (Cons _ xs) = mylast xs
0809デフォルトの名無しさん
垢版 |
2020/10/29(木) 21:10:47.05ID:wtq/xrTf
>>787 JavaScript
class List {
#data = []
push(n) {
this.#data = [n, this.#data]
return this
}
pop() {
const [head, tail] = this.#data
if (tail) this.#data = tail;
return head
}
toArray() { return this.#data.flat(Infinity) }
toString() { return String(this.toArray()) }
toJSON() { return this.toArray() }
}

const list = new List
list
.push(0)
.push(7)
.push(2)
console.log('文字列: ' + list) //=> 文字列: 2,7,0
console.log('JSON: ' + JSON.stringify(list))
//=> JSON: {"test":[2,7,0]}
list.pop() //=> 2
list.pop() //=> 7
list.pop() //=> 0
list.pop() //=> undefined
0811デフォルトの名無しさん
垢版 |
2020/10/29(木) 23:09:01.60ID:MaNQDMIt
>>803
お題
双方向リストをC89で実装してください
0813デフォルトの名無しさん
垢版 |
2020/10/29(木) 23:24:39.19ID:3o7XtB23
>>787 ocaml
https://ideone.com/8ceFxk
type 'a _list = Nil | Cons of 'a * 'a _list
exception EmptyListException
let push xs x = Cons(x, xs)
let pop = function Nil -> raise EmptyListException | Cons (x, c) -> (x, c)
let rec each f = function Nil -> () | Cons (x, xs) -> f x; each f xs
let x, xs = pop (push (push (push Nil 1) 2) 3)
let () = print_int x; each print_int xs
0815デフォルトの名無しさん
垢版 |
2020/10/30(金) 00:06:20.24ID:aDtUVDPI
>>802を改良?
State [Int] だとあらかじめ用意した一個のstackしか使えない
噂に聞いたことあつたST monadで複数のスタック使えるように改造
Haskell

import Control.Monad
import Control.Monad.ST
import Data.STRef

data Stack a = Empty | N { car :: a, cdr :: Stack a } deriving (Show)

push stk val = modifySTRef stk (N val)
pop stk = car <$> readSTRef stk <* modifySTRef stk cdr

main = print $ runST $ do
sA <- newSTRef Empty
sB <- newSTRef Empty
push sA 'o' >> push sA 'o' >>push sA 'f'
push sB 'r' >> push sB 'a' >> push sB 'b'
a1<-pop sA
a2<-pop sA
a3<-pop sA
b1<-pop sB
b2<-pop sB
b3<-pop sB
return [a1,a2,a2,b1,b2,b3]
----
出力
"foobar"
0816253
垢版 |
2020/10/30(金) 00:07:47.66ID:hMjmzAXb
>>787 Perl5

公式マニュアルに書かれている通りsplice関数を使ってpush, popを記述できる。
 splice(@a,@a,0,$x); # push(@a, $x)
 splice(@a,-1);    # pop(@a)
なんだけどspliceを使わず言語のstatementだけでpush, pop関数を記述すると…こんな感じ

use v5.18;
use feature 'signatures';
no warnings "experimental::signatures";
sub Push($a, $x) {
 @$a = (@$a, $x);
}
sub Pop($a) {
 my @a = @$a;
 my $b = $a[-1];
 @$a = @a[0..$#a-1];
 $b;
}
my @s = (1,2,3); # test main
Push(\@s, 4);
say "@s";
my $y = Pop(\@s);
say $y;


実行結果
~ $ perl 18_787_push_pop.pl
1 2 3 4
4
1 2 3
0817253
垢版 |
2020/10/30(金) 00:09:56.81ID:hMjmzAXb
>>816
say $y;
の下に書いてあった最後の行
say "@s";
をコピペしそびれた…orz
0818253
垢版 |
2020/10/30(金) 00:22:38.86ID:hMjmzAXb
>>816 Pop関数はこっちの方がいいな、無駄なコピーもないし。

sub Pop($a) {
 my $b = @$a[-1];
 delete @$a[-1];
 $b;
}
0819253
垢版 |
2020/10/30(金) 00:32:51.98ID:hMjmzAXb
>>818 deleteは削除したスカラー値を返すわ。だから以下でいいんだ

sub Pop($a) {
 my $b = @$a[-1];
 delete @$a[-1];
}
0820253
垢版 |
2020/10/30(金) 00:34:30.90ID:hMjmzAXb
>>819 my $b = @$a[-1]; 不要だった…orz

sub Pop($a) {
 delete @$a[-1];
}
0825デフォルトの名無しさん
垢版 |
2020/10/31(土) 13:49:55.42ID:QnYm1bfS
お題
与えられた文字列を一文字ずつ見ていき"trick"と"treat"の5文字でどちらが先に揃うか判定してください(順序込み)
どちらもヒットしないときは考慮しなくていいです

treakOrTreat("trick or treat")
// => trick
treakOrTreat(". tr ick")
// => trick
treakOrTreat("ttrriecatk")
// => treat
treakOrTreat("tri kc eat")
// => treat
treakOrTreat("my money")
// => none
0826デフォルトの名無しさん
垢版 |
2020/10/31(土) 13:51:26.24ID:QnYm1bfS
>>825 js(self)
function treakOrTreat(text) {
const [tri] = /t.*r.*i.*c.*k/.exec(text) || []
const [tre] = /t.*r.*e.*a.*t/.exec(text) || []
if (!tri && !tre) return 'none'
if (!tri) return 'treat'
if (!tre) return 'trick'
return tri.length < tre.length ? "trick" : "treat"
}
0830デフォルトの名無しさん
垢版 |
2020/10/31(土) 15:33:31.91ID:I05R+wBh
相変わらずキモいなあ、いつもの勝手に認定キッズ
ミュートにしてるという情報から相手が雑魚であるというぶっ飛んだ推論をする知性の欠片も持ち合わせない負け組
0831デフォルトの名無しさん
垢版 |
2020/10/31(土) 15:36:09.16ID:DmLmDhBA
>>825 Common Lisp
https://ideone.com/qHuipq

>>829は無駄な条件判定(二つめの (null a))があったので修正
0832デフォルトの名無しさん
垢版 |
2020/10/31(土) 15:44:11.18ID:pGrSKCPz
>>825 JavaScript
function trickOrTreat(str = '') {
const trick = [...'trick']
const treat = [...'treat']
let result = 'none'
for (const c of str) {
if (c === trick[0]) trick.shift()
if (c === treat[0]) treat.shift()
if (!trick.length || !treat.length) {
result = trick.length ? 'treat' : 'trick'
break;
}
}
console.log(result)
}
0838デフォルトの名無しさん
垢版 |
2020/10/31(土) 21:58:58.47ID:t2sIU1o6
>>825 Ruby
def trickOrTreat( str )
trick = str.match( /\A.*?t.*?r.*?i.*?c.*?k/ )
treat = str.match( /\A.*?t.*?r.*?e.*?a.*?t/ )
return 'none' unless trick or treat
return 'trick' unless treat
return 'treat' unless trick
return (trick[0].size < treat[0].size)? 'trick' : 'treat'
end

[ "trick or treat", ". tr ick", "ttrriecatk", "tri kc eat", "my money",
"treat or trick", "treat or trick t",
].each{|s|
puts trickOrTreat( s )
}
0839デフォルトの名無しさん
垢版 |
2020/10/31(土) 22:19:45.63ID:B0ELcd4k
>>834
改定
やはりHaskellerがこのお題でparsec使わないのはダメという事で

Haskell

import Text.ParserCombinators.Parsec

makeP cs = foldl1 (<>) $ map (\c -> (many $ noneOf [c]) <> (return <$> anyChar) ) cs :: Parser String

first xs ys = case (runParser (makeP xs) () "" ys) of
Left _ -> (1, 0)
Right x -> (0, length x)

trickOrTreat x = case compare (first "trick" x) (first "treat" x) of
LT -> "trick"
GT -> "treat"
otherwise -> "Happy Halloween"

main = do
mapM_ (print.trickOrTreat) ["trick or treat", ". tr ick","ttrriecatk","tri kc eat","my money"]
0840デフォルトの名無しさん
垢版 |
2020/10/31(土) 22:49:38.34ID:pe+8/Oyn
>>825
C

#include<stdio.h>

char* trickOrTreat(char*s, char*tk, char*tt){
if(!*tk)return "trick";
if(!*tt)return "treat";
if(!*s) return "none";

if(*s == *tk)tk++;
if(*s == *tt)tt++;

return trickOrTreat(s+1, tk, tt);
}

int main(void){
char* str[] = {"trick or treat", ". tr ick", "ttrriecatk", "tri kc eat", "my money",
"treat or trick", "treat or trick t",};
const int size = sizeof(str)/sizeof(str[0]);

char tk[] = "trick";
char tt[] = "treat";

int i;
for(i=0; i<size; i++){
printf("%s\n", trickOrTreat(str[i], tk, tt));
}

return 0;
}
0841253
垢版 |
2020/10/31(土) 22:58:55.98ID:i+h07tFB
>>825 Perl5

for (<DATA>) {
 chomp;
 %h = map{$_ => [split'']} qw{trick treat};
 $k = 'none';
 for $c (split'') {
  for (keys %h) {
   $r = $h{$_};
   shift(@$r) if $c eq $$r[0];
   unless (@$r) { $k = $_; goto L }
  }
 }
L: print "$_ -> $k\n";
}
__DATA__
trick or treat
. tr ick
ttrriecatk
tri kc eat
my money

実行結果
~ $ perl 18_825_trickOrTreat.pl
trick or treat -> trick
. tr ick -> trick
ttrriecatk -> treat
tri kc eat -> treat
my money -> none
0843253
垢版 |
2020/10/31(土) 23:20:38.29ID:i+h07tFB
>>842 IPアドレスがたまに変わるのと自分のレスを見分けやすくするため。固定ではなく番号はたまに変えてる
気にしないで
0846253
垢版 |
2020/10/31(土) 23:32:26.70ID:i+h07tFB
>>845
IPアドレスが変わったり日にちがたった自分のレスを簡単に表示し分けられる専ブラで良いのある?
出来ればLinuxで。ちなStyleは好みではない
0847253
垢版 |
2020/10/31(土) 23:38:27.89ID:i+h07tFB
>>844
教科書に載っているようなきれいなコード書くね
0848デフォルトの名無しさん
垢版 |
2020/10/31(土) 23:54:01.35ID:OVAIfmUR
>>847
サンクスコ

でも、引数の評価順については正直お行儀悪いんで
勉強してるみんなはそのへん各自ぐぐってみてね
0849デフォルトの名無しさん
垢版 |
2020/11/01(日) 00:59:27.52ID:KABEK1ar
>>825
Ruby

text = <<'TEXT'
trick or treat
. tr ick
ttrriecatk
tri kc eat
my money
TEXT

# 配列化
Trick = "trick".chars
Treat = "treat".chars

次へ続く
0850849
垢版 |
2020/11/01(日) 01:00:32.73ID:KABEK1ar
>>849
の続き

def find_index( str, original )
idx_2 = 0

str.each_char.with_index do |char, idx| # 1文字ずつ処理する
idx_2 += 1 if char == original[ idx_2 ]
return idx if idx_2 == original.length # すべての文字が一致
end
nil
end

results = text.each_line.map do |line|
trick = find_index( line, Trick )
treat = find_index( line, Treat )

if !( trick || treat ) then "none"
elsif !trick then "treat"
elsif !treat then "trick"
elsif trick < treat then "trick"
elsif trick > treat then "treat"
else "same"
end
end

p results
#=> ["trick", "trick", "treat", "treat", "none"]
0853838
垢版 |
2020/11/01(日) 12:58:01.92ID:g/v4ZA9S
>>825 Ruby
正規表現を捨てて index+inject に
def trickOrTreat( str )
trick = 'trick'.chars.inject(-1){|r,ch| break r unless r = str.index( ch, r+1 ); r }
treat = 'treat'.chars.inject(-1){|r,ch| break r unless r = str.index( ch, r+1 ); r }
return 'none' unless trick or treat
return 'trick' unless treat
return 'treat' unless trick
return (trick < treat)? 'trick' : 'treat'
end

[ "trick or treat", ". tr ick", "ttrriecatk", "tri kc eat", "my money",
"treat or trick", "treat or trick t",
].each{|s|
puts trickOrTreat( s )
}
0854蟻人間 ◆T6xkBnTXz7B0
垢版 |
2020/11/01(日) 14:40:36.23ID:wOVD56Lv
お題:大阪都構想が実現すると、現在の大阪市は消滅すると予想される。都構想実現前の住所を実現後の住所に変換しなさい。
0859253
垢版 |
2020/11/01(日) 16:54:48.84ID:I8lyxV1q
>>858
やろうとしたことはあるがまだ未経験
何か受験勉強みたいになっちゃってるコンテストには魅力を感じない
でも世界トップレベルは年間4000万くらい賞金稼ぐとい話をきいてそういうのにはちょっと惹かれる
0861デフォルトの名無しさん
垢版 |
2020/11/01(日) 17:18:29.18ID:EgIfcLXC
バカにしてるのはおまえ
他所の住所変更地の状況知らんのか?50年前の住所でも年賀届くわ
数年〜十数年或いはそれ以上旧住所で配送可能。舐めすぎ
0862デフォルトの名無しさん
垢版 |
2020/11/01(日) 17:31:11.77ID:+nQAPqAx
>>860
ここでそのお題といても大混乱が回避できるわけでもなし
そういう問題じゃなくてそろそろ自分にいい問題作るセンスがない事自覚すべき
0871デフォルトの名無しさん
垢版 |
2020/11/02(月) 04:45:05.89ID:BfD57ecO
"trick"と"treat"を受理するオートマトンを作って
入力文字列から1文字ずつ与えて状態遷移(または待機)させていく
末尾まで先に受理されたほうを答えとする
みたいなことだけ考えた
0874デフォルトの名無しさん
垢版 |
2020/11/02(月) 10:41:03.91ID:5JhQS2vf
正規表現で表現できる⇔オートマトンで受理できる
でしょ?
今回なら入力xに対し出力がtrickである場合を

[^t]*t[^r]*r[^ie]*i[^ce]*c[^ke]*k.*
|[^t]*t[^r]*r[^ie]*i[^ce]*c[^ke]*e[^ka]*k.*
...
(10パターン)
....

と正規表現だけで表現できてしまう
0875蟻人間 ◆T6xkBnTXz7B0
垢版 |
2020/11/02(月) 12:23:25.05ID:iXWhExA8
お題:パラボラアンテナが理論上の焦点に電波を集めることを示しなさい。

パラボラアンテナの半径を100とし、原点を中心にx軸上に焦点が来るように配置する。x軸と平行に電波がアンテナに入ってきて、入射角と反射角が等しくなるように電波が反射する。
このとき、どの場所で反射しても、反射した電波を表す直線が理論上の焦点に十分近づくことを示せ。
0879デフォルトの名無しさん
垢版 |
2020/11/02(月) 14:26:45.62ID:vIueiXdU
>>825 .bat
@echo off &setlocal enabledelayedexpansion
if "%~1"=="" echo none&exit /b
set "STR=%~1"
set TRICK=trick
set TREAT=treat
set /a n=0, k=0, t=0
:WHILE
if /i "!STR:~%n%,1!"=="!TRICK:~%k%,1!" if %k% LSS 4 ( set /a k+=1 ) else echo trick&exit /b
if /i "!STR:~%n%,1!"=="!TREAT:~%t%,1!" if %t% LSS 4 ( set /a t+=1 ) else echo treat&exit /b
set /a n+=1
if not "!STR:~%n%,1!"=="" goto :WHILE
echo none&exit /b
0880デフォルトの名無しさん
垢版 |
2020/11/02(月) 18:10:30.68ID:Ac4tp6ZL
>>825
Haskell
https://ideone.com/wg9JbO

iimport Text.ParserCombinators.Parsec

makeP = mconcat . map ( manyTill anyChar . char )

lastInd x s = case ( runParser ( makeP x ) () "" s ) of
Left _ -> ( [ 2, 0 ] , x )
Right y -> ( [ 0, length $ x ++ y ], x )

trickOrTreat x = snd $ minimum [
lastInd "trick" x,
lastInd "treat" x,
( [1,0], "Happy Halloween" ) ]

main = mapM_ ( print . trickOrTreat ) [
"trick or treat",
". tr ick",
"ttrriecatk",
"tri kc eat",
"my money" ]
0881デフォルトの名無しさん
垢版 |
2020/11/02(月) 19:01:54.49ID:hORytTpS
>>825
#include <stdio.h>
#include <string.h>

static void
tot (char *p)
{
int i = 0, j = 0;
if ((p = strchr (p, 't')) && (p = strchr (p + 1, 'r')))
while (*++p && !(*p == "ick"[i] && ++i == 3) && !(*p == "eat"[j] && ++j == 3)) ;
printf ("%s\n", (i == 3) ? "trick" : ((j == 3) ? "treat" : "none"));
}

int
main ()
{
tot ("trick or treat");
tot (". tr ick");
tot ("ttrriecatk");
tot ("tri kc eat");
tot ("my money");
}
0882デフォルトの名無しさん
垢版 |
2020/11/02(月) 19:55:30.38ID:0Q72CsT7
お題
アスペクト比X:Y、L[inch]のディスプレイの
幅Wと高さHをcm単位でそれぞれ求めよ

[入力]
X Y L

[出力]
W H ※cm単位で小数第1位まで出力

[例]
16 9 40
=> 88.6 49.8

64 27 29
=> 67.9 28.6

3 4 10.2
=> 15.5 20.7
0890デフォルトの名無しさん
垢版 |
2020/11/02(月) 23:19:41.46ID:ZpVsHyOp
>>882 JavaScript
const f=(x, y, l) => [x, y].map(i => (i * 2.54 * l / Math.sqrt(x ** 2 + y ** 2)).toFixed(1))
console.log(...f(16, 9, 40))
console.log(...f(64, 27, 29))
console.log(...f(3, 4, 10.2))
0891デフォルトの名無しさん
垢版 |
2020/11/03(火) 00:18:12.81ID:1BjkDVvF
>>882

Hadkell

cmpin =2.54
r10 = (/10).fromInteger.round.(*10)
toWH (x, y, sz) = let
arg = atan2 y x
diag = sz * cmpin
in ( r10 $ (cos arg) * diag , r10 $ (sin arg) * diag )

main = mapM_ ( print . toWH) [
(16, 9, 40),
(64,27,29),
(3,4, 10.2) ]
0892デフォルトの名無しさん
垢版 |
2020/11/03(火) 01:33:31.56ID:psuX0FGw
お題
{1,2,3,4,5,6,7,8}
を幾つかの共通部分を持たない空でない集合にわけるやり方を完全列挙
例えば
{1,6}+{2,8}+{3,4,5,7}

{2,8}+{1,6}+{3,4,5,7}
は同じやり方になるので二重カウントしないこと
0893デフォルトの名無しさん
垢版 |
2020/11/03(火) 02:32:26.13ID:yN+x511c
>>892
[1..8]は流石にtoo large
haskell

import Data.List

parts [] = [ [ ] ]
parts [x] = [ [ [x] ] ]
parts ( x : xs ) = [ (x : ys) : zs |
ys <- subsequences xs,
zs <- parts $ xs \\ ys ]

main = do
print $ parts [2,3]
print $ parts [1,2,3]
print $ length $ parts [1..8]
----
[[[2],[3]],[[2,3]]]
[[[1],[2],[3]],[[1],[2,3]],[[1,2],[3]],[[1,3],[2]],[[1,2,3]]]
4140
0895デフォルトの名無しさん
垢版 |
2020/11/03(火) 09:07:39.02ID:psuX0FGw
A:={1,2,3,4,5,6,7,8};
A_1:={A};
A_2:={ {a,b} \subset 2^A | a+b=A,~a+~b=A };
A_3:={ {a,b,c} \subset 2^A | a+b+c=A,~a+~b+~c=A };
A_4:={ {a,b,c,d} \subset 2^A | a+b+c+d=A,~a+~b+~c+~d=A };
A_5:={ {a,b,c,d,e} \subset 2^A | a+b+c+d+e=A,~a+~b+~c+~d+~e=A };
A_6:={ {a,b,c,d,e,f} \subset 2^A | a+b+c+d+e+f=A,~a+~b+~c+~d+~e+~f=A };
A_7:={ {a,b,c,d,e,f,g} \subset 2^A | a+b+c+d+e+f+g=A,~a+~b+~c+~d+~e+~f+~g=A };
A_8:={ {a,b,c,d,e,f,g,h} \subset 2^A| a+b+c+d+e+f+g+h=A,~a+~b+~c+~d+~e+~f+~g+~h=A};
B:=A_1+A_2+A_3+A_4+A_5+A_6+A_7+A_8;
count[expand B];

1:{{1},{2},{3},{4},{5},{6},{7},{8}}
2:{{1},{2},{3},{4},{5},{6},{7,8}}
3:{{1},{2},{3},{4},{5},{7},{6,8}}
4:{{1},{2},{3},{4},{5},{8},{6,7}}
5:{{1},{2},{3},{4},{5},{6,7,8}}
6:{{1},{2},{3},{4},{6},{7},{5,8}}
7:{{1},{2},{3},{4},{6},{8},{5,7}}
8:{{1},{2},{3},{4},{6},{5,7,8}}
9:{{1},{2},{3},{4},{5,6},{7,8}}
10:{{1},{2},{3},{4},{7},{8},{5,6}}
11:{{1},{2},{3},{4},{7},{5,6,8}}
12:{{1},{2},{3},{4},{5,7},{6,8}}
...中略....
4135:{{2,7,8},{1,3,4,5,6}}
4136:{{3,7,8},{1,2,4,5,6}}
4137:{{4,7,8},{1,2,3,5,6}}
4138:{{5,7,8},{1,2,3,4,6}}
4139:{{6,7,8},{1,2,3,4,5}}
4140:{{1,2,3,4,5,6,7,8}}
0896デフォルトの名無しさん
垢版 |
2020/11/03(火) 09:10:16.73ID:psuX0FGw
美しさだけなら某集合論用処理系に勝る
ものはないと思うが....
>>891の短時間回答能力とHaskelの潜在能力は
驚嘆すべきかも
0897デフォルトの名無しさん
垢版 |
2020/11/03(火) 09:15:47.91ID:psuX0FGw
間違ってたときのコード貼ってしまったw
~a+~b=A
とかは要らなかったw
a+b=A
とかだけでよかった
a \cup bが普通の和集合ね。
0898デフォルトの名無しさん
垢版 |
2020/11/03(火) 21:04:35.96ID:eC8ouzxK
>>882 bat
:: 引数は整数限定。結果は少数第2位を四捨五入。0〜0.04の時のみ少数第2位まで表示
:: 少し大き目の値を与えるとoverflow
@echo off &setlocal enabledelayedexpansion
set /a "x=%1*100, y=%2*100, z=0, d=%3*254, s=x*x+y*y, a=s>>1"
:WHILE
if %a% NEQ %z% set /a "z=a, a=(a+s/a)>>1" &goto :WHILE
set /a w=x*d/a, h=y*d/a
for %%G in (w h) do (
if !%%G:~-1! GEQ 5 set /a %%G+=10
if !%%G! GEQ 100 ( set %%G=!%%G:~0,-2!.!%%G:~-2,1!
) else if !%%G! GEQ 10 ( set %%G=0.!%%G:~-2,1!
) else if !%%G! GEQ 1 ( set %%G=0.0!%%G!
) else if !%%G! EQU 0 ( set %%G=0.00
) else echo ERROR: %%G=!%%G!
)
echo=%w% %h%
0899デフォルトの名無しさん
垢版 |
2020/11/04(水) 00:20:20.72ID:rxWDSDf0
>>882 Lua
function f(x, y, l)
local a =2.54 * l / (x * x + y * y)^0.5
return x * a , y * a
end
print(string.format("%.1f , %.1f", f(16, 9, 40)))
実行結果
88.6 , 49.8
■ このスレッドは過去ログ倉庫に格納されています

ニューススポーツなんでも実況