« first day (704 days earlier)      last day (2551 days later) » 

12:01 AM
I decided to do it with math
 
Anonymous
12:41 AM
Class is dragging on -- that sandwich made me tired
 
Anonymous
1:30 AM
@Kitler that second db book, on theory, is RELATIONAL DATABASE DESIGN AND IMPLICATIONS 3e
 
1:56 AM
@meagar My favorite thing about enumerators as a general concept is that they are awesome to write unit tests for.
 
@WayneConrad How so?
 
They have an easily understood, narrow, well defined interface.
 
Yeah, I guess they are
 
expect(enum_to_a).to eq [...]
expect(enum.take(100).last).to eq ...
etc etc etc.
 
 
1 hour later…
3:20 AM
0
A: Using regex to replace parameters in a string

sawaYou should use string format %{}. request.user = "%{user} %{name}" request.password = "%{password}" parameters = {"user" => "first", "name" => "last", "password" => "secret"} request.each do |value| value.replace(value % parameters) end

What does this do, in this context?
 
 
7 hours later…
10:08 AM
@Cereal Ruby's % operator (an alias for String#sprintf) can take a hash. In irb, try: "%{foo} %{bar}" % {foo: 1, bar: "abc"}
I don't even know what to ask google when looking for day 15's algorithm.
 
10:34 AM
It's kind of like the coin change problem with coins of every possible value.
 
11:07 AM
For me, day 15 is much more complex than the previous AoC problems.
 
11:48 AM
this reddit comment is a big help. It's not a spoiler.
 
12:17 PM
Good morning
 
Good morning.
 
1:02 PM
Should I look at that reddit ocmment, or try it on my own first
I'll wing it
#yolo
 
Anonymous
Morning all. I get to enroll in a 401K today!
 
Nice thats always a smart move
 
Anonymous
I am going for the maximum % I can move into it per paycheck.
 
I do the same thing
 
1:23 PM
I think I did something wrong in my recipe calculations
 
1:40 PM
I'm about to run some code that I'm fairly sure is going to crash windows
Wish me luck
Good news: It didn't crash my computer.

Bad news: It maxed my ram, and my computer is trying to write all the combinations of [0..100]*3 to my harddrive
Other good news: It fixed my algo in the process
 
Has anyone written a web service in GO?
 
