[過去ログ]
プログラミングのお題スレ Part13 (1002レス)
プログラミングのお題スレ Part13 http://mevius.5ch.net/test/read.cgi/tech/1549160513/
上
下
前次
1-
新
通常表示
512バイト分割
レス栞
抽出解除
レス栞
このスレッドは過去ログ倉庫に格納されています。
次スレ検索
歴削→次スレ
栞削→次スレ
過去ログメニュー
723: デフォルトの名無しさん [] 2019/03/17(日) 06:18:59.33 ID:k04EM+xl 2桁までの足し算の筆算を表示せよ。 例: 29 +15 ---- 14 3 ---- 44 29 + 5 ---- 14 2 ---- 34 http://mevius.5ch.net/test/read.cgi/tech/1549160513/723
730: デフォルトの名無しさん [sage] 2019/03/17(日) 12:38:59.54 ID:TUY5K+QC >>723 Perl5 for (<DATA>) { ($l, $o, $r) = split; @l = $l =~ /(\d?)(\d)/; @r = $r =~ /(\d?)(\d)/; $a1 = $l[0] + $r[0]; $a0 = $l[1] + $r[1]; @a1 = $a1 =~ /(\d?)(\d)/; @a0 = $a0 =~ /(\d?)(\d)/; $a = 10*$a1 + $a0; $" = ''; print <<"EOF"; @l $o@r --- @a1 @a0 --- $a EOF } __DATA__ 29 + 15 29 + 5 http://mevius.5ch.net/test/read.cgi/tech/1549160513/730
733: デフォルトの名無しさん [] 2019/03/17(日) 13:19:09.72 ID:k04EM+xl >>723 掛け算に対応したり、1桁どうしの計算用フォーマット作ったりしてたら規模がでかくなった(・ω・`) 1 * 2 ----- 2 10 * 0 ----- 0 Haskell https://ideone.com/SCzGKq http://mevius.5ch.net/test/read.cgi/tech/1549160513/733
735: デフォルトの名無しさん [sage] 2019/03/17(日) 18:42:43.38 ID:7j/Zhhp5 >>723 ネタ回答: WolframAlpha API / node // index.js const {get} = require('http'); const appid = '<<YOUR WolframAlpha APP ID>>'; process.stdin.on('data', data => { get(`http://api.wolframalpha.com/v2/query?appid=${appid}&input=${encodeURIComponent(data.toString().trim())}&podstate=Result__Step-by-step+solution&format=image&output=json`, res => { res.setEncoding('utf8'); let body = ''; res.on('data', chunk => {body += chunk;}); res.on('end', () => { get(JSON.parse(body).queryresult.pods.filter(({title}) => title === 'Results')[0].subpods.filter(({title}) => title === 'Possible intermediate steps')[0].img.src, res => { res.on('data', data => {process.stdout.write(data)}); }); }); }); }); $ echo 29+15 | node . > ./test1.gif https://i.imgur.com/QxolfNz.gif $ echo 29+5 | node . > ./test2.gif https://i.imgur.com/D0r3sSg.gif $ echo 29*15 | node . > ./test3.gif https://i.imgur.com/imvQO5g.gif 試しに一桁×一桁やってみたらなんだか微妙な計算過程に… $ echo 5*5 | node . > ./test.gif https://i.imgur.com/8z3kZPf.gif あと割り算はAPIからでは計算過程のURL取れなかった http://mevius.5ch.net/test/read.cgi/tech/1549160513/735
743: デフォルトの名無しさん [] 2019/03/21(木) 03:20:09.08 ID:ZuEvTwkR >>723 Kotlin https://paiza.io/projects/IQdiv40t3eXnM8CEXzF2Og http://mevius.5ch.net/test/read.cgi/tech/1549160513/743
748: デフォルトの名無しさん [sage] 2019/03/21(木) 22:33:42.92 ID:4Lv8Ku6J >>723 Squeak Smalltalk | fn | fn := [:int1 :int2 | | strings width digits interms ans max line | strings := {int1. int2} collect: #asString. width := (strings detectMax: #size) size. digits := strings collect: [:str | (str forceTo: width paddingStartWith: $0) reversed asArray collect: #asString]. interms := (digits reduce: #+) collectWithIndex: [:interm :idx | interm, (String new: idx-1 withAll: Character space)]. ans := interms polynomialEval: '10'. strings atLast: 1 put: '+ ', strings last. max := ((strings, {ans}) collect: #size) max. line := String new: max withAll: $-. (strings, {line}, interms, {line. ans} collect: [:str | (str forceTo: max paddingStartWith: Character space) withoutTrailingBlanks ]) asStringWithCr ]. fn value: 987 value: 65. "=> ' 987 + 65 ---- 12 14 9 ---- 1052' " http://mevius.5ch.net/test/read.cgi/tech/1549160513/748
メモ帳
(0/65535文字)
上
下
前次
1-
新
書
関
写
板
覧
索
設
栞
歴
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.043s