Решение на Бонус задача: ArnoldC+- от Петър Скорчелиев

Обратно към всички решения

Към профила на Петър Скорчелиев

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 4 успешни тест(а)
  • 25 неуспешни тест(а)

Код

class Integer
def arnold_bool
self != 0
end
def arnold_or(other)
self.arnold_bool || other.arnold_bool
end
def arnold_and(other)
self.arnold_bool && other.arn
old_bool
end
end
module ArnoldCPM
class << self
attr_accessor :printer, :showtime, :mars_course
attr_accessor :functions, :variables, :names
attr_accessor :current_conditionals, :good_conditions, :bull_shit
def totally_recall
initialize_instance_variables
yield
end
def initialize_instance_variables
ArnoldCPM.names = []
ArnoldCPM.variables = {}
ArnoldCPM.functions = {}
ArnoldCPM.showtime = false
ArnoldCPM.mars_course = false
ArnoldCPM.current_conditionals = 0
ArnoldCPM.good_conditions = true
ArnoldCPM.bull_shit = false
end
end
operations = {
knock_knock: :arnold_and,
consider_that_a_divorce: :arnold_or,
get_up: :+,
get_down: :-,
youre_fired: :*,
he_had_to_split: :/,
i_let_him_go: :%,
let_off_some_steam_bennet: :>,
you_are_not_you_you_are_me: :==
}
operations.each do |arnold_name, ruby_name|
define_method (arnold_name) do |x|
if this_code_must_be_executed
ArnoldCPM.variables[current_name] = ArnoldCPM.variables[current_name].send(ruby_name, x)
# Tame Rubocop, please!
end
ArnoldCPM.variables[current_name]
end
end
def i_lied
0
end
def no_problemo
1
end
def its_showtime
ArnoldCPM.showtime = true
end
def you_have_been_terminated
ArnoldCPM.showtime = false
end
def talk_to_the_hand(object)
ArnoldCPM.printer.print(object) if this_code_must_be_executed
end
def current_name
ArnoldCPM.names.last
end
def this_code_must_be_executed
ArnoldCPM.showtime && ArnoldCPM.good_conditions
end
def because_im_going_to_say_please(condition)
if this_code_must_be_executed
ArnoldCPM.current_conditionals += 1
if condition.arnold_bool
ArnoldCPM.good_conditions = true
ArnoldCPM.bull_shit = false
else
ArnoldCPM.good_conditions = false
ArnoldCPM.bull_shit = true
end
end
end
def bull_shit
ArnoldCPM.good_conditions = ArnoldCPM.bull_shit if ArnoldCPM.showtime
end
def you_have_no_respect_for_logic
if ArnoldCPM.showtime
ArnoldCPM.current_conditionals -= 1
ArnoldCPM.good_conditions = true if ArnoldCPM.current_conditionals == 0
end
end
def get_to_the_chopper(name)
ArnoldCPM.names.push(name) if this_code_must_be_executed
end
def here_is_my_invitation(value)
ArnoldCPM.variables[current_name] = value if this_code_must_be_executed
end
def enough_talk
ArnoldCPM.names.pop if this_code_must_be_executed
end
end
class Object
include ArnoldCPM
end

Лог от изпълнението

..FFFFFFFFFFFFFFFFFFFFFFF..FF

