Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Code Golf Talk @ Ruby Sauna

Code Golf Talk @ Ruby Sauna

Lucas Dohmen

October 08, 2015
Tweet

More Decks by Lucas Dohmen

Other Decks in Programming

Transcript

  1. ☺ cat lucas.md # Lucas Dohmen * Consultant @ innoQ

    GmbH * From Cologne, Germany * Open Source Developer * Podcaster * CoderDojo Cologne Organizer * Code Golfer
  2. >> f = proc { |a,b| puts a } =>

    #<Proc:0x007fa918b3c7c0@(irb):1> >> f['hello'] hello => nil Calling a Proc
  3. >> f = proc { |a,b| puts a } =>

    #<Proc:0x007fa918b3c7c0@(irb):1> >> f['hello'] hello => nil Arguments that were not provided are initialised as nil (not the case for a lambda) Calling a Proc
  4. >> f = proc { |a,b| puts a } =>

    #<Proc:0x007fa918b3c7c0@(irb):1> >> f['hello'] hello => nil Arguments that were not provided are initialised as nil (not the case for a lambda) Calling a Proc
  5. On every call from now on we will do two

    things 1. Move the shark 2. Change the arms
  6. matches all stages ~o~ \o/ |o| of the animation Changing

    the arms .gsub(/.o./,y ? '\o/':'|o|')
  7. depending on y we change it to either \o/ or

    |o| Changing the arms .gsub(/.o./,y ? '\o/':'|o|')
  8. If you enter a line it will be stored as

    1. a string 2. a fixnum
  9. If the fixnum is 0 it is a todo item

    otherwise it is a check-off action
  10. There is no item 0, does not matter 'Clean the

    house'.to_i #=> 0 '12'.to_i #=> 12 '0'.to_i #=> 0
  11. todo_list = [] loop do input_as_string = gets input_as_int =

    input_as_string.to_i system "clear" if input_as_int > 0 todo_list.delete_at(input_as_int - 1) else todo_list << input_as_string end todo_list.each_with_index do |item, index| puts "#{index+1}: #{item}" end end
  12. Replace names & save whitespace 103 characters t=[] loop{i,j=(s=gets).to_i,0 system

    "clear" i>0?t.delete_at(i-1):t<<s t.map{|g|puts "#{j+=1}: #{g}"}}
  13. DRY

  14. DRY

  15. $_