exercise

What is the Best Exercise for Good Posture?

I sit in an office chair all day long. I try to keep good posture, but I find myself in any number of bad positions throughout the day. Is there any particular exercise that would help maintain good posture for longer periods of time? ...

Performance challenge: NAL Unit Wrapping

From what I've seen in the past, StackOverflow seems to like programming challenges, such as the fast char to string exercise problem which got dozens of responses. This is an optimization challenge: take a very simple function and see if you can come up with a smarter way of doing it. I've had a function that I've wanted to further op...

How do you match only valid roman numerals with a regular expression?

Thinking about my other problem, i decided I can't even create a regular expression that will match roman numerals (let alone a context-free grammar that will generate them) The problem is matching only valid roman numerals. Eg, 990 is NOT "XM", it's "CMXC" My problem in making the regex for this is that in order to allow or not allow...

Do you have any favorite ergonomic exercise or habit?

I've read somewhere that ergonomic problems accounts for 70% of injury... And i don't want to be one of those guys who think, ahh it's just a slight sore, and go on and discover that i have CTS and have to operate on my hands!!! So are the any good ergo habits that you follow religiously each day? Or some cool tools that would send any ...

Event-driven simulation class

I am working through some of the exercises in The C++ Programming Language by Bjarne Stroustrup. I am confused by problem 11 at the end of Chapter 12: (*5) Design and implement a library for writing event-driven simulations. Hint: <task.h>. ... An object of class task should be able to save its state and to have that state restored s...

Online Programming Exercises

What online programming exercises would you suggest? Hopefully a site where you can submit code instead of submitting output. ...

Interesting problem using printf & scanf only...

I'm running out of ideas for my "Beginning C" class, and the only topics I've discussed so far are Data types, Variables & the printf & scanf functions. My last quizzes involved simple formulas (area of a circle, volume of a cube..) enclosed inside the printfs.. eg. printf("volume = %d",length * width * height); I'm looking for some...

The C programming language 2. ed. question

I'm reading the well known book "The C programming Language, 2nd edition" and there is one exercise that I'm stuck with. I can't figure out what exactly needs to be done, so I would like for someone to explain it to me. It's Exercise 5-17: Add a field-searching capability, so sorting may be done on fields within lines, each field sor...

Java Code Review: Merge sorted lists into a single sorted list

I want to merge sorted lists into a single list. How is this solution? I believe it runs in O(n) time. Any glaring flaws, inefficiencies, or stylistic issues? I don't really like the idiom of setting a flag for "this is the first iteration" and using it to make sure "lowest" has a default value. Is there a better way around that? publi...

Sieve of Eratosthenes algorithm

I am currently reading "programming principles and practice using c++" in chapter 4 there is an exercise in which i need to make a program to calculate prime numbers between 1 and 100. This is the program i came up with. #include <vector> #include <iostream> using namespace std; //finds prime numbers using Sieve of Eratosthenes algor...

Haskell learning exercise gives strange results

this is the question: "Write a function that computes the mean of a list, i.e. the sum of all elements in the list divided by its length. (You may need to use the fromIntegral function to convert the length of the list from an integer into a floating point number.)" first i tried this: mean :: [Double] -> Double mean [...

exercise on haskell, type definition, and guards.

first question: Define a function that joins a list of lists together using a separator value. the type definition should be like that: intersperse :: a -> [[a]] -> [a] The separator should appear between elements of the list, but should not follow the last element. Your function should behave as follows: ghci> :load Intersperse [1 o...

Time based VBA script for exercises

I have an excel spreadsheet with two columns, one with a list of exercises (33 of them) and a number of reps for each. What I really want is a program that picks a random exercise, displays it with it's number of reps, and has a button that says something like "Done?" When you click it, I want a timer that counts down 20 minutes, picks a...

Calculate car filled up times

Here is the question: The driving distance between Perth and Adelaide is 1996 miles. On the average, the fuel consumption of a 2.0 litre 4 cylinder car is 8 litres per 100 kilometres. The fuel tank capacity of such a car is 60 litres. Design and implement a JAVA program that prompts for the fuel consumptio...

Learning Python and trying to get first two letters and last two letters of a string.

Here's my code: # B. both_ends # Given a string s, return a string made of the first 2 # and the last 2 chars of the original string, # so 'spring' yields 'spng'. However, if the string length # is less than 2, return instead the empty string. def both_ends(s): if len(s) <= 2: return "" else: return s[0] + s[1] + s[len(s)-2]...

how to keep my infrequently used programming language skills in shape

I use ruby infrequently - usually it adds up to writing a script once in two months or more. I do most of my programming with C++, which is very different from ruby. with such wide gaps between my brushes with ruby I keep forgetting basic aspects of the language (like parsing a text file and other simple stuff). I would like to d...

List Sorting puzzle

Assuming I have final Iterable<String> unsorted = asList("FOO", "BAR", "PREFA", "ZOO", "PREFZ", "PREFOO"); What can I do to transform this unsorted list into this: [PREFZ, PREFA, BAR, FOO, PREFOO, ZOO] (a list which begin with known values that must appears first (here "PREFA" and "PREFZ") and the rest is alphabetically sorted) ...

exercise in the c++ programming language 3rd edition - desk calculator

I'm not sure what Bjarne meant with this exercise: "Convert the desk calculator to use a symbol structure instead of using the static variables number_value and string_value." Did he mean puting those 2 variables inside a structure and then using them through a structure? Edit: also one exercise related to the clculator and it says: "...

Algorithm to determine exchange rate

Given a data set of various currency pairs, how do I efficiently compute the implied fx rate for a pair not supplied in the data set? For example, say my database/table looks like this (this data is fudged): GBP x USD = 1.5 USD x GBP = 0.64 GBP x EUR = 1.19 AUD x USD = 1.1 Notice that (GBP,USD) != 1/(USD,GBP). I would expect the...

Alternating chars and nested parenthesesin (e)grep

I'm looking for a regex that finds all words in a list that do not have characters next to each other that are the same. (this is an exercise) So abcdef is printed, but aabcdef is not. I tried both egrep "^((.)[^\1])*$" and egrep "^((.)[^\2])*$" words but, other than being not sure which one would be right, they don't work. I k...