aww, I get the wrong answer :(
I've successfully changed my algorithm to give me the same wrong answer, in 10x the amount of time.
JUST KIDDING IT GAVE ME THE RIGHT ANSWER
 
Anonymous
1:57 PM
Day 6a is interesting. My original idea was a large hash of the coordinates. But now, I am thinking of using a class.
 
Anonymous
How do I replicate active record Light.where(x: y) in a non-AR class? -- (when I asked this last, I never really implemented it in whatever project I was on)
 
You'd set up a class variable to hold all instances of your class, and then a class method to select from that array
class Light
  @@lights
  def initialize
    @@lights << self
  end

  def self.where(opts)
    @@lights.find { }
  end
end
Or something
 
No!
Every time you think you want @@, you probably don't.
 
(that's how you'd do it in java :x)
I've angered the otter
 
Sorry, I shouldn't have yelled. Apologies.
 
Anonymous
2:05 PM
How would you guys do it then? I am about to post a Q on SO, because I think it is very interesting and would help others, too
 
#where is part of what is called an internal DSL. Google "Ruby internal DSL". There's also a name for the specific pattern that ARel is using with #where and its other methods. I never remember its specific name, but it's an instance of the general pattern known as "method chaining."
I remembered. google "fluent interface"
 
@WayneConrad What's inherently dangerous about class variables?
 
They are shared by all instances of the class and by instances of subclasses. A simple class instance variable is almost always sufficient, and simpler to reason about.
 
Anonymous
Feel free to edit or add tags (much appreciated)
 
Anonymous
0
Q: Find all instances of a class, given conditions, without ActiveRecord

Hunter StevensIn Rails/ActiveRecord, you can select instances of a model like so: User.where(state: 'New Jersey') However, ActiveRecord converts this to a comparable SQL query to run off the database. Right now, I am working with vanilla Ruby, without a database. Here is my class. class Light attr_acces...

 
2:15 PM
Well I mean activerecord is just doing a database query
Also that question reads like a code request
You'd have to store all Light instances somewhere, you could use class variable for this purpose, I guess. — Marek Lipka 3 mins ago
\O/
 
any body dere?
 
@HunterStevens Don't be that fancy. Just have a class named "Lights," an instance of which keeps all of your instances of Light. Let it do your search.
 
my server i created in my pc is not showing up on the internet. any idea why?
 
Anonymous
@WayneConrad wouldn't that be the same as a @@ variable?
 
Anonymous
Should I delete my question? :-(
 
2:20 PM
I think I know what he means
 
86
A: Difference between class variables and class instance variables?

Wayne ConradA class variable (@@) is shared among the class and all of its descendants. A class instance variable (@) is not shared by the class's descendants. Class variable (@@) Let's have a class Foo with a class variable @@i, and accessors for reading and writing @@i: class Foo @@i = 1 def se...

 
Anonymous
Okay, let me delete this Question.
 
Huh
Upvote for you
 
@HunterStevens Closed as dup; let me know if that doesn't answer your question
 
Anonymous
@meagar yes, it is a duplicate. Thank you
 
2:22 PM
Thought, stackoverflow.com/questions/14318079/… is a better answer
See that one, with its use of ObjectSpace. Basically does exactly what you're after without all the @@instances stuff
ObjectSpace.each_object(Project)
 
Anonymous
The question you duped, @meagar did not show in the suggested list when I made mine
 
The suggested lists suuuuuuck
I never use them when finding duplicates; I always google
 
Anonymous
Okay. Can mine just be deleted then?
 
In this case, google.ca/…
Yeah, you're free to delete your Q
 
Done day 15. Way easier than @WayneConrad lead me to believe. Of course, i did brute force it, so.. >.>
 
Anonymous
2:28 PM
For whatever reason, I cannot launch a screenshot app because memory cannot be allocated to it...
 
Anonymous
I guess it's timeto restart my computer!
 
@noelzubin No idea. You need to make sure that it's running, that it's bound to the interface and port you think it should be, and that your firewall is properly exposing that port on that box to the internet. If any one of these things is wrong, the server won't be visible to the internet.
 
@noelzubin Make sure it's running on ip 0.0.0.0 too, if you're just using a ruby application server
 
Anonymous
3:23 PM
Still haven't restarted my computer. I have instead opted to updated packages... Over 725 packages to update/install/etc. This is taking a while
 
4:22 PM
A lot of people didn't do 12b
 
Anonymous
@Cereal I would say it is more surprising that a lot of people did not do 1b
 
4:57 PM
Those might represent early drop-outs. "Did one, wasn't my thing, no reason to do part b"
 
Yeah. Whereas people doing day 12 are more likely to be committed
yet still left part b alone
 
It took me three or four problems before I noticed there was a part B. If you don't click on the link that takes you back to the problem, you wouldn't notice. And nothing on the page with that link indicates that there will be a part b when you go back to the problem.
 
@WayneConrad had the same experience
I did a few of the later problems first, and then threw out my solution to part 1
 
I read the about before I started, which mentions having two parts
> Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme.
 
then went back to the beginning and did the first problem, only to realize there was a second part to all of them, and had to re-invent my later solutions :|
 
5:01 PM
Who reads the "about?" Oh yeah... @Cereal does :D
 
Anonymous
I read it too...
 
You documentation readers, you.
 
I just clicked all the buttons :(
 
Anonymous
Actually, I have to agree. The site was so fantastic, I wanted to click everything
 
Anonymous
@meagar I looked up ObjectSpace,and it said this in the docs:
 
Anonymous
5:08 PM
> Generally, you SHOULD NOT use this library if you do not know about the MRI implementation. Mainly, this library is for (memory) profiler developers and MRI developers who need to know about MRI memory usage.
 
What's your usecase for this, exactly?
 
Anonymous
Day 6a -- I am making a class Light with attr position and status. Then I want to count the # of light instances that have a status of 1
 
Stick them in an array and lights.select { |l| l.status == 1 }?
 
Anonymous
I want to use classes for this one. Should I go with your way, and a class var?
 
You can put classes in an array
I don't think instantiating a whole bunch of objects, then accessing them through class level methods is very intuitive
 
Anonymous
5:17 PM
ObjectSpace instantiates the class objects?
 
I don't know what object space is, but an object has to exist for you to retrieve it, no?
This isn't a database
It sounds like you're doing something like
1000.times { |i| Light.new(i) }

Light.where(given_var: 1)
 
Anonymous
I feel like making Light objects would be simplest, rather than holding a huge hash/array
 
@HunterStevens Huh
 
I don't understand
 
I've never used ObjectSpace; you're in unfamiliar territory
 
Anonymous
5:20 PM
@meagar I thought you linked me to it, sorry
 
I did, but my first exposure to it is the SO question I linked you to
But generally I'd say you're probably going about this backwards
If you want an array of data, you should just create an array of data
 
Anonymous
# @Cereal this is what I was going to do:
class Light ; end
'0,0'..'999,999'.each { |x| Light.new(x) }
 
Rather than relying on being able to query the interpreter for all instantiated objects of a certain type
 
I'm going to go ahead and say that's not a good idea
But someone can feel free to correct me
 
Anonymous
Why is it not a good idea? Too much data held in memory?
 
5:22 PM
You're holding the same amount of data in memory regardless
 
@HunterStevens Why not just do
 
But now it's floating around aimlessly
 
lights = (0..999_999).map { |x| Light.new(x) }
 
Why not just ^ that
 
Anonymous
# I guess the alternative is:
lights = { }
'0,0'..'999,999'.each { |x| lights[x] = 0 }
# run through instructions
# reassign lights[x] if needed
 
5:24 PM
Are you trying to make a grid of lights?
 
Anonymous
Using map is good. I guess I then do: lights.count { |x| x.status == 1 }
 
You're going to have to do (0..999).each { |x| (0..999).each { |y| ... }}, not 0,0..999,999
Yes, exactly
There is no reason to want to do Light.where(status: 1)
When you can just do lights.select { |l| l.status == 1 }
 
Anonymous
@meagar you can actually do my range, and it works fine for instantiating.
 
@HunterStevens It returns strings, in the form "1,1", is that really how you want to index your array?
I guess you can do a single-dimensional mapping of strings to objects instead of an actual dimensional array
 
Anonymous
@meagar that would be the key, and I would just could the number of objects where the value = 1
 
5:27 PM
I mean, in this case it doesn't matter much, but generally that's a bad idea
You're going to be maintaining a string->object hash with 1 million keys
 
Anonymous
How do you suggest I do it then?
 
instead of a doubley-nested array
The look-up time is going to be quite slow compared to just indexing an array
Generally, you'd make a two-dimensional array
In Ruby, if you want a 1000x1000 grid of 0's, you would use
grid = 1000.times.map { Array.new(1000, 0) }
Or, rather
grid = Array.new(1000) { Array.new(1000, 0) }
I had to think about that for a second :p
 
Anonymous
Is that better than: `'0,0'..'999,999'.map { |x| x.split ',' }
 
But once you've done that, you can just do grid[x][y]
It's better and also different
doing map/split still returns a completely different data structure
 
Anonymous
What does Array.new(1000) do? I have not seen that before. (Also with the second param)
 
5:31 PM
Array.new(10) returns an array with 10 items in it
irb(main):006:0> Array.new(10)
=> [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
By default, they're nil
If you give it a second argument, that becomes the default
 
Anonymous
If the array is 1 dimensional, then how can I call grid[x][y] ?
 
If you give it a block instead of a second argument, the block is evaluated for each one
My suggestion wasn't one-dimensional; I gave the outer array a block that returned another array
So, Array.new(10) { Array.new(10, 'x') }
 
Anonymous
Oh, I see now. I was looking at your first one (before "or rather")
 
Returns a 10x10 grid of 'x'
 
Anonymous
Thanks, @meagar. I will work on day6 today :-) I still need 5b. But am unsure how to do it in 1 program (a and B together)
 
5:34 PM
Do you have to do it in one program?
 
Anonymous
No, but I'd like to for github. Easier to follow?
 
Anonymous
Especially with some of the early days, where part b is a small change, small enough to make a new method or something
 
In this case, part B is basically a different question
> None of the old rules apply, as they are all clearly ridiculous.
 
Anonymous
Okay.. Didn't think of it like that
 
I agree, in previous questions, the output from part 1 was usually the input for part 2
But in this case, part 1 and part 2 have no overlap
 
Anonymous
5:35 PM
What I was talking about was how @basement was the only addition for 1b to work: github.com/onebree/adventofcode/blob/master/day01/day01.rb
 
Anonymous
 
I did it in one file, but there's 2 different methods there
Why do I read the file twice.
._.
 
He refuses to believe that [ksh93] is not a tag about 93 kenyan shillings
Aaand I'm in the wrong room :|
 
I'm glad you posted that
I'm enjoying it
 
Anonymous
I wish I could star in mobile
 
Anonymous
5:50 PM
I'm sure everyone (besides @Cereal) will get a kick out of this: reddit.com/r/linux/comments/3wwzyj/…
 
6:01 PM
@meagar If you give Array.new a second argument, it becomes the value, not the default. I know you know this; I'm just feeling pedantic. It matters when the second argument is mutable.
 
Sooooo
Array.new(10, [])[0] << 1 => [[1],[1],[1],[1],[1],[1],[1],[1],[1],[1]]?
 
Pretty much. Only pretty much because the value returned by Arrayt#<< is the element inserted, not the array itself.
That's why you use the second form that meagar mentioned (with a block) when you want each element to be a separate reference.
Should I change my nickname to "pendantic man?"
 
@WayneConrad You know what I meant >:(
 
I knew what Meagar meant, too. I'm not afraid of the blue ones. :D
 
I googled pedantic otter, and got this: twitter.com/pedanticotter
Maybe nsfw?
 
Anonymous
6:07 PM
Probably. Trash that
 
@WayneConrad Yeah, sorry, that is an important distinction
In the case of a Hash, giving the hash a default really is a default.
 
Anonymous
HELLLOO FROM THE OTTER SLIDEEEE https://t.co/6ZtBfvyyIt
 
> Hash.new(3)[0]
=> 3
An array has no default; the second argument is the value to use to fill the initial array
> Array.new(0,3)[0]
=> nil
 
 
1 hour later…
7:11 PM
The more I think about it, the more I think I was being silly about the wording. Hash works the same as Array in regard to initial/default values, but I can't think of a word other than "default" that makes any sense there.
2.2.2 :004 > h = Hash.new([])
 => {}
2.2.2 :005 > h[:foo] << 1
 => [1]
2.2.2 :006 > h[:bar]
 => [1]
2
 
The difference is that a "default" is the default value when accessing elements that don't exist
 
I think it's just gotta be one of those things you learn about Ruby data structures--not something that can be imparted by just picking a different name for the arguments.
@meagar Well, that's true.
 
For an array, you're not setting the default, you're specifying the initial values to fill the array with
With a hash, you can specify a default, and it's still an empty hash. With Array.new(x,y), you're explicitly filling the array with x copies of y
 
OK, that makes sense.
 
The trick is that "x copies of y" behaves surprisingly for new Rubyists
When y is a reference to an object, you're getting x copies of that reference, not x by-value copies of the object
 
7:19 PM
Yeah. When people ask "is Ruby pass by value or pass by reference," I think the correct answer is "Ruby is pass reference by value."
 
The javascript room is dumb
 
Ruby is pass by value
 
@meagar And now you've confused me
 
The caveat is in how objects held in variables work
variables hold references to objects
 
That's a confusing way to define it to someone who knows C++. In C++, if you pass an object by value, it gets copied.
 
7:25 PM
It is confusing if you're coming from C++, much less so if you're coming from a language with no pointers
Most dynamic languages (AFAIK) behave the same way
Variables are always pass-by-value. The "value" just happens to be a pointer to some data
 
That's inherently confusing
 
It's the exact same way that JavaScript behaves
And PHP
 
If the value is the pointer, then calling it pass by value is obfuscating the actual behaviour, isn't it?
 
I understand it, and how it works
But saying it's pass by value is misleading
 
7:31 PM
It's... the truth though
 
I know, I just don't like it
 
Regardless of what data is in a variable, you're passing around references to that object
 
If you said it was pass by value to someone with no low level knowledge at all, they'd probably get very confused
 
can't you just say pass by reference?
 
It's not though
Look, this is pass-by-reference, and this is nothing like how Ruby behaves:
 
Anonymous
7:37 PM
This is my 6a so far... I am not sure what to do next. I want to do a range of array indexes, but am unable to do it.
 
#include <iostream>

void incr(int& x) {
  x++;
}


int main() {
  int i = 0;

  incr(i);

  std::cout << i; // i is now 1!

  return 0;
}
 
@HunterStevens I actually didn't use the vanilla input files for any of my solutions
For that one, for example, I downloaded the input file, and then in Vim I ran a bunch of substitutions on it manually
Basically, I turned this...
toggle 461,550 through 564,900
turn off 370,39 through 425,839
turn off 464,858 through 833,915
into
 
Anonymous
Isn't part of the challenge to parse the input?
 
inputs = [2, 461, 550, 564, 900],
  [0, 370, 39, 425, 839],
  [0, 464, 858, 833, 915],
Then pasted that into irb :p
 
7:46 PM
Parsing the input is trivial
Wayne just regexes it
I just split the string
 
Anonymous
I regex it too, with groups!
 
This is why I was talking about how weird it is to have access to the inputs
In a regular programming contest, yes, you would have to be able to parse the input
But with AOC you can just dump it into a text editor and transform the input into code
 
Anonymous
I guess.
 
I've never actually done a programming contest that gives you inputs and wants an answer in the form of output, rather than wanting the answer in the form of an algorithm for producing output
It's actually kind of nice, it lets you be super lazy :p
 
Probably because it's not a contest
 
Anonymous
 
@Cereal "programming challenge" then
 
Anonymous
I need something easier for change_display... Am I able to use zip or something? I do not like the nested do/end statements
 
I think it is nice, though in some cases when your input doesn't cover the same edge cases as someone else's it feels odd
 
Anonymous
@CuddleBunny can you give me an example? What edge case does it not cover?
 
in yesterday's puzzle that happened to @Cereal and I. His answer to the puzzle was correct but not to the sample because his input didn't require catching the edge case to get the right output.
 
7:52 PM
Mm, I never fixed that
 
8:06 PM
@HunterStevens Looks clean to me.
 
Anonymous
Thank you, Wayne. I am... for lack of a better word, self-concious of my code because I see this as a great way to practice best-practices in Ruby...
 
Anonymous
Yay! A little debugging and I got the answer!
 
@HunterStevens I think you have a fine eye for beauty in code. Given enough practice in any language, you'd write nice code.
 
Anonymous
@WayneConrad Thank you, Wayne. Is there anything that tells you that? I think Ruby in general is beautiful, so it is hard for me to think mine is especially so.
 
I like excessive white space personally
 
Anonymous
8:15 PM
Hmmm I am starting to think I should split the days up by parts -- 6 is doing the same thing, where part b is different enough from part a
 
Anonymous
@CuddleBunny Did mine have that? What do you define as excessive?
 
Beautiful code is code that has nothing ugly in it. Your methods are short and do one thing, your style is close enough to "standard" Ruby style that it never hurts to read, your variable and method names are descriptive... etc, etc.
 
I think yours has a healthy amount of white space, I put random new lines just because I feel like it
 
I do not like vertical whitespace within a method: If some lines of code belong together enough that they deserve to be delimited by vertical whitespace, then they probably deserve to be extracted into another method.
 
Anonymous
@CuddleBunny You also use hard tabs, instead of spaces :P
 
8:17 PM
I do, it is ugly on Github
 
I have one minor comment, regarding your earlier ask for ways to un-nest change_display
 
I like being able to jump the whole tab width with arrow keys
 
Your loop is doing a lot, you can split it up into two parts and un-indent it one level this way:
 
Anonymous
@WayneConrad That is a very good guideline. I will keep that in mind. I know for Rails that can be tricky, mainly in controllers when you want to keep the action within its respective method.
 
Anonymous
@CuddleBunny In your editor, you would have to configure the TAB key to produce 2 spaces, rather than a \t character.
 
Anonymous
8:19 PM
@meagar I appreciate the suggestion. That is the only part of my code I am unhappy with.
 
Actually, I'm wrong, this doesn't unindent anything :p
def change_display(input)
  instructions = input.each_line.map do |line|
    parse_instructions(line)
  end

  instructions.each do |instruction|
    (instructions[:start][0]..instructions[:finish][0]).each do |x|
      (instructions[:start][1]..instructions[:finish][1]).each do |y|
        @lights[x][y] = perform_action(@lights[x][y], instructions[:action])
      end
    end
  end
end
You could argue that it makes things clearer
 
I think I made that a yield
 
You could make it a little less verbose by changing the way in which instructions are passed around
 
instructions(input).each do |instruction|
 
Anonymous
Maybe? Not enough though. I want to simplify/better the nested do stuff
 
8:21 PM
@HunterStevens yeah, I like \t and I like 4 space indents. Though I actually have my RubyMine set up to use \t but to make it only 2 spaces wide.
 
def do_something(start_coord, end_coord)
  nested
    loops
      yield(grid[x][y])
    end
  end
end
or something
 
Anonymous
@WayneConrad That woould mean I need to edit the parse_instructions method, which returns a hash
 
I'd have to go look
 
Hard tabs are the invention of the dark lords of the underworld. Well, they weren't, because we didn't have much memory or disk space. But now that we do, they are wicked.
 
Anonymous
@CuddleBunny Because that is the ruby standard -- 2 spaces (as a soft tab)
 
8:22 PM
def parse_instructions(input)
  input.scan(/([a-z ]+) (\d+),(\d+) through (\d+),(\d+)/).flatten.map { |x| x[/\d/] ? x.to_i : x }
end

def change_display(input)
  instructions = input.each_line.map do |line|
    parse_instructions(line)
  end

  instructions.each do |action, x1, y1, x2, y2|
    (x1..x2).each do |x|
      (y1..y2).each do |y|
        @lights[x][y] = perform_action(@lights[x][y], action)
      end
    end
  end
end
 
Yeah, I changed my evil hard tabs to two-space width to match the scaffold code...
 
Anonymous
@meagar having 5 objects instead of 1 is much better. I think I will implement that. To me, though, calling the instruction and parsing inside input.each_line just makes more sense, organizational-wise
 
@HunterStevens It's just a separation of concerns thing
Regarding your earlier comment, you can't zip the two ranges together, but you can use product
you shouldn't though :p
(x1..x2).to_a.product((y1..y2).to_a).each do |x,y|
  @lights[x][y] = perform_action(@lights[x][y], action)
end
 
hmm RubyMine has a new icon now and it is weird...
 
Anonymous
8:38 PM
@meagar why should I not perform a zip?
 
8:57 PM
@HunterStevens zip won't give you the results you're after
> (1..5).zip('a'..'e')
=> [[1, "a"], [2, "b"], [3, "c"], [4, "d"], [5, "e"]]
You want the product, ie [1,a], [1,b], [1,c],...
The problem is that product doesn't work on enumerable, it works on arrays
So you have to convert your ranges into full arrays, and then turn the result into a full array, which is very expensive (comparatively) in terms of both CPU and memory.
(0..100).each { (0..100).each { } } takes up no memory and requires no initialization, it just loops
((0..100).to_a).product((0..100).to_a).each { |x,y| } must first produce an array of 100 items, then produce another array of 100 items, and then finally produce an array of 10,000 items, before it can even start looping
 
Anonymous
That makes sense.
 
Anonymous
# Is there any way to shorten:
input.scan(/([a-z ]+) (\d+),(\d+) through (\d+),(\d+)/).flatten.map { |x| x[/\d/] ? x.to_i : x }
 
Anonymous
This is the first or second time I am using groups in regex, so IDK if that part, especially, can be shorter
 
It's pretty close to ideal
The only thing I'd say is that, because you know the inputs are valid, you don't need to be so explicit in your matches
 
Anonymous
That's what I mean, how can I shorten it since the input will never be incorrect?
 
9:08 PM
You could just use /(.+) (.+),(.+) through (.+),(.+)/
 
Anonymous
Hmmm interesting, but it does not provide enough meaning, IMO (dots mean anything)
 
Yeah
As I said though; you know the inputs are valid. You don't need to match digits or letters, you only need to tokenize the string
 
Anonymous
What about the flatten/map part?
 
Anonymous
What does "tokenize the string" mean?
 
Text segmentation is the process of dividing written text into meaningful units, such as words, sentences, or topics. The term applies both to mental processes used by humans when reading text, and to artificial processes implemented in computers, which are the subject of natural language processing. The problem is non-trivial, because while some written languages have explicit word boundary markers, such as the word spaces of written English and the distinctive initial, medial and final letter shapes of Arabic, such signals are sometimes ambiguous and not present in all written languages. Compare...
 
Anonymous
9:15 PM
I just feel like that entire line is too long... I initially thought of dong (a) start_with? checks, (b) \d checks. But that means the same line will be parsed in two separate operations.
 
Does what you're doing need to be optimized?
 
Anonymous
If anything, just to have fewer characters on that line.
 
If you're optimizing first for readability/clarity, then you're on the right track.
 
wI have a few really long lines in my day16 thing
 
Anonymous
That LOC is what I want to accomplish, just unsure if I can make it shorter, without sacrificing meaning (dots)
 
9:20 PM
Dunno how I feel about long onelines
 
@HunterStevens You could skip the regex entirely and use:
[input[6]] + inputs.scan(/\d+/).map(&:to_i)
That gives you an array where the first item is either " " for toggle, "n" for "on" or "f" for "off"`, and then the next 4 items are x1,y1,x2,y2
 
Anonymous
In the words of Codewars, that is very "clever"
 
> inputs = ["toggle 461,550 through 564,900", "turn off 370,39 through 425,839", "turn on 464,858 through 833,915"]
=> ["toggle 461,550 through 564,900", "turn off 370,39 through 425,839", "turn on 464,858 through 833,915"]
> inputs.map { |i| [i[6]] + i.scan(/\d+/).map(&:to_i) }
=> [[" ", 461, 550, 564, 900], ["f", 370, 39, 425, 839], ["n", 464, 858, 833, 915]]
 
Anonymous
Then I would change the case statement to ' ' / 'f' / 'n' ?
 
Anonymous
Is it possible to split 1 commit into 2 commits, still on the same day as the original?
 
9:32 PM
@meagar Yay for the scan. Boo for the clever input[6] trick, which I like (who can resist the cuteness of clever?) but would be ashamed to use.
 
Anonymous
Is it also possible to customize the date/time of a commit in git? Mainly, I want to pull the commit history from my gists into ONE repo... But am not sure how.
 
@WayneConrad I'd actually be fine with it
In this case, there is no need to validate the input
It is guaranteed to be well-formed and uniform
The only goal is to turn it into usable chunks of data
 
True. I don't dislike it because it doesn't validate. I dislike it because trickery obscures the programmer's intent.
 
I would probably go a step further and use
instructions = { ' ' => 2, 'n' => 1, 'f' => 0 }
 
The where clauses in the case statement are no longer obvious.
 
9:35 PM
> inputs.map { |i| [instructions[i[6]]] + i.scan(/\d+/).map(&:to_i) }
 
All that to avoid a regex match on the line?
 
@WayneConrad No, to prep the data for use
actually, wait, @HunterStevens Are you done step one?
 
:27561523 git repos are pretty much separate. There is some way to pull multiple git projects together as sub-projects of a sort... I forget what it's called.
 
Anonymous
Nodules, modules, something
 
"sub-modules"
 
Anonymous
9:37 PM
@meagar never mind about my questions... I will just commit them in loads when I get home.
 
Yeah, that. I don't know if they do what @HunterStevens wants.
 
Anonymous
( I was looking to do something like git pull some_gist_hash master, but nvm)
 
@HunterStevens I mean, are you done AoC day 6 step 1;
 
Anonymous
Yes, I am done with AOC 6a. Which made me realize why I should have 2 programs (1 per part) per day
 
I didn't want to spoiler anything
But @WayneConrad You need to turn the on/off/toggle into numeric 1/-1/2 anyways
 
Anonymous
9:41 PM
I know how to work it. I am going to do methods increase, decrease, super_increase
 
In the second half, the instructions become "turn on" -> add 1, "turn off" -> subtract 1, "toggle" => add 2
 
@meagar Oh, OK. I turned them into lambdas
Which is probably too clever by half.
 
10:02 PM
@WayneConrad Woh man
I think I'm the only person here for whom the challenge is solving the problems quickly and with the laziest possible method :p
 
10:25 PM
@meagar That's awesome, though.
 

« first day (704 days earlier)      last day (2551 days later) »