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;
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
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)); }
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"] 0851デフォルトの名無しさん2020/11/01(日) 01:29:12.30ID:17LNcGyj>>825 Kotlin https://paiza.io/projects/pLXGwy1V_3FlM4eqH2w5tg0852デフォルトの名無しさん2020/11/01(日) 01:49:31.61ID:17LNcGyj>>825 C https://paiza.io/projects/hjm6unXa-mcUi6cx1mTJ9g08538382020/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
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単位でそれぞれ求めよ
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