Failures:

  1) ArnoldCPM can assign variables
     Failure/Error: get_to_the_chopper _the_answer
     NameError:
       undefined local variable or method `_the_answer' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe6d2130>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:35:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:33:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) ArnoldCPM can define and call functions with arguments
     Failure/Error: listen_to_me_very_carefully _printing_function
     NameError:
       undefined local variable or method `_printing_function' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe6c8428>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:476:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:475:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  3) ArnoldCPM can define and call functions with return value
     Failure/Error: listen_to_me_very_carefully _non_void_function
     NameError:
       undefined local variable or method `_non_void_function' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe6a8a38>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:500:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:499:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  4) ArnoldCPM returns 0 by default
     Failure/Error: listen_to_me_very_carefully _return_no_argument
     NameError:
       undefined local variable or method `_return_no_argument' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe685268>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:526:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:525:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  5) ArnoldCPM can take functions as arguments
     Failure/Error: listen_to_me_very_carefully _forty_two_printer
     NameError:
       undefined local variable or method `_forty_two_printer' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe656f30>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:557:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:556:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  6) ArnoldCPM can return functions
     Failure/Error: listen_to_me_very_carefully _function_generator
     NameError:
       undefined local variable or method `_function_generator' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe647d28>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:594:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:593:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  7) ArnoldCPM defines new inner functions for each function invocation
     Failure/Error: listen_to_me_very_carefully _define_function
     NameError:
       undefined local variable or method `_define_function' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe631b68>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:626:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:625:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  8) ArnoldCPM supports basic recursion
     Failure/Error: listen_to_me_very_carefully _count
     NameError:
       undefined local variable or method `_count' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe625f20>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:667:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:666:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  9) ArnoldCPM can calculate fibonacci(20) recursively
     Failure/Error: listen_to_me_very_carefully _fibonacci
     NameError:
       undefined local variable or method `_fibonacci' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe5ab1a8>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:715:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:714:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  10) ArnoldCPM can use closures in very convoluted ways
     Failure/Error: listen_to_me_very_carefully _null
     NameError:
       undefined local variable or method `_null' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f4ebe5974a0>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:766:in `block (3 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:765:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  11) ArnoldCPM has algebra that can sum numbers
     Failure/Error: get_to_the_chopper _sum
     NameError:
       undefined local variable or method `_sum' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f4ebe552cd8>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:52:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  12) ArnoldCPM has algebra that can subtract numbers
     Failure/Error: get_to_the_chopper _difference
     NameError:
       undefined local variable or method `_difference' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f4ebe539850>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:69:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:67:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  13) ArnoldCPM has algebra that can multiply numbers
     Failure/Error: get_to_the_chopper _product
     NameError:
       undefined local variable or method `_product' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f4ebe5205a8>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:86:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:84:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  14) ArnoldCPM has algebra that can divide numbers
     Failure/Error: get_to_the_chopper _quotient
     NameError:
       undefined local variable or method `_quotient' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f4ebe502120>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:103:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:101:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  15) ArnoldCPM has algebra that can calculate modulo
     Failure/Error: get_to_the_chopper _modulu
     NameError:
       undefined local variable or method `_modulu' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f4ebe4e3658>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:120:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:118:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  16) ArnoldCPM has algebra that can chain multiple operations
     Failure/Error: get_to_the_chopper _result
     NameError:
       undefined local variable or method `_result' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f4ebe4ddd98>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:138:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:136:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  17) ArnoldCPM has algebra that can use variables in calculations
     Failure/Error: get_to_the_chopper _x
     NameError:
       undefined local variable or method `_x' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f4ebe4b8278>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:163:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:161:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  18) ArnoldCPM has boolean arithmetic that given *or* returns truthy values if one of the operands is truthy
     Failure/Error: get_to_the_chopper _result
     NameError:
       undefined local variable or method `_result' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007f4ebe4a1208>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:194:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:192:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  19) ArnoldCPM has boolean arithmetic that given *or* returns falsy values if both operands are falsy
     Failure/Error: get_to_the_chopper _result
     NameError:
       undefined local variable or method `_result' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007f4ebe490a70>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:225:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:223:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  20) ArnoldCPM has boolean arithmetic that given *or* between two truthy values returns the first one
     Failure/Error: get_to_the_chopper _result
     NameError:
       undefined local variable or method `_result' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007f4ebe466450>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:242:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:240:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  21) ArnoldCPM has boolean arithmetic that given *and* returns falsy values if either operand is falsy
     Failure/Error: get_to_the_chopper _result
     NameError:
       undefined local variable or method `_result' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007f4ebe4580f8>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:263:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:261:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  22) ArnoldCPM has boolean arithmetic that given *and* between two truthy values returns the second one
     Failure/Error: get_to_the_chopper _result
     NameError:
       undefined local variable or method `_result' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007f4ebe426c60>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:294:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:292:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  23) ArnoldCPM has boolean arithmetic that has the same precedence of *or* and *and* operations
     Failure/Error: get_to_the_chopper _result
     NameError:
       undefined local variable or method `_result' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007f4ebe4110b8>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:311:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:309:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  24) ArnoldCPM has branching mechanism that can nest if-else statements
     Failure/Error: talk_to_the_hand 44
       (Double "printer").print(44)
           expected: 0 times with arguments: (44)
           received: 1 time with arguments: (44)
     # /tmp/d20170103-15620-2t6hyz/solution.rb:78:in `talk_to_the_hand'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:420:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:408:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  25) ArnoldCPM has branching mechanism that considers functions truthy
     Failure/Error: listen_to_me_very_carefully _function
     NameError:
       undefined local variable or method `_function' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3:0x007f4ebe367b80>
     # /tmp/d20170103-15620-2t6hyz/spec.rb:452:in `block (4 levels) in <top (required)>'
     # /tmp/d20170103-15620-2t6hyz/solution.rb:24:in `totally_recall'
     # /tmp/d20170103-15620-2t6hyz/spec.rb:451:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.02807 seconds
