Last active
September 6, 2021 12:54
-
-
Save ochaochaocha3/ccab5c4e443865a2793f26bb9ae11a8a to your computer and use it in GitHub Desktop.
オークの問題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# https://twitter.com/MomiRaccoon/status/1434402973627531267 | |
# | |
# 女騎士「わ、私に性感度3000倍もさせて一体何をさせるんだ…」 | |
# オーク「ククク…」 | |
# | |
# オークA「感度を半分にするクスリだ」 | |
# オークB「感度を900マイナスにするクスリだ」 | |
# オークC「感度を2000プラスにするクスリだ」 | |
# オークD「感度を5倍するクスリだ」 | |
# オークE「感度を500プラスにするクスリだ」 | |
# | |
# 女騎士「はじめの感度の値が0であった場合、感度の値を3000にするためにオーク達はどんな順序でクスリを飲ませることになるんだ…!?」 | |
Orc = Struct.new(:name, :medicate) | |
orc_a = Orc.new('A', ->s { s / 2.0 }) | |
orc_b = Orc.new('B', ->s { s - 900 }) | |
orc_c = Orc.new('C', ->s { s + 2000 }) | |
orc_d = Orc.new('D', ->s { 5 * s }) | |
orc_e = Orc.new('E', ->s { s + 500 }) | |
orcs = [orc_a, orc_b, orc_c, orc_d, orc_e] | |
puts orcs | |
.permutation | |
.map { |os| | |
result = os.reduce(0) { |acc, o| o.medicate[acc] } | |
[os, result] | |
} | |
.filter { |_, result| result.to_f == 3000.0 } | |
.map { |os, _| os.map(&:name).join('->') } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
B->C->D->E->A | |
C->A->B->E->D | |
C->A->E->B->D | |
C->B->D->E->A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment