プログラミングのお題スレです。
【出題と回答例】
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/
探検
プログラミングのお題スレ Part18
レス数が900を超えています。1000を超えると表示できなくなるよ。
2020/07/14(火) 13:53:46.47ID:jW5p6F/e
>>787
双方向リストの方が、後々いろいろ流用できてありがたいんですけど、それでも端方向リストでインプリしないといけないのですか?
双方向リストの方が、後々いろいろ流用できてありがたいんですけど、それでも端方向リストでインプリしないといけないのですか?
804デフォルトの名無しさん
2020/10/29(木) 19:02:59.18ID:c1P6mcgH 持て余すくらいなら「なるべく使わない」とか評価基準を示すだけにしとけばいいのに
805デフォルトの名無しさん
2020/10/29(木) 19:32:46.09ID:EQ9lcE/o >>793
全く同じこと思ってたわw
全く同じこと思ってたわw
806デフォルトの名無しさん
2020/10/29(木) 19:34:40.84ID:EQ9lcE/o >>797
どうでもいいけどお前のIDもjsだsな
どうでもいいけどお前のIDもjsだsな
807デフォルトの名無しさん
2020/10/29(木) 19:40:10.12ID:Pf0NRL7D808デフォルトの名無しさん
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
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
809デフォルトの名無しさん
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
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
810デフォルトの名無しさん
2020/10/29(木) 21:13:39.21ID:wtq/xrTf うわ
console.log('JSON: ' + JSON.stringify({'test': list})) //=> JSON: {"test":[2,7,0]}
だった
console.log('JSON: ' + JSON.stringify({'test': list})) //=> JSON: {"test":[2,7,0]}
だった
811デフォルトの名無しさん
2020/10/29(木) 23:09:01.60ID:MaNQDMIt813デフォルトの名無しさん
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
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
814デフォルトの名無しさん
2020/10/29(木) 23:26:08.36ID:GFOWX4AY815デフォルトの名無しさん
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"
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"
816253
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
公式マニュアルに書かれている通り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
818253
2020/10/30(金) 00:22:38.86ID:hMjmzAXb819253
2020/10/30(金) 00:32:51.98ID:hMjmzAXb820253
2020/10/30(金) 00:34:30.90ID:hMjmzAXb821デフォルトの名無しさん
2020/10/30(金) 00:50:28.84ID:9RgBA+ge822デフォルトの名無しさん
2020/10/30(金) 02:22:50.19ID:9RgBA+ge823デフォルトの名無しさん
2020/10/30(金) 07:07:30.18ID:cChJ6BWU >>812
あ?
あ?
824デフォルトの名無しさん
2020/10/30(金) 23:30:40.86ID:hYhF3+Ov Brainfuck読めないわ
覚えようかな
覚えようかな
825デフォルトの名無しさん
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
与えられた文字列を一文字ずつ見ていき"trick"と"treat"の5文字でどちらが先に揃うか判定してください(順序込み)
どちらもヒットしないときは考慮しなくていいです
treakOrTreat("trick or treat")
// => trick
treakOrTreat(". tr ick")
// => trick
treakOrTreat("ttrriecatk")
// => treat
treakOrTreat("tri kc eat")
// => treat
treakOrTreat("my money")
// => none
826デフォルトの名無しさん
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"
}
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"
}
827デフォルトの名無しさん
2020/10/31(土) 14:54:50.69ID:HHhQTZ6R 関数名のミススペリングは修正していいですか
828デフォルトの名無しさん
2020/10/31(土) 15:02:04.99ID:QnYm1bfS ごっつtypoしてたすまんFIXME
829デフォルトの名無しさん
2020/10/31(土) 15:07:31.21ID:DmLmDhBA830デフォルトの名無しさん
2020/10/31(土) 15:33:31.91ID:I05R+wBh 相変わらずキモいなあ、いつもの勝手に認定キッズ
ミュートにしてるという情報から相手が雑魚であるというぶっ飛んだ推論をする知性の欠片も持ち合わせない負け組
ミュートにしてるという情報から相手が雑魚であるというぶっ飛んだ推論をする知性の欠片も持ち合わせない負け組
831デフォルトの名無しさん
2020/10/31(土) 15:36:09.16ID:DmLmDhBA832デフォルトの名無しさん
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)
}
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)
}
833デフォルトの名無しさん
2020/10/31(土) 15:54:22.22ID:i0S/O8KX834デフォルトの名無しさん
2020/10/31(土) 16:42:52.45ID:B0ELcd4k835デフォルトの名無しさん
2020/10/31(土) 17:10:35.46ID:M62mfk9p836デフォルトの名無しさん
2020/10/31(土) 17:42:14.32ID:/zmNVLOW837デフォルトの名無しさん
2020/10/31(土) 21:33:28.24ID:g64iH70d838デフォルトの名無しさん
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 )
}
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 )
}
839デフォルトの名無しさん
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"]
改定
やはり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"]
840デフォルトの名無しさん
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;
}
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;
}
841253
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
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
842デフォルトの名無しさん
2020/10/31(土) 23:10:35.06ID:8FYB/kmH >>841
なんでお前ずっとコテハンつけてんの?
なんでお前ずっとコテハンつけてんの?
843253
2020/10/31(土) 23:20:38.29ID:i+h07tFB >>842 IPアドレスがたまに変わるのと自分のレスを見分けやすくするため。固定ではなく番号はたまに変えてる
気にしないで
気にしないで
844デフォルトの名無しさん
2020/10/31(土) 23:26:17.77ID:OVAIfmUR845デフォルトの名無しさん
2020/10/31(土) 23:27:34.12ID:wd4K8eMC >>843
専ブラ使えばいいのに
専ブラ使えばいいのに
846253
2020/10/31(土) 23:32:26.70ID:i+h07tFB848デフォルトの名無しさん
2020/10/31(土) 23:54:01.35ID:OVAIfmUR849デフォルトの名無しさん
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
次へ続く
Ruby
text = <<'TEXT'
trick or treat
. tr ick
ttrriecatk
tri kc eat
my money
TEXT
# 配列化
Trick = "trick".chars
Treat = "treat".chars
次へ続く
850849
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"]
の続き
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"]
851デフォルトの名無しさん
2020/11/01(日) 01:29:12.30ID:17LNcGyj852デフォルトの名無しさん
2020/11/01(日) 01:49:31.61ID:17LNcGyj853838
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 )
}
正規表現を捨てて 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 )
}
854蟻人間 ◆T6xkBnTXz7B0
2020/11/01(日) 14:40:36.23ID:wOVD56Lv お題:大阪都構想が実現すると、現在の大阪市は消滅すると予想される。都構想実現前の住所を実現後の住所に変換しなさい。
855デフォルトの名無しさん
2020/11/01(日) 16:05:05.76ID:+nQAPqAx 次行ってみよう
856蟻人間 ◆T6xkBnTXz7B0
2020/11/01(日) 16:41:27.74ID:wOVD56Lv857蟻人間 ◆T6xkBnTXz7B0
2020/11/01(日) 16:44:49.88ID:wOVD56Lv858デフォルトの名無しさん
2020/11/01(日) 16:51:14.83ID:VQGUeFT5 お前らは競技プログラミングとかやってる?
859253
2020/11/01(日) 16:54:48.84ID:I8lyxV1q >>858
やろうとしたことはあるがまだ未経験
何か受験勉強みたいになっちゃってるコンテストには魅力を感じない
でも世界トップレベルは年間4000万くらい賞金稼ぐとい話をきいてそういうのにはちょっと惹かれる
やろうとしたことはあるがまだ未経験
何か受験勉強みたいになっちゃってるコンテストには魅力を感じない
でも世界トップレベルは年間4000万くらい賞金稼ぐとい話をきいてそういうのにはちょっと惹かれる
861デフォルトの名無しさん
2020/11/01(日) 17:18:29.18ID:EgIfcLXC バカにしてるのはおまえ
他所の住所変更地の状況知らんのか?50年前の住所でも年賀届くわ
数年〜十数年或いはそれ以上旧住所で配送可能。舐めすぎ
他所の住所変更地の状況知らんのか?50年前の住所でも年賀届くわ
数年〜十数年或いはそれ以上旧住所で配送可能。舐めすぎ
862デフォルトの名無しさん
2020/11/01(日) 17:31:11.77ID:+nQAPqAx863デフォルトの名無しさん
2020/11/01(日) 17:35:33.69ID:S9fsJ+JS データ引っ張ってくるだけじゃん
ただの知識問題は悪問
ただの知識問題は悪問
864デフォルトの名無しさん
2020/11/01(日) 18:32:31.31ID:erpRcPg0 やってみたが
競技系はプログラミングのスキル向上には役立たんよ
競技系はプログラミングのスキル向上には役立たんよ
865デフォルトの名無しさん
2020/11/01(日) 18:50:53.93ID:4+fLUvoM >>857
このサイト気持ち悪いな
このサイト気持ち悪いな
867デフォルトの名無しさん
2020/11/01(日) 19:57:24.03ID:wWMHVvTS >>866
消えろ
消えろ
869デフォルトの名無しさん
2020/11/02(月) 00:22:13.64ID:bEILeQs7870デフォルトの名無しさん
2020/11/02(月) 04:28:03.49ID:2/AbCXtL871デフォルトの名無しさん
2020/11/02(月) 04:45:05.89ID:BfD57ecO "trick"と"treat"を受理するオートマトンを作って
入力文字列から1文字ずつ与えて状態遷移(または待機)させていく
末尾まで先に受理されたほうを答えとする
みたいなことだけ考えた
入力文字列から1文字ずつ与えて状態遷移(または待機)させていく
末尾まで先に受理されたほうを答えとする
みたいなことだけ考えた
872デフォルトの名無しさん
2020/11/02(月) 04:48:28.19ID:BfD57ecO けど実装すると無駄にでかくなりそう
873デフォルトの名無しさん
2020/11/02(月) 10:04:22.80ID:/BOVDIIM オートマトンって言語でなんか表現できる構造ある?
874デフォルトの名無しさん
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パターン)
....
と正規表現だけで表現できてしまう
でしょ?
今回なら入力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パターン)
....
と正規表現だけで表現できてしまう
875蟻人間 ◆T6xkBnTXz7B0
2020/11/02(月) 12:23:25.05ID:iXWhExA8 お題:パラボラアンテナが理論上の焦点に電波を集めることを示しなさい。
パラボラアンテナの半径を100とし、原点を中心にx軸上に焦点が来るように配置する。x軸と平行に電波がアンテナに入ってきて、入射角と反射角が等しくなるように電波が反射する。
このとき、どの場所で反射しても、反射した電波を表す直線が理論上の焦点に十分近づくことを示せ。
パラボラアンテナの半径を100とし、原点を中心にx軸上に焦点が来るように配置する。x軸と平行に電波がアンテナに入ってきて、入射角と反射角が等しくなるように電波が反射する。
このとき、どの場所で反射しても、反射した電波を表す直線が理論上の焦点に十分近づくことを示せ。
876デフォルトの名無しさん
2020/11/02(月) 12:23:58.15ID:UfGVYnOo まじでセンスないな
877デフォルトの名無しさん
2020/11/02(月) 12:36:09.22ID:zo3ZJgwO パラボラアンテナの半径ってどこのことだよ
878デフォルトの名無しさん
2020/11/02(月) 13:43:55.18ID:gftnEWfN879デフォルトの名無しさん
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
@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
880デフォルトの名無しさん
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" ]
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" ]
881デフォルトの名無しさん
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");
}
#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");
}
882デフォルトの名無しさん
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
アスペクト比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
883869
2020/11/02(月) 20:41:57.79ID:PEXljxha884デフォルトの名無しさん
2020/11/02(月) 20:50:30.27ID:LqVECFSh885デフォルトの名無しさん
2020/11/02(月) 20:55:38.75ID:UfGVYnOo >>882
実用的じゃん
実用的じゃん
886デフォルトの名無しさん
2020/11/02(月) 21:39:44.31ID:PEXljxha887デフォルトの名無しさん
2020/11/02(月) 22:00:22.68ID:PEXljxha888デフォルトの名無しさん
2020/11/02(月) 22:02:25.78ID:i1cL0pVh >>875
消えろ
消えろ
889デフォルトの名無しさん
2020/11/02(月) 22:12:37.48ID:2/AbCXtL890デフォルトの名無しさん
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))
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))
891デフォルトの名無しさん
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) ]
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) ]
892デフォルトの名無しさん
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}
は同じやり方になるので二重カウントしないこと
{1,2,3,4,5,6,7,8}
を幾つかの共通部分を持たない空でない集合にわけるやり方を完全列挙
例えば
{1,6}+{2,8}+{3,4,5,7}
と
{2,8}+{1,6}+{3,4,5,7}
は同じやり方になるので二重カウントしないこと
893デフォルトの名無しさん
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
[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
894デフォルトの名無しさん
2020/11/03(火) 08:10:12.54ID:WKYb8LN0 >>893
きれいだな
きれいだな
895デフォルトの名無しさん
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}}
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}}
896デフォルトの名無しさん
2020/11/03(火) 09:10:16.73ID:psuX0FGw897デフォルトの名無しさん
2020/11/03(火) 09:15:47.91ID:psuX0FGw 間違ってたときのコード貼ってしまったw
~a+~b=A
とかは要らなかったw
a+b=A
とかだけでよかった
a \cup bが普通の和集合ね。
~a+~b=A
とかは要らなかったw
a+b=A
とかだけでよかった
a \cup bが普通の和集合ね。
898デフォルトの名無しさん
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%
:: 引数は整数限定。結果は少数第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%
899デフォルトの名無しさん
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
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
900デフォルトの名無しさん
2020/11/04(水) 00:20:22.20ID:kNuSoIVx windows知らんけど
バッチ・ファイルすげぇなww
バッチ・ファイルすげぇなww
901デフォルトの名無しさん
2020/11/04(水) 20:24:03.31ID:uO47xEs9902デフォルトの名無しさん
2020/11/05(木) 03:19:19.40ID:EuRO0zRP903デフォルトの名無しさん
2020/11/05(木) 20:02:28.58ID:pDv0veJc お題
'□'(正方形)と'_'(空白)で表される図形を45度回転して描画せよ。
[例1]
□
/\
\/
[例2]
___□
□□_□
_□□□
/\
\/\
/\/ /\
\/\/\/
\/\/
\/
'□'(正方形)と'_'(空白)で表される図形を45度回転して描画せよ。
[例1]
□
/\
\/
[例2]
___□
□□_□
_□□□
/\
\/\
/\/ /\
\/\/\/
\/\/
\/
レス数が900を超えています。1000を超えると表示できなくなるよ。
ニュース
- 【次の一手】台湾問題で小林よしのり氏が私見「まさに戦争前夜」「ただちに徴兵制を敷いて、高市支持者を最前線へ」… ★5 [BFU★]
- 【野球】大谷翔平、佐々木朗希、山本由伸らがWBC辞退なら広がる不協和音… 『過去イチ盛り上がらない大会』になる可能性も★2 [冬月記者★]
- 【国際】ロシアはすでに戦争準備段階――ポーランド軍トップが警告 [ぐれ★]
- 「町中華」の“息切れ倒産”が増加 ブームにも支えられ職人技で踏ん張ってきたが… 大手チェーンは値上げでも絶好調 [ぐれ★]
- 【news23】小川彩佳アナ「ここまでの広がりになるということを、高市総理はどれだけ想像できていたんでしょうね」 日中問題特集で [冬月記者★]
- 毛寧(もう・ねい)報道官「中国に日本の水産品の市場は無い」 高市首相の国会答弁に「中国民衆の強い怒り」 ★2 [ぐれ★]
- 【高市売り】円安、止まらず!凄い勢いで暴落中。157円へ [219241683]
- 俺「お湯を流してと…」シンク「ボンッw」
- 【悲報】ヤフコメ民「中国が水産物を輸入禁止にするなら、日本国民向けに安く販売すればいい。中国依存から脱するべき」 [153736977]
- ヤフコメ「中国への輸出がなくなる事で、日本国内で美味しくいただける事に感謝します」👈やたら政権寄りなのはなぜ?(´・ω・`) [399259198]
- もう寝ます
- 1,000万円のBMWに擦ってしまった札幌のガキ、捕らえられてガチで詰む [329329848]