29 examples, 25 failures

Failed examples:

rspec /tmp/d20170103-15620-2t6hyz/spec.rb:28 # ArnoldCPM can assign variables
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:466 # ArnoldCPM can define and call functions with arguments
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:489 # ArnoldCPM can define and call functions with return value
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:517 # ArnoldCPM returns 0 by default
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:540 # ArnoldCPM can take functions as arguments
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:583 # ArnoldCPM can return functions
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:613 # ArnoldCPM defines new inner functions for each function invocation
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:651 # ArnoldCPM supports basic recursion
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:695 # ArnoldCPM can calculate fibonacci(20) recursively
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:760 # ArnoldCPM can use closures in very convoluted ways
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:45 # ArnoldCPM has algebra that can sum numbers
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:62 # ArnoldCPM has algebra that can subtract numbers
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:79 # ArnoldCPM has algebra that can multiply numbers
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:96 # ArnoldCPM has algebra that can divide numbers
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:113 # ArnoldCPM has algebra that can calculate modulo
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:130 # ArnoldCPM has algebra that can chain multiple operations
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:154 # ArnoldCPM has algebra that can use variables in calculations
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:183 # ArnoldCPM has boolean arithmetic that given *or* returns truthy values if one of the operands is truthy
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:218 # ArnoldCPM has boolean arithmetic that given *or* returns falsy values if both operands are falsy
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:235 # ArnoldCPM has boolean arithmetic that given *or* between two truthy values returns the first one
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:252 # ArnoldCPM has boolean arithmetic that given *and* returns falsy values if either operand is falsy
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:287 # ArnoldCPM has boolean arithmetic that given *and* between two truthy values returns the second one
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:304 # ArnoldCPM has boolean arithmetic that has the same precedence of *or* and *and* operations
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:378 # ArnoldCPM has branching mechanism that can nest if-else statements
rspec /tmp/d20170103-15620-2t6hyz/spec.rb:441 # ArnoldCPM has branching mechanism that considers functions truthy

История (1 версия и 1 коментар)

Петър обнови решението на 29.12.2016 18:30 (преди почти 8 години)

