Open Side Menu Go to the Top

05-03-2016 , 08:30 AM
Quote:
Originally Posted by CyberShark93
Hey friends, suppose if I want to run an exhaustive search across all permutations in 16 different arrays in c, is there a elegant way to write this without having 16 nested loops?
Sure, you can do it either recursively or iteratively. I think recursively is probably easier to understand. Here it is in python

Code:
def permutate(val, arrays, output):
    if not len(arrays):
        output.append(val)
        return

    for el in arrays[0]:
        permutate(val+[el], arrays[1:], output)

arrays = [[1,2,3], ['a','b', 'c'], ['X', 'Y', 'Z'], ['!', '@','#']]
output = []
permutate([], arrays, output)
print output
The iterative version is probably a little harder to follow but isn't that much longer or more complicated.
Programming homework and newbie help thread Quote
Programming homework and newbie help thread
150% up to $2,000 Welcome Bonus on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Programming homework and newbie help thread
05-03-2016 , 08:54 AM
Quote:
Originally Posted by Wolfram
3) Intro to C# - the language of Microsoft. Similar to java in many ways, better than java if you want to make Windows Gui apps. Arguably worse than java for backend stuff because it forces you to use their proprietary tech stack.
Not anymore.
Programming homework and newbie help thread Quote
05-03-2016 , 11:28 AM
Quote:
Originally Posted by CyberShark93
Hey friends, suppose if I want to run an exhaustive search across all permutations in 16 different arrays in c, is there a elegant way to write this without having 16 nested loops?
Yes, Donald Knuth provided many non-recursive algorithms for generation of all permutations in section 7.2.1.2 of volume 4 of 'The Art of Computer Programming'.

Also, non-recursive C code (using a string instead of an array) can be found here.

Last edited by coon74; 05-03-2016 at 11:44 AM.
Programming homework and newbie help thread Quote
05-03-2016 , 11:57 AM
Quote:
Originally Posted by ChrisV
Not anymore.
too little, too late
Programming homework and newbie help thread Quote
05-04-2016 , 06:25 PM
Quote:
Originally Posted by CyberShark93
Hey friends, suppose if I want to run an exhaustive search across all permutations in 16 different arrays in c, is there a elegant way to write this without having 16 nested loops?
Not C, but here's a js version that used the ramda library for the permutation function that i think expresses the algorithm pretty nicely:

Code:
var perm = (arr, result=[[]]) => 
  !arr.length ? map(flatten, result) :
    addIndex(chain)(
      (x,i) => perm(remove(i,1,arr), xprod(result, of(x)))
    , arr)
Note: addIndex(chain) is just the "flatMap" function with an index attached. xprod is the cross product of two arrays (useful utility for your general problem) which in this case i'm just using to attach to attach a single element to the end of every array in an array. that is, as a synonym for map(concat(x))
Programming homework and newbie help thread Quote
05-08-2016 , 02:00 AM
Any idea what the -4:00 means in this timestamp?

"timestamp": "2016-03-24T13:25:34.000-04:00"
Programming homework and newbie help thread Quote
05-08-2016 , 02:34 AM
Timezone. EDT, in this case I think.
Programming homework and newbie help thread Quote
05-08-2016 , 12:46 PM
Well, it's not really "time zone" it's just "offset from UTC", i.e. "4 hours behind UTC".

I really hate this means of recording datetimes, because the "right" offset for wherever you are will change a couple times a year. But then again dealing with timezones is a giant cluster**** in nearly every programming environment no matter what you do.
Programming homework and newbie help thread Quote
05-09-2016 , 09:11 PM
SOF FAQ say when you edit your unanswered question it will get bumped up. does not seem to be working for me. ??
Programming homework and newbie help thread Quote
05-10-2016 , 07:32 PM
Quote:
Originally Posted by RustyBrooks
Well, it's not really "time zone" it's just "offset from UTC", i.e. "4 hours behind UTC".

I really hate this means of recording datetimes, because the "right" offset for wherever you are will change a couple times a year. But then again dealing with timezones is a giant cluster**** in nearly every programming environment no matter what you do.
Win32 handles it pretty well in my view FWIW
Programming homework and newbie help thread Quote
05-10-2016 , 07:55 PM
What does "win32" mean? When I say programming environment I mean a programming langauge and it's associated libraries. If you mean at a system level, I think I probably disagree, the win32 os library for timezones is pretty much as crazypants as most things I've seen.

