Dominion Strategy Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 227 228 [229] 230  All

Author Topic: Random Stuff Part II  (Read 1217637 times)

0 Members and 3 Guests are viewing this topic.

silverspawn

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 5300
  • Shuffle iT Username: sty.silver
  • Respect: +3188
    • View Profile
Re: Random Stuff Part II
« Reply #5700 on: December 09, 2015, 05:38:18 pm »
0

woah

Tables

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2816
  • Build more Bridges in the King's Court!
  • Respect: +3347
    • View Profile
Re: Random Stuff Part II
« Reply #5701 on: December 09, 2015, 05:52:25 pm »
0

Factorials can be pretty fun.
9! seconds is a little more than 4 days.
11! seconds is over a year and 3 months.
16! seconds is about three times the current lifespan of humanity (homo sapiens)
Logged
...spin-offs are still better for all of the previously cited reasons.
But not strictly better, because the spinoff can have a different cost than the expansion.

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2219
    • View Profile
Re: Random Stuff Part II
« Reply #5702 on: December 10, 2015, 07:37:15 am »
+11

I asked someone how many seconds there were in six weeks. He correctly replied "There's 10!"

I liked that joke! I give it 4.9 out of 5!

Or maybe I didn't like it that much after all!
Logged
A man has no signature

sudgy

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3431
  • Shuffle iT Username: sudgy
  • It's pronounced "SOO-jee"
  • Respect: +2706
    • View Profile
Re: Random Stuff Part II
« Reply #5703 on: December 13, 2015, 12:02:12 am »
0

Have any of you ever found a good use for gotos?  I just had this type of thing happen in my code:

Code: [Select]
for loop {
    if condition {
        do stuff
        goto end
    }
}
other for loop {
    if other condition {
        do other stuff
        goto end
    }
}
another for loop {
    if another condition {
        do another stuff
        goto end
    }
}
end:
do some more stuff

I can't see a way to make this simpler and more readable without gotos...
Logged
If you're wondering what my avatar is, watch this.

Check out my logic puzzle blog!

   Quote from: sudgy on June 31, 2011, 11:47:46 pm

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2219
    • View Profile
Re: Random Stuff Part II
« Reply #5704 on: December 13, 2015, 01:19:36 am »
0

I suppose you could nest the loops, but I would definitely say that it's more readable with the gotos.
Logged
A man has no signature

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9411
    • View Profile
Re: Random Stuff Part II
« Reply #5705 on: December 13, 2015, 02:22:10 am »
0

Are the for loops related in any way?  This seems like the sort of thing that would usually be taken care of by break(n);
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

sudgy

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3431
  • Shuffle iT Username: sudgy
  • It's pronounced "SOO-jee"
  • Respect: +2706
    • View Profile
Re: Random Stuff Part II
« Reply #5706 on: December 13, 2015, 02:49:01 am »
0

Are the for loops related in any way?  This seems like the sort of thing that would usually be taken care of by break(n);

Not really, it's basically trying to do one thing, and if that fails, it does another, and if that fails, then another.
Logged
If you're wondering what my avatar is, watch this.

Check out my logic puzzle blog!

   Quote from: sudgy on June 31, 2011, 11:47:46 pm

eHalcyon

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 8689
  • Respect: +9187
    • View Profile
Re: Random Stuff Part II
« Reply #5707 on: December 13, 2015, 03:00:37 am »
0

Are the for loops related in any way?  This seems like the sort of thing that would usually be taken care of by break(n);

Not really, it's basically trying to do one thing, and if that fails, it does another, and if that fails, then another.

So, this?

loop 1
   if success
      break
end loop

if not success
   loop 2
      if success
         break
   end loop

if not success
   loop 3
      if success
         break
   end loop



Or it may be better to throw and catch errors.
Logged

qmech

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1918
  • Shuffle iT Username: qmech
  • What year is it?
  • Respect: +2320
    • View Profile
Re: Random Stuff Part II
« Reply #5708 on: December 13, 2015, 07:17:40 am »
0

Or it may be better to throw and catch errors.

Yes.  sudgy, this is a very common pattern, and people who think gotos are dangerous designed language features exactly for your situation.  If you're in a language without exceptions (which is what this feature is normally called) try looking up the standard work around.
Logged

Titandrake

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2210
  • Respect: +2854
    • View Profile
Re: Random Stuff Part II
« Reply #5709 on: December 13, 2015, 07:52:41 am »
+1

You could put everything from the first for loop to just before end into a separate function, then replace all the gotos with returns. Depends on what exactly you're doing though.
Logged
I have a blog! It's called Sorta Insightful. Check it out?

LastFootnote

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7495
  • Shuffle iT Username: LastFootnote
  • Respect: +10721
    • View Profile
Re: Random Stuff Part II
« Reply #5710 on: December 13, 2015, 09:26:50 am »
0