+class Integer
+ def arnold_bool
+ self != 0
+ end
+
+ def arnold_or(other)
+ self.arnold_bool || other.arnold_bool
+ end
+
+ def arnold_and(other)
+ self.arnold_bool && other.arn
+ old_bool
+ end
+end
+
+module ArnoldCPM
+ class << self
+ attr_accessor :printer, :showtime, :mars_course
+ attr_accessor :functions, :variables, :names
+ attr_accessor :current_conditionals, :good_conditions, :bull_shit
+
+ def totally_recall
+ initialize_instance_variables
+ yield
+ end
+
+ def initialize_instance_variables
+ ArnoldCPM.names = []
+ ArnoldCPM.variables = {}
+ ArnoldCPM.functions = {}
+ ArnoldCPM.showtime = false
+ ArnoldCPM.mars_course = false
+
+ ArnoldCPM.current_conditionals = 0
+ ArnoldCPM.good_conditions = true
+ ArnoldCPM.bull_shit = false
+ end
+ end
+
+ operations = {
+ knock_knock: :arnold_and,
+ consider_that_a_divorce: :arnold_or,
+ get_up: :+,
+ get_down: :-,
+ youre_fired: :*,
+ he_had_to_split: :/,
+ i_let_him_go: :%,
+ let_off_some_steam_bennet: :>,
+ you_are_not_you_you_are_me: :==
+ }
+ operations.each do |arnold_name, ruby_name|
+ define_method (arnold_name) do |x|
+ if this_code_must_be_executed
+ ArnoldCPM.variables[current_name] = ArnoldCPM.variables[current_name].send(ruby_name, x)
+ # Tame Rubocop, please!
+ end
+ ArnoldCPM.variables[current_name]
+ end
+ end
+
+ def i_lied
+ 0
+ end
+
+ def no_problemo
+ 1
+ end
+
+ def its_showtime
+ ArnoldCPM.showtime = true
+ end
+
+ def you_have_been_terminated
+ ArnoldCPM.showtime = false
+ end
+
+ def talk_to_the_hand(object)
+ ArnoldCPM.printer.print(object) if this_code_must_be_executed
+ end
+
+ def current_name
+ ArnoldCPM.names.last
+ end
+
+ def this_code_must_be_executed
+ ArnoldCPM.showtime && ArnoldCPM.good_conditions
+ end
+
+ def because_im_going_to_say_please(condition)
+ if this_code_must_be_executed
+ ArnoldCPM.current_conditionals += 1
+ if condition.arnold_bool
+ ArnoldCPM.good_conditions = true
+ ArnoldCPM.bull_shit = false
+ else
+ ArnoldCPM.good_conditions = false
+ ArnoldCPM.bull_shit = true
+ end
+ end
+ end
+
+ def bull_shit
+ ArnoldCPM.good_conditions = ArnoldCPM.bull_shit if ArnoldCPM.showtime
+ end
+
+ def you_have_no_respect_for_logic
+ if ArnoldCPM.showtime
+ ArnoldCPM.current_conditionals -= 1
+ ArnoldCPM.good_conditions = true if ArnoldCPM.current_conditionals == 0
+ end
+ end
+
+ def get_to_the_chopper(name)
+ ArnoldCPM.names.push(name) if this_code_must_be_executed
+ end
+
+ def here_is_my_invitation(value)
+ ArnoldCPM.variables[current_name] = value if this_code_must_be_executed
+ end
+
+ def enough_talk
+ ArnoldCPM.names.pop if this_code_must_be_executed
+ end
+end
+
+class Object
+ include ArnoldCPM
+end

mars_course xd

Странно е, че си решил да "преведеш" някои от ключовите думи, но си оставил други. Monkey patch-a в Object добавя доста хаос. ArnoldCPM не трябваше да пази друг контекст освен printer. Какво ще стане ако пусна две Arnold+- програми една след друга. Или още по-лошо - паралелно.

Щях да питам дали си си пуснал примерните тестове, но виждам, че си предал в последния момент. (:

Надявам се задачата да ти е била забавна и полезна. Може да погледнеш нашето решение ако ти е интересно как сме подходили към проблема.