Nearly every mainstream language has at least one way to make timezone stuff work well enough, as long as you don't make any mistakes or follow the wrong path. And most of them also have ways that seem like they should work, but do not.

A python example comes to mind.

Code:
>>> x = datetime.datetime(2016, 1, 1, 0, 0, tzinfo=pytz.timezone('US/Central'))
>>> x
datetime.datetime(2016, 1, 1, 0, 0, tzinfo=<DstTzInfo 'US/Central' LMT-1 day, 18:09:00 STD>)
What? 18:09? Let's see what this is in UTC

Code:
>>> x.astimezone(pytz.utc)
datetime.datetime(2016, 1, 1, 5, 51, tzinfo=<UTC>)
5:51. So somehow midnight in US/Central turned into 5:51 in UTC. That's pretty ****ed up. The reason why is fairly clear once you understand how pytz works, but it's bitten nearly every python programmer I ever met.
Programming homework and newbie help thread Quote
05-10-2016 , 10:55 PM
Quote:
Originally Posted by RustyBrooks
What does "win32" mean? When I say programming environment I mean a programming langauge and it's associated libraries. If you mean at a system level, I think I probably disagree, the win32 os library for timezones is pretty much as crazypants as most things I've seen.

Nearly every mainstream language has at least one way to make timezone stuff work well enough, as long as you don't make any mistakes or follow the wrong path. And most of them also have ways that seem like they should work, but do not.

A python example comes to mind.

Code:
>>> x = datetime.datetime(2016, 1, 1, 0, 0, tzinfo=pytz.timezone('US/Central'))
>>> x
datetime.datetime(2016, 1, 1, 0, 0, tzinfo=<DstTzInfo 'US/Central' LMT-1 day, 18:09:00 STD>)
What? 18:09? Let's see what this is in UTC

Code:
>>> x.astimezone(pytz.utc)
datetime.datetime(2016, 1, 1, 5, 51, tzinfo=<UTC>)
5:51. So somehow midnight in US/Central turned into 5:51 in UTC. That's pretty ****ed up. The reason why is fairly clear once you understand how pytz works, but it's bitten nearly every python programmer I ever met.
Piece of cake to convert UTC to local time with win32. Regarding what win32 is, Google is your friend.
Programming homework and newbie help thread Quote
05-11-2016 , 08:40 AM
It's a piece of cake to convert UTC to local time in most programming languages. The problem is, most of them have several ways to do it that will give a wrong result in some circumstances.

I know what win32 is. It's not a programming language, so I don't know why you answered in that way. It's like if I said "most cars have problems with brakes" and you replied "the brakes on highway 95 are pretty good"
Programming homework and newbie help thread Quote
05-11-2016 , 08:43 PM
thought this was interesting and worth a share:

Quote:
An anonymous reader has shared an interesting article that talks about one of the most common challenges faced by novice developers: "I know how to program, but I don't know what to program."
https://news.slashdot.org/story/16/0...hat-to-program
Programming homework and newbie help thread Quote
05-21-2016 , 10:36 PM
Anyone have experience with Wordpress and AWS? Basically I followed this tutorial, https://aws.amazon.com/getting-start...press-website/ Easy peasy. Then I tried editing a wordpress theme and this is where my trouble starts.

I am on my page, let's say it is www.myexample.com/admin. I try changing a wordpress theme but I get the message, 'You need to make this file writable before you can save your changes. See the Codex https://codex.wordpress.org/Changing...rmission_Modes for more information.' I look at the codex and I don't understand anything. Then I google for a few hours and make no progress. Stuff like this makes me question if I am really cut out for programming. I feel like I don't have even a basic understanding of what is going on.
Programming homework and newbie help thread Quote
05-21-2016 , 10:54 PM
Quote:
Originally Posted by penguinpoker
Anyone have experience with Wordpress and AWS? Basically I followed this tutorial, https://aws.amazon.com/getting-start...press-website/ Easy peasy. Then I tried editing a wordpress theme and this is where my trouble starts.

