-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Randomize conditionals #201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
みました
|
||
conditional2-calc = (x) -> | ||
if x is 5 | ||
then 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
インデントすればthenは不要なのでそうしてください
@@ -51,6 +54,16 @@ sum-of-digits = (n) -> n.to-string!split '' .map (parse-int _, 10) .reduce (+) | |||
fibonacci-calc = (n, value = 1, prev = 0) -> | |||
if n is 0 then prev else fibonacci-calc n - 1, value + prev, value | |||
|
|||
conditional1-calc = (x) -> | |||
if (x % 2) is 0 then 2 * x else 3 * x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
括弧いらない気がする
(LiveScriptではなるべく括弧を殺していきたい)
expect io .to.satisfy io-spec | ||
|
||
expect zip io.input, io.output .to.all.satisfy ([input, output]) -> | ||
output is conditional1-calc input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputが200未満になる旨のテストもあったほうがよさそう
output: [10, 18, null, null], | ||
ioGenerator: (random) => { | ||
const generateAnswer = (input) => { | ||
if (input === 5) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputが5か6のテストケースはすでに(固定で)あるので、5か6がランダムに生成されても嘘解法が通りやすくなるだけな気がするけど、どうだろう⋯⋯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これ、めんどくさくてやってなかっただけなので、普通にやります
各種、終わりました。レビューお願いします |
} | ||
return number + offset; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
うーん、やりたいことは何となくわかるけど、ちょっと複雑になりすぎな感じがある。ここまで一般的なアルゴリズムを書かなくても、今回の場合は1から200までの数値を含む配列から5と6を除いたものから2個乱択する処理を書けば十分だと思う。
こんな感じ。
const candidates = Array.from({length: 200}, (item, index) => index + 1).filter(n => n !== 5 && n !== 6);
const input1 = candidates[Math.floor(random() * candidates.length)];
const input2 = candidates[Math.floor(random() * candidates.length)];
あと、5や6が生まれなくなるのでgenerateAnswer
関数もいらないと思う。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> 2個乱択する処理を書けば十分
わかりました・・・
> 5や6が生まれなくなるのでgenerateAnswer関数
たしかにそうですね・・・
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OKです! お疲れさま! 引き続きデプロイお願いします。
マージします |
通りました。レビューお願いします