EppsNet Archive: Programming

Donald Knuth: Observations About Programming and Specifications

 

When you’re doing programming, you have to explain something to a computer, which is dumb. When you’re writing a document for a human being to understand, the human being will look at it and nod his head and say, “Yeah, this makes sense.” But there are all kinds of ambiguities and vagueness that you don’t realize until you try to put it into a computer. Then all of a sudden, almost every five minutes as you’re writing the code, a question comes up that wasn’t addressed in the specification. “What if this combination occurs?” It just didn’t occur to the person writing the design specification. When you’re faced with doing the implementation, a person who has been delegated the job of working from a design would have to say, “Well, hmm, I don’t know what the designer meant by this.” It’s so hard to do the design unless you’re faced… Read more →

Do You Want a Programmer or a Pizza?

 

I teach programming classes for a living. The school has a Slack account and one of the things we use it for is to post relevant job openings. These postings come from the hiring companies and most of them unfortunately simply consist of a copy of the job description: Responsibilities, Requirements, Technical Skills. Bullet points. Trying to hire programmers like ordering a pizza. When I was a hiring manager, HR would try to run job postings like that. The problem was that I wanted to hire good programmers and good programmers have a lot of options regarding where they work. So just as a candidate needs to sell themselves to a company, a company needs to sell itself to candidates. One way of doing this is through job postings. So I rewrote the job postings to make them more enticing. To give you an example of what I mean, here’s… Read more →

Now Here’s a Guy Who Gets Me

 

I teach programming classes for a living. The classes are 8 hours a day, 5 days a week, for 12 weeks. I put a lot of preparation into it because I want students to have the best, most up-to-date and relevant instruction. It’s a good job for me. Programming seems to me like an important, valuable skill . . . it’s allowed me to make a living doing (for the most part) things I like and things I’m good at. It gives you a lot of options. You don’t have to work for a tech company. Almost any field of endeavor now uses software and data and they hire programmers. You can work in education, healthcare, finance, sports, whatever energizes you. So it’s good to have a job where I feel like I’m helping people. The downside is that the students can’t really tell good instruction from bad instruction. Yes,… Read more →

Teaching Computer Science: Priorities

 

When schoolchildren start paying union dues, that’s when I’ll start representing the interests of schoolchildren. — Albert Shanker, President of the United Federation of Teachers (1964-1984) and President of the American Federation of Teachers (1974-1997) It’s a problem in my profession that the number of schools that want to teach computer science far exceeds the number of computer science majors who want to teach computer science. The opportunity cost is too high. Computer science majors can earn a lot more working as software engineers than working as teachers. I volunteer a couple mornings a week to help with computer science instruction at a local high school. This school has a teacher, originally hired as a math teacher, who must be well into her fourth decade of teaching.  She now teaches computer science classes — poorly, but she teaches them. Because of her professional longevity, she makes a six-figure income with… Read more →

Competitive Programming: UVa 612 – DNA Sorting

 

[Link to problem] One measure of “unsortedness” in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence DAABEC, this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence AACEDGG has only one inversion (E and D) — it is nearly sorted — while the sequence ZWQM has 6 inversions (it is as unsorted as can be — exactly the reverse of sorted). You are responsible for cataloging a sequence of DNA strings (sequences containing only the four letters A, C, G, and T). However, you want to catalog them, not in alphabetical order, but rather in order of “sortedness,” from “most sorted” to “least sorted.” All the strings… Read more →

Activities That No One Does Anymore

 

I got an email today from a company wanting to introduce me to their faxing API (Application Programming Interface). Faxing!? Will they also help me do other activities that no one does anymore, like playing the zither or baking my own bread? Read more →

Making it Easier for Women to Do Things They Don’t Want to Do

 

Apple launching tech camps for women in bid to diversify industry Like other major tech companies, Apple has been trying to lessen its dependence on men in high-paying programming jobs. I don’t think “dependence” is the right word there. Is that dependence like alcohol dependence, or like dependence on foreign oil? It’s an oblique way of saying “we’re trying to employ fewer men,” but explicitly singling out members of a certain group for unwelcome attention sounds discriminatory and possibly illegal. Women filled just 23 percent of Apple’s technology jobs in 2017, according to the company’s latest breakdown. “Just” — why do we assume that working at Apple is a goal that a lot of women have? Maybe women found better jobs? Or something else they’d rather be doing? Industry critics have accused the technology companies of discriminating against women through a male-dominated hierarchy that has ruled the industry for decades.… Read more →

Competitive Programming: SPOJ – Glass Beads

 

Link to problem Once upon a time there was a famous actress. As you may expect, she played mostly Antique Comedies most of all. All the people loved her. But she was not interested in the crowds. Her big hobby were beads of any kind. Many bead makers were working for her and they manufactured new necklaces and bracelets every day. One day she called her main Inspector of Bead Makers (IBM) and told him she wanted a very long and special necklace. The necklace should be made of glass beads of different sizes connected to each other but without any thread running through the beads, so that means the beads can be disconnected at any point. The actress chose the succession of beads she wants to have and the IBM promised to make the necklace. But then he realized a problem. The joint between two neighbouring beads is not… Read more →

Competitive Programming: SPOJ – String Problem

 

Link to problem Substring of some string A is defined as one or more (not necessary succeeding) elements of the string with maintaining the sequence. There are given two strings, string VOKI and string TOKI. Write the program that will calculate the length of any shortest substring of string VOKI such as it is not substring of string TOKI. Input In first line of input file there is string VOKI and in second one is string TOKI. The only characters that will occur are lowercase characters of English alphabet (‘a’- ‘z’). String lengths will be less or equal to 1000. Note: input data will be such so there will always be a solution. Output In the first line of file you should print the length of wanted substring. Sample input banana anbnaanbaan Sample output 5 (eg. banna) Sample input babab babba Sample output 3 (eg. aab) Solution below . .… Read more →