I am on my page, let's say it is www.myexample.com/admin. I try changing a wordpress theme but I get the message, 'You need to make this file writable before you can save your changes. See the Codex https://codex.wordpress.org/Changing...rmission_Modes for more information.' I look at the codex and I don't understand anything. Then I google for a few hours and make no progress. Stuff like this makes me question if I am really cut out for programming. I feel like I don't have even a basic understanding of what is going on.
your first problem is that editing a wordpress theme is not programming
Programming homework and newbie help thread Quote
05-21-2016 , 11:16 PM
It is a php file that I would be changing.
Programming homework and newbie help thread Quote
05-22-2016 , 12:03 AM
By following this tutorial, https://wiki.bitnami.com/Amazon_clou...through_SSH.3f I was able to SSH into my account. I think. No real idea what this means yet, but if something comes of it I will post back.
Programming homework and newbie help thread Quote
05-22-2016 , 12:37 AM
Well looks like I am getting somewhere. Once you are in SSH you navigate to the folder and then set the permission by doing $ chmod -v 746 foldername. This changes the permission, however doing so causes an error, stylesheet not found. This is really strange because the stylesheet is still there. I am not actually even changing the files yet, just changing the permissions.

Last edited by penguinpoker; 05-22-2016 at 12:58 AM.
Programming homework and newbie help thread Quote
05-22-2016 , 04:31 AM
Promise this will be the last post for now. If I could delete earlier posts I would.

Think I have a decent understanding now. First you can download MAMP (Mac, Apache, MSQL, PHP) and then download Wordpress and put it into your MAMP folder so that you develop locally. Then once you develop locally you can push up a file or even a whole folder to your AWS instance by using something called SSH. So no need to even edit your files on AWS!

Weird how some days you make zero progress and other days you make a lot. Once I decided to try and figure out how to SSH then everything sort of went from there. Even though I didn't know if it would help me at all at the start.
Programming homework and newbie help thread Quote
05-22-2016 , 05:38 AM
Wait until you learn about ssh tunneling.
Programming homework and newbie help thread Quote
05-22-2016 , 06:11 AM
Quote:
Originally Posted by RustyBrooks
Well, it's not really "time zone" it's just "offset from UTC", i.e. "4 hours behind UTC".

I really hate this means of recording datetimes, because the "right" offset for wherever you are will change a couple times a year. But then again dealing with timezones is a giant cluster**** in nearly every programming environment no matter what you do.
Quote:
Originally Posted by RustyBrooks
It's a piece of cake to convert UTC to local time in most programming languages. The problem is, most of them have several ways to do it that will give a wrong result in some circumstances.

I know what win32 is. It's not a programming language, so I don't know why you answered in that way. It's like if I said "most cars have problems with brakes" and you replied "the brakes on highway 95 are pretty good"
Interesting and please show me the post where I stated win32 was a programming language. Thanks. No programming environments that utilize the win32 API? Cmon.

Not hard to use this function.

win32 -GetLocalTime

Last edited by adios; 05-22-2016 at 06:21 AM.
Programming homework and newbie help thread Quote
05-22-2016 , 02:04 PM
GetLocalTime specifically *doesn't* deal with timezones. It gives you the system time. It doesn't even give you a time back that contains information about what the local timezone *is*
Programming homework and newbie help thread Quote
05-22-2016 , 04:02 PM
Quote:
Originally Posted by penguinpoker
Well looks like I am getting somewhere. Once you are in SSH you navigate to the folder and then set the permission by doing $ chmod -v 746 foldername. This changes the permission, however doing so causes an error, stylesheet not found. This is really strange because the stylesheet is still there. I am not actually even changing the files yet, just changing the permissions.
You need to add the -R flag. R means recursive. The chmod commands are pretty straightforward, and I disagree with your numbers. Also, you probably need to do that with sudo, since the folder is probably owned by root.
Programming homework and newbie help thread Quote
05-22-2016 , 06:11 PM
I actually prefer using the named parameters instead of the numbers. It's easier to get right. For example

chmod a+rw
means "give everyone (a=all) read and write permision"

chmod g-x
means "take away execute permission from group"

and so forth.

You're probably getting stylesheet not found because you don't have the execute bit set on one of the folders. The "read" flag allows you to list the files in a directory, but the "execute" flag allows you to change directories into it (i.e. you can't access a subdir if you don't have execute permissions on the parent dir)

"7" gives rwx to the owner of the directory, 4 gives just r to the group and 6 gives rw to everyone else. This probably is not what you want. I would give the directories all a+rx at the least.
Programming homework and newbie help thread Quote
Programming homework and newbie help thread
150% up to $2,000 Welcome Bonus on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Programming homework and newbie help thread

      
m