Search Results

Search found 407 results on 17 pages for 'sequences'.

Page 11/17 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Most elegant way to morph this sequence

    - by Ed Woodcock
    Hi folks: I've got the Day of the week stored in a database table (that I do not control), and I need to use it in my code. Problem is, I want to use the System.DayOfWeek enum for representation for this, and the sequences are not the same. In the database, it's as follows: 1 2 3 4 5 6 7 S M T W T F S I need it as follows: 0 1 2 3 4 5 6 M T W T F S S What's the most elegant way to do this? for example, I could do: i = dayOfWeek; i = i - 2; if (i < 0) { i = 6; } but that's a bit inelegant. Any suggestions?

    Read the article

  • Encode/compress sequence of repeating integers

    - by Alex
    Hey there! I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now I need some algorithm to convert this string into something compressed like a9b3a3c3a2d5 Which means "a 9 times, then b 3 times, then a 3 times" and so on, where "a" stands for 0, "b" for 1, "c" for 2 and "d" for 3. How would you do that? So far nothing suitable came to my mind, and I had no luck with google because I didn't really know what to search for. What is this kind of encoding / compression called? PS: I am going to do the encoding with PHP, and the decoding in JavaScript.

    Read the article

  • What should I call a class that contains a sequence of states

    - by Robert P
    I have a GUI tool that manages state sequences. One component is a class that contains a set of states, your typical DFA state machine. For now, I'll call this a StateSet. However, I have another class that has a collection (possibly partially unordered) of those state sets, and lists them in a particular order. and I'm trying to come up with a good name for it - not just for internal code, but for customers to refer to it. I've got: Sequence (maybe) StateSetSet (reasonable for code, but not for customers) Any other suggestions or ideas?

    Read the article

  • Regular expression for parsing CSV in PHP

    - by Discodancer
    I already managed to split the CSV file using this regex: "/,(?=(?:[^\"]\"[^\"]\")(?![^\"]\"))/" But I ended up with an array of strings that contain the opening and ending double quotes. Now I need a regex that would strip those strings of the delimiter double quotes. As far as I know the CSV format can encapsulate strings in double quotes, and all the double quotes that are already a part of the string are doubled. For example: My "other" cat becomes "My ""other"" cat" What I basically need is a regex that will replace all sequences of N doublequotes with a sequence of (N/2 - rounded down) double quotes. Or is there a better way ? Thanks in advance.

    Read the article

  • MS SQL replace sequence of same characters inside Text Field (TSQL only)

    - by zmische
    I have a text column varchar(4000) with text: 'aaabbaaacbaaaccc' and I need to remove all duplicated chars - so only one from sequence left: 'abacbac' It should not be a function, Procedure or CLR - Regex solution. Only true SQL select. Currently I think about using recursive WITH clause with replace 'aa'-'a', 'bb'-'b', 'cc'-'c'. So recursion should cycle until all duplicated sequences of that chars would be replaced. DO you have another solution, perhaps more Permormant one? PS: I searched through this site about different replace examples - they didnt suit to this case.

    Read the article

  • Convert matched string of UTF-8 values to UTF-8 characters in Ruby

    - by user1475154
    Trying to convert output from a rest_client GET to the characters that are represented with escape sequences. Input: ..."sub_id":"\u0d9c\u8138\u8134\u3f30\u8139\u2b71"... (which I put in 'all_subs') Match: m = /sub_id\"\:\"([^\"]+)\"/.match(all_subs.to_str) [1] Print: puts m.force_encoding("UTF-8").unpack('U*').pack('U*') But it just comes out the same way I put it in. ie, "\u0d9c\u8138\u8134\u3f30\u8139\u2b71" However, if I convert a raw string of it: puts "\u0d9c\u8138\u8134\u3f30\u8139\u2b71".unpack('U*').pack('U*') The output is perfect as "??????"

    Read the article

  • Calculating probability that a string has been randomized? - Python

    - by RadiantHex
    Hi folks, this is correlated to a question I asked earlier (question) I have a list of manually created strings such as: lucy87 gordan_king fancy_unicorn77 joplucky_kanga90 base_belong_to_narwhals and a list of randomized strings: johnkdf pancake90kgjd fancy_jagookfk manhattanljg What gives away that the last set of strings are randomized is that sequences such as 'kjg', 'jgf', 'lkd', ... . Any clever way I could separate strings that contain these apparently randomized strings from the crowd? I guess that this plays a lot on the fact that certain characters are more likely to be placed next to others (e.g. 'co', 'ka', 'ja', ...). Any ideas on this one? Kylotan mentioned Reverend, but I am not sure if it can be used fr such purpose. Help would be much appreciated!

    Read the article

  • Working with multiple input and output files in Python

    - by Morlock
    I need to open multiple files (2 input and 2 output files), do complex manipulations on the lines from input files and then append results at the end of 2 output files. I am currently using the following approach: in_1 = open(input_1) in_2 = open(input_2) out_1 = open(output_1, "w") out_2 = open(output_2, "w") # Read one line from each 'in_' file # Do many operations on the DNA sequences included in the input files # Append one line to each 'out_' file in_1.close() in_2.close() out_1.close() out_2.close() The files are huge (each potentially approaching 1Go, that is why I am reading through these input files one at a time. I am guessing that this is not a very Pythonic way to do things. :) Would using the following form good? with open("file1") as f1: with open("file2") as f2: # etc. If yes, could I do it while avoiding the highly indented code that would result? Thanks for the insights!

    Read the article

  • Should I convert overlong UTF-8 strings to their shortest normal form?

    - by Grant McLean
    I've just been reworking my Encoding::FixLatin Perl module to handle overlong UTF-8 byte sequences and convert them to the shortest normal form. My question is quite simply "is this a bad idea"? A number of sources (including this RFC) suggest that any over-long UTF-8 should be treated as an error and rejected. They caution against "naive implementations" and leave me with the impression that these things are inherently unsafe. Since the whole purpose of my module is to clean up messy data files with mixed encodings and convert them to nice clean utf8, this seems like just one more thing I can clean up so the application layer doesn't have to deal with it. My code does not concern itself with any semantic meaning the resulting characters might have, it simply converts them into a normalised form. Am I missing something. Is there a hidden danger I haven't considered?

    Read the article

  • Is OpenGL required for my iPhone game?

    - by Ben X Tan
    On an iPhone: If I am writing a game that has multiple levels, with multiple animations (image sequences), jpg and png (transparent), some full screen and some not, some looped and some played once only. What is the best way of doing it? Each level might have up to 10MB of images. Add on to this music, and video (cut scenes). All 2D graphics, no 3D models. Is OpenGL required? Or can this be achieved with Quartz or Core Animation?

    Read the article

  • Operant conditioning algorithm?

    - by Ken
    What's the best way to implement real time operant conditioning (supervised reward/punishment-based learning) for an agent? Should I use a neural network (and what type)? Or something else? I want the agent to be able to be trained to follow commands like a dog. The commands would be in the form of gestures on a touchscreen. I want the agent to be able to be trained to follow a path (in continuous 2D space), make behavioral changes on command (modeled by FSM state transitions), and perform sequences of actions. The agent would be in a simulated physical environment.

    Read the article

  • Unicode and URI encoding, decoding and escaping in JavaScript

    - by apphacker
    If you look at this table here, it has a list of escape sequences for Unicode characters that don't actually work for me. For example for "%96", which should be a –, I get an error when trying decode: decodeURIComponent("%96"); URIError: URI malformed If I attempt to encode "–" I actually get: encodeURIComponent("–"); "%E2%80%93" I searched through the internet and I saw this page, which mentions using escape and unescape with decodeURIComponent and encodeURIComponent respectively. This doesn't seem to help because %96 doesn't show up as "–" no matter what I try and this of course wouldn't work: decodeURIComponent(escape("%96)); "%96" Not very helpful. How can I get "%96" to be a "–" with JavaScript (without hardcoding a map for every single possible unicode character I may run into)?

    Read the article

  • Remove adjacent identical elements in a Ruby Array?

    - by Mike Woodhouse
    Ruby 1.8.6 I have an array containing numerical values. I want to reduce it such that sequences of the same value are reduced to a single instance of that value. So I want a = [1, 1, 1, 2, 2, 3, 3, 3, 3, 2, 2, 2, 3, 3, 3] to reduce to [1, 2, 3, 2, 3] As you can see, Array#uniq won't work in this case. I have the following, which works: (a.size - 1).downto(1) { |i| a[i] = nil if a[i - 1] == a[i] } Can anyone come up with something less ugly?

    Read the article

  • Project Euler #163 understanding

    - by Paul
    I spent quite a long time searching for a solution to this problem. I drew tons of cross-hatched triangles, counted the triangles in simple cases, and searched for some sort of pattern. Unfortunately, I hit the wall. I'm pretty sure my programming/math skills did not meet the prereq for this problem. So I found a solution online in order to gain access to the forums. I didn't understand most of the methods at all, and some just seemed too complicated. Can anyone give me an understanding of this problem? One of the methods, found here: http://www.math.uni-bielefeld.de/~sillke/SEQUENCES/grid-triangles (Problem C) allowed for a single function to be used. How did they come up with that solution? At this point, I'd really just like to understand some of the concepts behind this interesting problem. I know looking up the solution was not part of the Euler spirit, but I'm fairly sure I would not have solved this problem anyhow.

    Read the article

  • How to feed an xml database with tags obtained thru html forms ?

    - by blaise1
    Hello! Not a programmer, I begin with xml, html forms and xslt on Mac. I plan to use a form to post short texts in a xhtml page and invite end users to add some annotations to the said text. The users would select a specific part of the text posted and each annotation would stand for one specific chain of characters. My goal is to consolidate the tags obtained from various user's annotations to one xml "knowledge base" containing the original text with all the revision indicators. Then I plan to use xslt sheets to product various reports based on the tags obtained. my two questions are : 1- am I dreaming ? Is it really possible to do that with xml, xforms, xslt without using java, php, ajax or other seasoned programmer's tools ? 2- What should be my focus for further explorations aiming in that direction ? Which schema, events, sequences should I study ? Je vous remercie à l'avance, Please excuse my English. Blaise

    Read the article

  • Time Complexities of recursive algorithms

    - by Peter
    Whenever I see a recursive solution, or I write recursive code for a problem, it is really difficult for me to figure out the time complexity, in most of the cases I just say its exponential? How is it exponential actually? How people say it is 2^n, when it is n!, when it is n^n or n^k. I have some questions in mind, let say find all permutations of a string (O(n!)) find all sequences which sum up to k in an array (exponential, how exactly do I calculate). Find all subsets of size k whose sum is 0 (will k come somewhere in complexity , it should come right?). Can any1 help me how to calculate the exact complexity of such questions, I am able to wrote code for them , but its hard understanding the exact time complexity.

    Read the article

  • What is the representation of the mac command key in the terminal?

    - by freethinker
    Like control key is represented by a '^' in the terminal, what is the equivalent for the command key (mac)? I am trying to remap my bash shortcuts using stty For eg stty eof ^D But instead of control, I want to use the command key. EDIT: Okay so the issue I was trying to solve was that I wanted to interchange command and control keys because I work on osx and linux and the different key combinations cause me a lot of pain. So I interchanged the modifier keys using osx preferences. But now all the bash shortcuts like Ctrl+C etc had become equivalent of using the key sequences 'cmd+c' - which is not acceptable. Thankfully iTerm2, supports remapping of modifier keys as well, so for iterm2 I reversed them again which means iTerm2 recognizes command as command and control as control. So problem solved for now.

    Read the article

  • How can I load an MP3 or similar music file for display and analysis in wxWidgets?

    - by Jon Cage
    I'm developing a GUI in wxPython which allows a user to generate sequences of colours for some toys I'm building. Part of the program needs to load an MP3 (and potentially other formats further down the line) and display it to the user. That should be sufficient to get started but later I'd like to add features like identifying beats and some crude frequency analysis. Is there any simple way of loading / understanding an MP3's contents to display a plot of its amplitudes to the screen using wxWidgets? I later intend to port to C++/wxWidgets for speed and to avoid having to distribute wxPython.

    Read the article

  • byte-sized bit pattern in C and its relevance?

    - by Nikunj Banka
    I a reading Kerninghan and Ritchie's C programming language book and on page 37 it mentions byte sized bit patterns like : '\013' for vertical tab . '\007' for bell character . My doubts : What is byte sized in it and and what's a bit pattern ? What relevance does this hold and where can I apply it ? Is it in any sense related to escape sequences ? I can't seem to find any information what so ever about these byte sized bit patterns on the web . please help . thanks .

    Read the article

  • Object-oriented Programming - need your help

    - by wanderameise
    hey folks, I try to realize a little game project to dive deeper into OO programming (winforms c++/cli). I already started coding but now I´d like to make a re-design. For the beginning the game should consist of four parts like game-engine, user interface, highscore and playground. Heres a little (non-UML-conform) class diagramm to visualize my purposes http://i.imgur.com/lmpwj.png Would this be the right way? In my eyes the game engine is responsible to control the game sequences (state machine?) and exchanges information betweens all other classes. I appreciate any help!

    Read the article

  • Replacing elements within a string in R

    - by Maureen
    Hi, I have a row in a data frame in R that is made up of sequences of undetermined length of 0s 1s and 2s as characters. So "01", "010", "201", "102", "00012"... things like this. I'd like to find a way to determine if the last character in the string is NUMERICALLY the largest. It's important that I keep the row in the data frame as characters for other purposes. So basically I want to take substr(x, nchar(x), nchar(x)) and determine if it, as a number, is the largest of the numbers in the character string. I'm super lost as to how to do this, since I'm not all that familiar with regular expressions and I have to back and forth between treating elements as characters and numbers. Thanks in advance. ~Maureen

    Read the article

  • PHP with SQL Injection

    - by Scott S
    For our first assignment in a System Security class, we have to hack into the professors "cheaply organized" sql database. I know the only user is "admin" and the select statement generated in the php is: select user_id from user where user_username = 'admin' AND user_password = md5('noob') I am having a number of problems attempting to bypass the password part of this statement as the professor has some javascript embedded in the page to sanitize the username and password of any non-alphanumeric values. This can be bypassed by turning off javascript :P but any values sent still get cleaned by the operating system (some build of Debian 32-bit). I've seen the code for the login request and it does not escape any characters. How do I bypass the operating systems escape sequences?

    Read the article

  • bash: How to evaluate PS1, PS2, ...?

    - by Harry
    Is there any way to 'evaluate' PS1, PS2, etc from within a bash script? Although, I can use alternate means to get all elements of my current PS1, I would really like to be able to reuse its definition instead of using these alternate means. For example, ===================================== PS1 element --> Alternate means ===================================== \u --> $USER \h --> $HOSTNAME \w --> $PWD ... ===================================== I could very well use the 'alternate means' column in my script, but I don't want to. In my PS1, I, for example, use bold blue color via terminal escape sequences which I'd like to be able to simply reuse by evaluating PS1.

    Read the article

  • Mapping over multiple Seq in Scala

    - by bsdfish
    Suppose I have val foo : Seq[Double] = ... val bar : Seq[Double] = ... and I wish to produce a seq where the baz(i) = foo(i) + bar(i). One way I can think of to do this is val baz : Seq[Double] = (foo.toList zip bar.toList) map ((f: Double, b : Double) => f+b) However, this feels both ugly and inefficient -- I have to convert both seqs to lists (which explodes with lazy lists), create this temporary list of tuples, only to map over it and let it be GCed. Maybe streams solve the lazy problem, but in any case, this feels like unnecessarily ugly. In lisp, the map function would map over multiple sequences. I would write (mapcar (lambda (f b) (+ f b)) foo bar) And no temporary lists would get created anywhere. Is there a map-over-multiple-lists function in Scala, or is zip combined with destructuring really the 'right' way to do this?

    Read the article

  • Emulating a transaction-safe SEQUENCE in MySQL

    - by Michael Pliskin
    We're using MySQL with InnoDB storage engine and transactions a lot, and we've run into a problem: we need a nice way to emulate Oracle's SEQUENCEs in MySQL. The requirements are: - concurrency support - transaction safety - max performance (meaning minimizing locks and deadlocks) We don't care if some of the values won't be used, i.e. gaps in sequence are ok. There is an easy way to archieve that by creating a separate InnoDB table with a counter, however this means it will take part in transaction and will introduce locks and waiting. I am thinking to try a MyISAM table with manual locks, any other ideas or best practices?

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17  | Next Page >