If you are in e.g. Java (and you don't consider a failure within the loops to be exception-worthy), then what you want it this:

Code: [Select]
label: {
    for loop {
        if condition {
            do stuff
            break label
        }
    }
    other for loop {
        if other condition {
            do other stuff
            break label
        }
    }
    another for loop {
        if another condition {
            do another stuff
            break label
        }
    }
}
do some more stuff

You don't have to have a while, for, if, etc. in order to throw up some brackets. You can just surround all the loops in one set of brackets, label that block of code, and then break out of the entire block by referencing the label.
Logged

pingpongsam

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1760
  • Shuffle iT Username: pingpongsam
  • Respect: +777
    • View Profile
Re: Random Stuff Part II
« Reply #5711 on: December 13, 2015, 09:36:08 am »
+1

I use goto in DOS batch files and the original BASIC language. The latter I have not touched in probably a decade or more. In the former I still write one or three a year. I write in several other languages and goto is something I would never even think of doing.
Logged
You are the brashest scum player on f.ds.

sudgy

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3431
  • Shuffle iT Username: sudgy
  • It's pronounced "SOO-jee"
  • Respect: +2706
    • View Profile
Re: Random Stuff Part II
« Reply #5712 on: December 13, 2015, 03:25:43 pm »
0

It's c++, so I can't use break label.

I've heard people saying that exceptions can be performance heavy (or something like that), and I usually only use exceptions for actual errors.  I think the if not success way is more confusing and less readable than gotos.

As I said, I can't find a simpler and more readable way to write it.  I already thought of most of these ways, but I think using goto in this case is just more readable (at least more than all of these options).
Logged
If you're wondering what my avatar is, watch this.

Check out my logic puzzle blog!

   Quote from: sudgy on June 31, 2011, 11:47:46 pm

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9411
    • View Profile
Re: Random Stuff Part II
« Reply #5713 on: December 13, 2015, 04:08:04 pm »
0

Hanabi becomes much, much harder when all the 1s in two suits are in the bottom half of the deck...

Edit:  Oh, and four of the 5s are in our hands already.  (Online game obviously)
« Last Edit: December 13, 2015, 04:16:55 pm by Kirian »
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

Witherweaver

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 6476
  • Shuffle iT Username: Witherweaver
  • Respect: +7861
    • View Profile
Re: Random Stuff Part II
« Reply #5714 on: December 13, 2015, 04:17:40 pm »
0

It's c++, so I can't use break label.

I've heard people saying that exceptions can be performance heavy (or something like that), and I usually only use exceptions for actual errors.  I think the if not success way is more confusing and less readable than gotos.

As I said, I can't find a simpler and more readable way to write it.  I already thought of most of these ways, but I think using goto in this case is just more readable (at least more than all of these options).

Are you sure the logic can't be switched?  You have to run each loop separately?
Logged

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2219
    • View Profile
Re: Random Stuff Part II
« Reply #5715 on: December 13, 2015, 09:14:12 pm »
0

Hanabi becomes much, much harder when all the 1s in two suits are in the bottom half of the deck...

Edit:  Oh, and four of the 5s are in our hands already.  (Online game obviously)

I've put aside my deck of cards and play with the tiles, so this comment confused me at first.

That scenario is exactly why I don't like the rules as written. It seems like you are really hoping that the last 1s and 2s are not at the bottom of the deck. I think even the last 3s could be problematic.

So I play where we go through all the cards/tiles based on one of the variants, but we don't declare the game over if we lock ourselves out.
Logged
A man has no signature

Donald X.

  • Dominion Designer
  • *****
  • Offline Offline
  • Posts: 6357
  • Respect: +25671
    • View Profile
Re: Random Stuff Part II
« Reply #5716 on: December 13, 2015, 11:51:50 pm »
0

It's c++, so I can't use break label.

I've heard people saying that exceptions can be performance heavy (or something like that), and I usually only use exceptions for actual errors.  I think the if not success way is more confusing and less readable than gotos.

As I said, I can't find a simpler and more readable way to write it.  I already thought of most of these ways, but I think using goto in this case is just more readable (at least more than all of these options).
Have you considered using self-modifying code?

It would be easier to make fun of your program if you provided actual code. As it stands I recommend making a function for "do a loop but stop if a condition is met and do special stuff then, with a return value telling you if the condition happened." I mean you do it 3 times there.
Logged

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9411
    • View Profile
Re: Random Stuff Part II
« Reply #5717 on: December 14, 2015, 12:05:52 am »
0

Have you considered using self-modifying code?

Is that... a thing?  I mean, I assume you're not talking about some sort of AI programmer, and I feel like I've heard the concept before... but I'm not certain what that means.
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

XerxesPraelor

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1069
  • Respect: +364
    • View Profile
Re: Random Stuff Part II
« Reply #5718 on: December 14, 2015, 12:10:29 am »
0

It's c++, so I can't use break label.

I've heard people saying that exceptions can be performance heavy (or something like that), and I usually only use exceptions for actual errors.  I think the if not success way is more confusing and less readable than gotos.

As I said, I can't find a simpler and more readable way to write it.  I already thought of most of these ways, but I think using goto in this case is just more readable (at least more than all of these options).

I am probably at about your level or maybe a little lower, but the way I'd do it is make helper bool functions, pass everything in, and then use ||. Feel free to make fun of this too.

Have you considered using self-modifying code?

Is that... a thing?  I mean, I assume you're not talking about some sort of AI programmer, and I feel like I've heard the concept before... but I'm not certain what that means.
I think it's a common example of something that will mess your program really badly if you don't do it exactly right, and so shouldn't be done.
Logged

Titandrake

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2210
  • Respect: +2854
    • View Profile
Re: Random Stuff Part II
« Reply #5719 on: December 14, 2015, 03:10:09 am »
+1

Have you considered using self-modifying code?

Is that... a thing?  I mean, I assume you're not talking about some sort of AI programmer, and I feel like I've heard the concept before... but I'm not certain what that means.

It's a thing, but if you actually use it for anything people have the right to punch you in the head, because understanding what it does is so difficult.

The core idea is that in the end, everything breaks down to 0s and 1s arranged in a particular way. That image file is a sequence of bits describing pixel color values. This song file is a sequence of bits describing what frequencies to play at what time. Thus, if you're clever enough about it, there's no reason you can't interpret the same binary data in two different ways. Effectively, that means your program can write some data somewhere, treat that data as code, and start running from there.

Edit: A complicated example of this is http://web.mit.edu/puzzle/www/2014/puzzle/puzzle_with_answer_rice/, where each step modifies the behaviors of other steps.
« Last Edit: December 14, 2015, 03:11:26 am by Titandrake »
Logged
I have a blog! It's called Sorta Insightful. Check it out?

silverspawn

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 5300
  • Shuffle iT Username: sty.silver
  • Respect: +3188
    • View Profile
Re: Random Stuff Part II
« Reply #5720 on: December 14, 2015, 08:03:42 pm »
0

question: if I walk through an empty land and I come across some kind of structure, is that a 'change in geography?' Also, is it a 'change in landscape?' Also, is the 'change in' phrasing even correct for the latter?

I think the answers are yes / no / yes, but I'm not sure.

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9411
    • View Profile
Re: Random Stuff Part II
« Reply #5721 on: December 14, 2015, 08:22:15 pm »
+1

No, no, sometimes.  "Change of [landscape|geography|venue]" is more common in English.

A single structure is a change of neither landscape nor geography.
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

silverspawn

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 5300
  • Shuffle iT Username: sty.silver
  • Respect: +3188
    • View Profile
Re: Random Stuff Part II
« Reply #5722 on: December 14, 2015, 08:57:09 pm »
0

I see, thanks.

Donald X.

  • Dominion Designer
  • *****
  • Offline Offline
  • Posts: 6357
  • Respect: +25671
    • View Profile
Re: Random Stuff Part II
« Reply #5723 on: December 15, 2015, 04:21:52 am »
0

Have you considered using self-modifying code?

Is that... a thing?  I mean, I assume you're not talking about some sort of AI programmer, and I feel like I've heard the concept before... but I'm not certain what that means.
I have seen it used.

It was easy to do when everything was in machine language. You have a program in 6502; it's just a bunch of hexadecimals. Your assembler translated LDA #0 to A9 00 and that's that. Your program is at some specific address in memory - it was very rare to have code that could execute from some random address. So, if your code isn't firmware, you can modify a byte to be a different instruction, or different data value or address, and then the code will do different things.

In practice it is really really bad to do this. Odds are your program is now impossible to debug. Odds are that whatever you were accomplishing, there was a better way to do it. The guy I saw using it, he didn't understand how indirect addressing worked. So he used direct addressing and modified the addresses in the code on the fly. He was bad. Later he was fired.

These days, self-modifying code has the additional problem of, your processor may be constantly trying to cache things to speed up. It caches the code, you modify it, it didn't modify it in the cache, now your code doesn't work.
Logged

AdamH

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2833
  • Shuffle iT Username: Adam Horton
  • You make your own shuffle luck
  • Respect: +3879
    • View Profile
    • My Dominion Videos
Re: Random Stuff Part II
« Reply #5724 on: December 15, 2015, 08:35:58 am »
+3

As I said, I can't find a simpler and more readable way to write it.  I already thought of most of these ways, but I think using goto in this case is just more readable (at least more than all of these options).

When I was in school, they said never use goto for any reason, you can always do without them and they're evil. I know why they teach you this, because if you don't use gotos properly your code turns into spaghetti. I don't get why they don't teach you the proper way to use gotos, though, that seems kinda wak.

The moment I stepped into the professional world, I was writing these nested for loops and everyone was all "what is this I can't even." They told me to use gotos to make the code more readable. I spit hot fire back "what if I write it in a function and use multiple returns, yo?" and they were like "you can do that, cuz, but I'd rather you just use gotos."

If you aren't allowed to use gotos, then that's silly, but I guess you aren't. The next best thing is multiple return statements, and after that you have to use the Nested Loops Of Sadness™ (NLOS).
Logged
Visit my blog for links to a whole bunch of Dominion content I've made.
Pages: 1 ... 227 228 [229] 230  All
 

Page created in 0.104 seconds with 21 queries.