Competitive Programming: SPOJ – Palindromes

 

A palindrome is a word, phrase, number or other sequence of units that has the property of reading the same in either direction, e.g. ‘racecar’, ‘solos’. Task You are given a number k (2 <= k <= 30000) and a non-empty string S whose length does not exceed 30000 lowercase letters. We say two palindromes are different when they start from different positions. How many different palindromes of the length k does S contains? Input The first line contains K. The second line contains S. K does not exceed the length of S. Output The first and only line should consist of a single number – the number of palindromes found. Example Input: 5 ababab Output: 2 Time limit: 0.100s Link to problem Solution below . . . Read more →

Competitive Programming: SPOJ – Distinct Substrings

 

Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 1000 Output For each test case output one number saying the number of distinct substrings. Example Sample Input: 2 CCCCC ABABA Sample Output: 5 9 Explanation for the testcase with string ABABA: len=1 : A,B len=2 : AB,BA len=3 : ABA,BAB len=4 : ABAB,BABA len=5 : ABABA Thus, total number of distinct substrings is 9. Link to problem Solution below . . . Read more →

Competitive Programming: SPOJ – The Bulk!

 

ACM uses a new special technology of building its transceiver stations. This technology is called Modular Cuboid Architecture (MCA) and is covered by a patent of Lego company. All parts of the transceiver are shipped in unit blocks that have the form of cubes of exactly the same size. The cubes can be then connected to each other. The MCA is modular architecture, that means we can select preferred transceiver configuration and buy only those components we need . The cubes must be always connected “face-to-face”, i.e. the whole side of one cube is connected to the whole side of another cube. One cube can be thus connected to at most six other units. The resulting equipment, consisting of unit cubes is called The Bulk in the communication technology slang. Sometimes, an old and unneeded bulk is condemned, put into a storage place, and replaced with a new one. It… Read more →

Competitive Programming: SPOJ – Build the Fence

 

At the beginning of spring all the sheep move to the higher pastures in the mountains. If there are thousands of them, it is well worthwhile gathering them together in one place. But sheep don’t like to leave their grass-lands. Help the shepherd and build him a fence which would surround all the sheep. The fence should have the smallest possible length! Assume that sheep are negligibly small and that they are not moving. Sometimes a few sheep are standing in the same place. If there is only one sheep, it is probably dying, so no fence is needed at all … Input t [the number of tests <= 100] [empty line] n [the number of sheep <= 100000] x1 y1 [coordinates of the first sheep] … xn yn [integer coordinates from -10000 to 10000] [empty line] [other lists of sheep] Text grouped in [ ] does not appear in the input file.… Read more →

Competitive Programming: POJ 2185 – Milking Grid

 

Description Every morning when they are milked, the Farmer John’s cows form a rectangular grid that is R (1 <= R <= 10,000) rows by C (1 <= C <= 75) columns. As we all know, Farmer John is quite the expert on cow behavior, and is currently writing a book about feeding behavior in cows. He notices that if each cow is labeled with an uppercase letter indicating its breed, the two-dimensional pattern formed by his cows during milking sometimes seems to be made from smaller repeating rectangular patterns. Help FJ find the rectangular unit of smallest area that can be repetitively tiled to make up the entire milking grid. Note that the dimensions of the small rectangular unit do not necessarily need to divide evenly the dimensions of the entire milking grid, as indicated in the sample input below. Input Line 1: Two space-separated integers: R and C… Read more →

Competitive Programming: POJ 1147 – Binary Codes

 

Description Consider a binary string (b1…bN) with N binary digits. Given such a string, the matrix of Figure 1 is formed from the rotated versions of the string. b1 b2 … bN-1 bN b2 b3 … bN b1 … bN-1 bN … bN-3 bN-2 bN b1 … bN-2 bN-1 Figure 1. The rotated matrix Then rows of the matrix are sorted in alphabetical order, where ‘0’ is before ‘1’. You are to write a program which, given the last column of the sorted matrix, finds the first row of the sorted matrix. As an example, consider the string (00110). The sorted matrix is 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 0 0 1 1 1 0 0 0 and the corresponding last column is (1 0 0 1 0). Given this last column your program should determine the first row, which is… Read more →

Competitive Programming: POJ 1961 – Period

 

Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the largest K > 1 (if there is one) such that the prefix of S with length i can be written as AK, that is A concatenated K times, for some string A. Of course, we also want to know the period K. Input The input consists of several test cases. Each test case consists of two lines. The first one contains N (2 <= N <= 1,000,000) – the size of the string S. The second line contains the string S. The input file ends with a line, having the number zero on it. Output For each test case, output “Test… Read more →

Competitive Programming: POJ 2074 – Line of Sight

 

Description An architect is very proud of his new home and wants to be sure it can be seen by people passing by his property line along the street. The property contains various trees, shrubs, hedges, and other obstructions that may block the view. For the purpose of this problem, model the house, property line, and obstructions as straight lines parallel to the x axis: Input Because each object is a line, it is represented in the input file with a left and right x coordinate followed by a single y coordinate: <x1> <x2> <y> where x1, x2, and y are non-negative real numbers, x1 < x2 . An input file can describe the architecture and landscape of multiple houses. For each house, the first line will have the coordinates of the house. The second line will contain the coordinates of the property line. The third line will have a… Read more →

Competitive Programming: POJ 2318 – TOYS

 

Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem – their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys in, but John is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for John to find his favorite toys. John’s parents came up with the following idea. They put cardboard partitions into the box. Even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. The following diagram shows a top view of an example toy box. For this problem, you are asked to determine how many toys fall into each partition as John throws them into… Read more →

Next Page »