EppsNet Archive: Programming

Competitive Programming: POJ 1426 – Find The Multiple

18 Apr 2018 /

Description

Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.
Input

The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.

Output

For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple solutions for a given value of n, any one of them is acceptable.

Sample Input

2
6
19
0

Sample Output

10
100100100100100100
111111111111111111

Link to problem

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * There are at least 3 ways to solve this:
 * 
 * 1. NUMERICAL METHODS
 * 
 * I found several links to numerical methods and couldn't understand any of them.
 * Here's a sample:
 * 
 * https://math.stackexchange.com/questions/164986/smallest-multiple-whose-digits-are-only-ones-and-zeros
 * 
 * 2. CHEAT
 * 
 * Input is guaranteed to be no more than 200, and results have been computed 
 * for far more numbers than that (see http://oeis.org/A004290/b004290.txt). 
 * Put the answers in a hash table and just look them up.
 * 
 * 3. BREADTH-FIRST SEARCH (BFS)
 * 
 * Every node of the search tree will be a binary digit number. For each number x, 
 * the next-level nodes will be x0 and x1 (x concatenated with 0 and 1).
 * 
 * We start by adding 1 to the queue, which will then add 10 and 11 and so on.
 * After taking a number from the queue, we’ll check whether the number is a 
 * multiple of the given number or not. If yes, we have our answer.
 * 
 * Optimization: we're using a set for mod values. If a number has a 
 * previously seen mod value, we don’t add this new number to the queue. 
 * Explanation: Let x and y be numbers that give the same value mod N. 
 * Let x < y. Let z be another number which, when appended to y gives a 
 * number divisible by N. Then we can also append this number to x and 
 * get a number divisible by N. So we can safely ignore y.
 * 
 * NOTE: The sample outputs given for inputs 6 and 19 are "acceptable" but 
 * much smaller answers are available. 
 * 
 */

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	// returns smallest multiple which has
	// only 1s and 0s
	static long getMinimumMultiple(int N)
	{
		Deque<Long> q = new ArrayDeque<Long>();
		Set<Long> visit = new HashSet<Long>();
	 
	    long t = 1;
	 
	    //  starting with 1 in queue
	    q.add(t);
	 
	    //  loop while queue is not empty
	    while (!q.isEmpty())
	    {
	        // Take the first number from queue.
	        t = q.pop();
	 
	        // Find remainder of t with respect to N.
	        long rem = t % N;
	 
	        // if remainder is 0 then we have
	        // found our solution
	        if (rem == 0)
	            return t;
	 
	        // If this remainder is not previously seen,
	        // then add t + '0' and t + '1' to queue
	        else if(!visit.contains(rem))
	        {
	            visit.add(rem);
	            q.add(t * 10);
	            q.add(t * 10 + 1);
	        }
	    }
	    return -1; //something went wrong
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		while (N != 0) {
			System.out.println(getMinimumMultiple(N));
			N = sc.nextInt();
		}
		
		sc.close();
	}
}

Competitive Programming: POJ 2084 – Game of Connections

18 Apr 2018 /

Description

This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, . . . , 2n – 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another. And, no two segments are allowed to intersect.

It’s still a simple game, isn’t it? But after you’ve written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?

Input

Each line of the input file will be a single positive number n, except the last line, which is a number -1.
You may assume that 1 <= n <= 100.

Output

For each n, print in a single line the number of ways to connect the 2n numbers into pairs.

Sample Input

2
3
-1

Sample Output

2
5

Link to problem

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.math.BigInteger;
import java.util.Scanner;

/*
 * There are two ways to solve it.
 * 
 * 1. RECURSIVE
 * 
 * Select a fixed point O from one of the 2n points on the circle. A line going 
 * from this point would have to divide the circle into two regions, each 
 * containing an even number of points. There are thus n possible choices for a 
 * chord leaving from O (try drawing it).
 * 
 * Choosing one such chord will lead to unique divisions of the circle (two 
 * different chords leaving from O will give different divisions). Any division 
 * of the circle would match with one of these chords. So we have divided the 
 * problem into a set of disjoint subproblems.
 * 
 * Then, to get a recursive formula, we need to count, for each possible chord,
 * how many points are on each side of the chord : the regions have 
 * (2k, 2(n?k?1)) points, for 0 ? k ? n?1.
 * 
 * So a recursive formula for h(n) would be:
 * 
 *      h(n) = sum, from k = 0 to k = n-1, of h(k) * h(n?k?1)
 *      
 * 2. CLOSED FORM
 * 
 * The solution is the set of Catalan numbers. The nth Catalan number can be 
 * calculated directly as:
 * 
 *     the product, from k = 2 to k = n, of (n + k) / k
 *     
 * NOTE: We use BigIntegers because Catalan numbers get big very quickly. 
 * (See https://oeis.org/A000108)
 *  
 */
public class Main {

	static BigInteger catalan(int n) {

		// dp array containing the sum
		BigInteger[] dpArray = new BigInteger[n + 1];

		dpArray[0] = BigInteger.ONE;
		dpArray[1] = BigInteger.ONE;

		for (int i = 2; i <= n; i++) {
			dpArray[i] = BigInteger.ZERO;

			for (int k = 0; k < i; k++) {
				dpArray[i] = dpArray[i].add(dpArray[k].multiply(dpArray[i - k - 1]));
			}
		}

		return dpArray[n];
	}

	static BigInteger catalanClosedForm(int n) {

		if (n <= 1)
			return BigInteger.ONE;

		BigInteger num = BigInteger.ONE;
		BigInteger denom = BigInteger.ONE;
		
		for (int k = 2; k <= n; k++) {
			num = num.multiply(new BigInteger((n + k) + ""));
			denom = denom.multiply(new BigInteger(k + ""));
		}
		
		return num.divide(denom);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		while (n != -1) {
			System.out.println(catalan(n).toString());
			n = sc.nextInt();
		}
		sc.close();
	}
}

Competitive Programming: POJ 1654 – Area

16 Apr 2018 /

Description

Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, …. In a subtree whose root node is X, we can get the minimum number in this subtree by repeating going down the left node until the last level, and we can also find the maximum number by going down the right node. Now you are given some queries as “What are the minimum and maximum numbers in the subtree whose root node is X?” Please try to find answers for the queries.

BST

Input

In the input, the first line contains an integer N, which represents the number of queries. In the next N lines, each contains a number representing a subtree with root number X (1 <= X <= 231 – 1).

Output

There are N lines in total, the i-th of which contains the answer for the i-th query.

Sample Input

2
8
10

Sample Output

1 15
9 11

Link to problem

import java.util.Scanner;

/*
There's a pattern with the lowest-order set bit of the numbers:
  - For leaf-node numbers, the lowest order set bit is 1.
  - Go up one level and the lowest order set bit is 2.
  - Go up one more level and the lowest order set bit is 4.
  - Etc.

That said, we can take advantage of Bit Hack #7 from 
http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
to isolate the lowest-order set bit.

Each node will have one less than that number of nodes in each subtree.
 */

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		while (N-- > 0) {
			int x = sc.nextInt();
			int diff = (x & (-x)) -1;
			System.out.println((x - diff) + " " + (x + diff));
		}

		sc.close();
	}
}

Competitive Programming: POJ 2242 — The Circumference of the Circle

14 Apr 2018 /

Description

To calculate the circumference of a circle seems to be an easy task – provided you know its diameter. But what if you don’t?

You are given the cartesian coordinates of three non-collinear points in the plane.
Your job is to calculate the circumference of the unique circle that intersects all three points.

Input

The input will contain one or more test cases. Each test case consists of one line containing six real numbers x1,y1, x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.

Output

For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.

Sample Input

0.0 -0.5 0.5 0.0 0.0 0.5
0.0 0.0 0.0 1.0 1.0 1.0
5.0 5.0 5.0 7.0 4.0 6.0
0.0 0.0 -1.0 7.0 7.0 7.0
50.0 50.0 50.0 70.0 40.0 60.0
0.0 0.0 10.0 0.0 20.0 1.0
0.0 -500000.0 500000.0 0.0 0.0 500000.0

Sample Output

3.14
4.44
6.28
31.42
62.83
632.24
3141592.65

Link to problem

import java.util.Scanner;

public class Main
{
	static final double EPS = 1e-12;

	static double dot(PT p, PT q) {
		return p.x * q.x + p.y * q.y;
	}

	// distance squared
	static double dist2(PT p, PT q) {
		return dot(p.subtract(q), p.subtract(q));
	}

	static double cross(PT p, PT q) {
		return p.x * q.y - p.y * q.x;
	}

	static PT RotateCW90(PT p) {
		return new PT(p.y, -p.x);
	}

	// compute intersection of line passing through a and b
	// with line passing through c and d, assuming that unique
	// intersection exists; for segment intersection, check if
	// segments intersect first
	static PT ComputeLineIntersection(PT a, PT b, PT c, PT d) {
		b = b.subtract(a);
		d = c.subtract(d);
		c = c.subtract(a);
		assert (dot(b, b) > EPS && dot(d, d) > EPS);
		return a.add(b.multiply(cross(c, d)).divide(cross(b, d)));
	}

	// compute center of circle given three points
	static PT ComputeCircleCenter(PT a, PT b, PT c) {
		b = (a.add(b)).divide(2);
		c = (a.add(c)).divide(2);
		return ComputeLineIntersection(b, b.add(RotateCW90(a.subtract(b))), c,
						c.add(RotateCW90(a.subtract(c))));
	}

	public static void main(String[] args) {
		
//		long start = System.currentTimeMillis();

		Scanner sc = new Scanner(System.in);
		Scanner lineTokenizer;
		
		while (sc.hasNextLine()) {
			lineTokenizer = new Scanner(sc.nextLine());
			
			PT p1 = new PT(lineTokenizer.nextDouble(), lineTokenizer.nextDouble());
			PT p2 = new PT(lineTokenizer.nextDouble(), lineTokenizer.nextDouble());
			PT p3 = new PT(lineTokenizer.nextDouble(), lineTokenizer.nextDouble());
			
			lineTokenizer.close();
			
			PT center = ComputeCircleCenter(p1, p2, p3);
			
			// distance from point to center
			double radius = Math.sqrt(dist2(p1, center));
			
			System.out.printf("%.2f\n", Math.PI * radius * 2);
		}
		
		sc.close();
//		System.out.println("$:" + (System.currentTimeMillis() - start));
		}
}

class PT {
	double x, y;

	PT() {
	}

	PT(double x, double y) {
		this.x = x;
		this.y = y;
	}

	PT(PT p) {
		this.x = p.x;
		this.y = p.y;
	}

	PT add(final PT p) {
		return new PT(x + p.x, y + p.y);
	}

	PT subtract(final PT p) {
		return new PT(x - p.x, y - p.y);
	}

	PT multiply(double c) {
		return new PT(x * c, y * c);
	}

	PT divide(double c) {
		return new PT(x / c, y / c);
	}

	@Override
	public String toString() {
		return "(" + x + "," + y + ")";
	}
}

Teaching Computer Science: How to Get Top-Notch Teachers in the Classroom

23 Mar 2018 /
Woman teaching geometry, from Euclid's Elements.

Woman teaching geometry, from Euclid’s Elements.

I read something every day where educators and/or elected officials are talking about the importance for our kids, our country, our future, etc., of teaching computer science, the sticking point being an extreme shortage of qualified teachers.

A person entering the workforce with a computer science degree is unlikely to go into teaching because of the opportunity cost: they can earn a lot more money as a software engineer.

The likelihood of getting a mid-career tech industry professional to switch into teaching is even lower. Teacher salaries are based in large part on years of service. A mid-career person switching into teaching is not going to get a mid-career teacher’s salary, they are going to get a first-year teacher’s salary.

So here’s the idea:

Give CS professionals the opportunity to apply their years in industry to years of service as a teacher.

It’s still a pay cut going from software engineering to teaching but it’s on a scale that people may be willing to take if they’re looking for a new direction in life. It’s not a pay cut to back when you were 22 years old and right out of college.

What’s the alternative? Schools can’t attract qualified CS teachers so they’re taking in-service teachers and sending them to a workshop for a few days to learn to be computer science teachers.

It’s like hiring music teachers who aren’t musicians, or Spanish teachers who don’t speak Spanish.

Are you going to have a good CS program if it’s run by someone whose only connection to the subject is a five-day workshop? No. Are kids going to get excited about computer science? No. How could they? The teacher isn’t even excited about computer science.

How can these teachers know if what they’re teaching is valuable, or how well they’re teaching it?

 

Programming is difficult, there’s no way around that. The first programming class I took in college had a 75 percent drop rate.

The essential difficulty is that we’re used to giving instructions to other humans. If our instructions are less than perfect and we leave out some details, people can still probably figure out what to do. If we send a text or an email with a grammatical error or a typo, the recipient can figure it out.

Computers can’t figure it out. If you’re giving instructions to a computer, everything has to be perfect and you can’t leave anything out. It’s not a natural mindset, operating at that level of detail.

UC Berkeley offers a CS class, intended for non-majors, called The Beauty and Joy of Computing, the idea being that yes, programming is hard, but it also opens up new ways for people to connect, design, research, play, create and express themselves, to translate ideas into code.

You can’t get the beauty and joy and challenge and fun of computing across to students via teachers who just learned programming at a week-long workshop last summer. The only thing that comes across is how difficult it is.

Introducing kids to computer science and programming in this way may be worse than not teaching CS at all. Kids decide pretty quickly that programming is too hard, it’s boring, they’re not smart enough, they don’t have the right aptitude, their efforts are not rewarded and they don’t want to have anything to do with it because it makes them feel bad about themselves.

Computer science is not unique in this respect, but it’s less about presenting “material” and more about conveying a way of thinking. Teachers can’t convey a way of thinking when they don’t genuinely think that way.

If teaching CS is important, provide an incentive to get qualified teachers in the classroom, who can teach what they do, teach something that is part of their life, teach something that is personal and valuable to them, and pass on their own insights and experience.

Thus spoke The Programmer.


Teaching Computer Science: The Phones Aren’t Helping You

15 Feb 2018 /

I’m volunteering a couple mornings a week at a local high school, helping out with computer science classes.

The way the classes are taught, via an online curriculum, provides a great temptation to kids to get off-task, which they do, usually by entertaining themselves with their phones.

They get off-task in other ways too — web surfing, doing homework for other classes — but the main distractor is the phones . . .

 

“As I mentioned before, I worked with another CS class a couple years ago. No phones allowed in the classroom.

Students with cell phones

“I remember one day the assistant principal was in class observing . . . a student had a phone out, looking at it . . . he was holding it under the table so no one could see it, but this guy, the assistant principal, he did see it.

“Oh man, did he hit the roof! If a student had pulled out a gun, there couldn’t have been any more excitement in the room.

“I thought that was overkill at the time. But I have to tell you that those kids kicked ass on the AP exam. Can I say that? That was the CS A test. Hard test.

“Most of the students got a 5. Most of the students who didn’t get a 5 got a 4. Nobody got a 3, one student got a 2 and, out of about 35 students, 6 of them got a 1, including the guy who spent 47 hours playing video games instead of studying. What did you expect, right?

“Now you guys may crush it on the AP test too. We don’t know yet.

“A lot of programmers have a phone in view when they’re working . . . a lot of programmers listen to music, sometimes through their phone . . . but nobody has the phone in their hand looking at it every minute, you’d never get anything done.

“So it depends what your goals are. If your goal is to get a top score on an AP exam, I don’t think you’re helping yourself with the phones.”


Teaching Computer Science: When You Need Help, Ask For Help

1 Feb 2018 /

I’m volunteering a couple mornings a week at a local high school, helping out with computer science classes.

It’s a mixed class . . . most of the students are taking AP Computer Science Principles, and about 10 kids just recently started a second-semester Visual Basic class.

Help

The VB kids were pretty inquisitive at first but started to get discouraged . . . in my opinion because of the way the material is presented to them via an online curriculum.

The current approach to teaching computer science in American schools, because of the shortage of (I almost said “lack of”) qualified teachers is to use packaged courses delivered to students online.

My observation is students assume that because they’ve been put in front of a computer full of lessons, they’re expected to be able to read and understand the material and complete the assignments on their own with no help.

This is a fatal misconception. The material is too difficult for most people who are not already programmers, so the kids decide pretty quickly that they just don’t have what it takes to learn the stuff.

“Tragedy” is probably too strong a word for what is happening in computer science education, but programming is what I do, I think programming and computational thinking are important and valuable skills, and it makes me sad to see them taught in a way that crushes students’ enthusiasm.

 

Brief digression: I take piano lessons. My teacher is a musician, a pianist. Music is part of her life, it’s part of who she is, part of how she thinks. How could someone who’s not a musician teach music?

How can someone who’s not a programmer teach computer science?

 

Because of everything I’ve said above, along with offering technical assistance, I try to encourage kids to stay engaged . . .

UC Santa Barbara

“I’m going to tell you a story,” I said this morning. “First I’ll tell you the moral of the story, then I’ll tell you the story. The moral is: When you need help, ask for help.

“That may seem obvious but I feel like some of you are thinking that you should be working through online lessons with a lot of independence.

“I worked with a class a couple years ago at another school. One of the students there was very quiet but she always asked for help when she needed help. She asked quietly, but she asked.

“And when I gave her an answer, she almost always asked ‘why?’ I don’t mean ‘why why why’ like a 5-year-old, but if she didn’t understand why something was important or why you’d want to do something one way and not another way, she asked why.

“It’s a good question because if the only reason for doing something is because I said to do it, what is she going to do if I’m not there?

“What happened to this girl? She’s now a computer science major at UC Santa Barbara. She was able to do that because she didn’t give up on herself when she didn’t understand something and because, even though she wasn’t the most naturally outgoing person she decided to own her own results and use the resources that were available.”

“You’ve got to own it, kids. When you need help, ask for help. Don’t give up on yourself.”

Thus spoke The Programmer.


Teaching Computer Science: Asking for Help

9 Jan 2018 /

I’m volunteering a couple mornings a week at a local high school, helping out with computer science classes.

Cell phone

This morning, in AP Computer Science Principles, the teacher went through an explanation of the hexadecimal number system, then gave an in-class assignment for students to convert their cell phone number to hexadecimal. Not in two parts, 3 digits and 4 digits, but as a 7-digit number.

It seemed pretty obvious from the interaction and the body language and the looks on their faces that a lot of students didn’t get it, but in a class of 25 students, only one student asked for help. Until the teacher finished with that student and asked “Does anyone else need help?” and eight more students immediately raised their hand.

I asked the teacher, “Can I address the class for a minute?”

 

“First off, doing a 7-digit hex conversion is not easy. I know professional programmers who can’t do it. So I’d expect someone trying to do it for the first time to need some help.

“In fact, if you know any professional programmers, ask them to do a hex conversion on their phone number. Let me know what happens. I guarantee you won’t have to ask too many people before you stump someone.

Snap programming

“None of the material in this class is easy. Snap programming? You might look at it and think ‘There’s a cat and a fish and a duck . . . I’m not understanding it but it looks like a program for 5-year-olds. It’s embarrassing as a high school student to have to ask for help with it. Maybe I’m not very smart.’

“No, Snap is a university-level curriculum from Berkeley. Academically rigorous. I worked through the assignments myself and I found them pretty challenging. I’d expect many of you to find them challenging as well. So you should be asking for help.

“If you need help, waiting for someone to ask if you need help is not going to be a winning strategy. In school, in life or in anything. Because if no one asks, then you need help and you don’t get it.

“There’s probably a natural reluctance to ask questions because what if I’m the only person who doesn’t know the answer? Then I ask a question and look foolish.

“It’s going to be unusual in any class that you’re the only person who doesn’t understand something. If you find that happens to you a lot, you may have a problem. But normally it’s going to be pretty unusual.

“I can tell you in this class, there’s definitely more than one person who finds the material pretty challenging. As I said, I find it pretty challenging myself. It’s not so challenging that I need help with it, but it’s definitely challenging enough that I’d expect most people who are not programmers to need help with it.

Hexadecimal

“I’m also hearing some people today saying to themselves or to the person next to them, ‘Why do we need to know this?'” That’s actually a very good question. Binary of course is the fundamental language of computers, but why would you need to know hexadecimal? Anyone?”

No hands go up.

“OK, we’ll talk about that in a minute. If it’s not clear to you, in this class or any class, why you’re being asked to learn something, put your hand up and insist on understanding the relevance.

“One final anecdote:

“I worked with an AP class a couple of years ago at another school. About this same timeframe, late first semester, I was in class on a Monday and before the class started, one of the students asked me, ‘How was your weekend?’

“I said, ‘It was okay. How was yours?’

“‘It was great! I played like 47 straight hours of [some video game I can’t remember the name of].’

“And he was one of the worst students in the class, maybe the worst.

“I know he and his parents had met with the principal and the teacher to figure out why he was doing so poorly in computer science. It had to be the school’s fault, right?

“So I’m trying to wrap my mind around this. You played 47 hours of video games, you have no idea what’s going on in this class, and it’s the teacher’s fault?!

“No, it’s your fault. You put nothing into it so you get nothing out of it, you don’t ask for help, and that’s why you’re failing.

“Moral of the story: Don’t be that guy.

Thus spoke The Programmer.


Teaching Computer Science: It’s Not Easy to Teach a Subject in Which You Have No Training

29 Dec 2017 /
Mr. Rex Manihera, a teacher at the Glendowie South Primary School at Auckland

A recent issue of Science has an article on the pipeline for computer science teachers . . .

The first sentence says, “It’s not easy to teach a subject in which you have no training.”

That could be the whole article, really. That’s about all you need to know about the current state of computer science instruction: It’s not easy to teach a subject in which you have no training.

Cameron Wilson, chief operating officer and president of the Code.org Advocacy Coalition, is quoted as saying, “It’s really hard to convince a computer science professional to give up a job that pays up to three times more to pursue teaching. And I don’t think we should.”

Wilson’s opinion that computer science classes should not be taught by someone who actually knows something about computer science is probably influenced by the fact that Code.org is one of the leading providers of training programs and online curricular resources for in-service teachers tasked with teaching computer science.

How would this “train a neophyte” scheme work in other academic areas?

Assuming you could provide a one- or two-week training workshop to prospective teachers, would you:

  • Hire someone who has never played an instrument to teach a music class?
  • Hire someone who has never picked up a drawing pencil to teach an art class?
  • Hire someone who doesn’t speak Spanish to teach a Spanish class?

These all seem like absurd ideas with a very low ceiling on what you could hope to accomplish pedagogically. Why does anyone think it makes sense for computer science? Someone needs to explain that to me.

Putting non-practitioners in the CS classroom also requires, in addition to the teacher training, a second key component: the prefabricated curriculum.

Teachers are not able to design and teach a year-long class on a subject in which they have themselves only a week or two of experience, so Code.org and others offer packaged courses delivered to students online.

I’ve had an opportunity to see this in action. I volunteer two mornings a week at a local high school, helping out with the first period computer science class. It’s a mixed class, with most of the students taking AP Computer Science Principles, and a handful of kids taking an introductory programming class in Python.

The AP students are using UTeach, supplemented by the Berkeley BJC curriculum. The Python students are using CodeHS.

The teacher, a converted math teacher, does little to no independent instruction during the class period.

The material is too hard in my opinion for most people who are not programmers to read and understand and to figure out the assignments without a lot of help. Keep in mind that the teacher is also not a programmer.

The first two programming classes I took in college had a ~75 percent drop rate. Programming is hard but it can also be fun and beautiful. I don’t think a teacher who is not a programmer is able to convey that. Minus the beauty and fun, there’s nothing left but the difficulty.

I don’t see most students having what it takes to push themselves through difficult material delivered to them via a computer screen with no human interaction.

They give up and they blame themselves. I’m not smart enough for this. I don’t have what it takes.

It’s discouraging to see this because even kids who are not going to be programmers can learn useful ways of thinking about and solving problems from a computer science class . . .

  • How to break down complex problems into manageable parts
  • How to recognize patterns among and within problems
  • How to recognize important information vs. irrelevant detail
  • How to develop step-by-step solutions to a problem, or rules to follow to solve a problem

It’s a way of thinking that can’t be taught by someone who doesn’t genuinely think that way.

Thus spoke The Programmer.


More Words and Phrases I’m Sick Unto Death Of

13 Oct 2017 /

Although I can’t claim never to have said these things myself, if I had a dollar for every time I’ve heard someone say either a) “It was working fine 10 minutes ago,” or b) “It works okay on my machine,” I would be comfortably retired by now.

Thus spoke The Programmer.


What Does a Programmer Do?

8 Oct 2017 /

I was asked to give a talk last week to a high school computer science class on “What Does a Programmer Do?” (I’m indebted to Jim McCarthy for the “lords and ladies of logic” section.)

 

Programming is problem solving.

Programmer

At the highest level, the problem that programmers solve is that people want to be able to do things with computers that they can’t do. And by computers, I don’t mean just the kind of computers you have on the desks here, I mean phones, watches, cars . . . more and more different kinds of devices are running software.

So one good thing about being a programmer is that pretty much every field of endeavor now uses software and data.

You can work at a tech company like Microsoft or Google or Twitter or Facebook, but you can also work in healthcare, finance, education, sports . . . you can work on cancer research, you can write video games . . . everybody uses software and everybody hires programmers.

Programming is a good job if you want to be learning new things all the time, if you don’t want to do the same things over and over.

The dark side of this is that it can be daunting trying to keep up with the pace of technological change. It can be overwhelming.

I was asked once in an interview, “What’s the coolest thing you’ve learned in the last week?” If you haven’t learned anything in the last week, it’s hard to answer that question, let alone if you haven’t learned anything in a month or a year. It’s easy to let your career slip away from you.

Programming has been a good job for me because I’ve been able to make a living doing things I like and things that I’m good at. I’ve always liked solving problems and building things.

To me that’s a good job: you do things you like and things that you’re good at. I don’t think most people can say that. Most people seem to be like “I hate Mondays,” “Thank god it’s Friday,” “Thank god it’s Thursday because it’s almost Friday.” If you spend a lot of time doing things you don’t like and you’re not good at, that’s a bad job.

As a programmer, you’re given problems to solve and a set of tools with which to solve them. You need to be able to figure out “what do i need to do, what do I need to learn, to be able to solve these problems with these tools?”

Self-reliance is good. Persistence is good. Floundering is bad. Know when to ask for help.

Asking for help is a no-lose strategy. Worst case, you ask for help and someone can’t help you or won’t help you, but you’re not any worse off than you were in the first place.

The demand for programmers exceeds the supply and it doesn’t look like that’s going to change anytime soon.

Nearly 30 percent of Americans ages 18 to 24 cannot locate the Pacific Ocean on a map, and 25 percent of Americans think the sun goes around the earth. Those people are not going to be programmers.

In a time of ubiquitous software and intellectual lethargy, programmers are like the priests in the Middle Ages. We are the lords and ladies of logic. We’re in charge of rationality for our era. We’re bringing common sense and sound judgment and aggregated wisdom and glory to everyone.

That’s our job.


I’m a Winner!

23 May 2017 /

I’ve been doing the daily challenges at CodeFights for quite a while and yesterday’s challenge is the first time I got first place! (CodeFights ranks solutions by fewest number of characters, with solution time as the tiebreaker.)

Codefights leader board


AP Computer Science Revisited

6 Feb 2017 /

I got a LinkedIn invitation today from a student I taught in an AP Computer Science class a couple of years ago.

She’s now a computer science major at UCSB. Several of the kids from that class are now in college as computer science majors. Some of them would have been computer science majors anyway, without the class — they came in already having programming interest and experience — but this young lady was not in that group.

She was quiet in class but when I worked with her one on one, she asked a lot of questions. She asked them quietly but she asked. And when I told her to do something a certain way she always asked why.

She only has four connections at this time so I appreciate her thinking of me. 🙂

LinkedIn


Learn to Code

24 Jan 2017 /

I’m a programmer . . .

Job searches for me go like this: I’m old, I have to compete with people half my age, but I’ve worked in Orange County since forever so I know some people, and I can write good code in interviews, which the majority of programmers who show up for interviews can’t.

I was out of work on January 5. It’s now January 24. I have three job offers and picked the one I like best.

Moral of the story: Learn to code, kids . . .

Thus spoke The Programmer.


See You in Hell

15 May 2016 /

Satan

[See You in Hell is a feature by our guest blogger, Satan — PE]

Along with pleas for money, almost 100 percent of the cardboard signs I see being held by people on freeway off-ramps and the like include the phrase “God Bless You.”

There seems to be a correlation between belief in God and begging for money on off-ramps. Notice that you never see Satanists begging for money.

Why don’t they pray for the money? Maybe they did pray and God told them to make a cardboard sign?

I tell my acolytes if they need money, learn to code.

See you in Hell . . .


Programmer or Parolee?

15 Mar 2016 /

Our office building is next door to a probation field office . . .

I have a game I play in the parking lot each morning: Programmer or Parolee. I spot someone, guess if he’s here for a programming challenge or a meeting with his parole officer, then wait to see if he shows up in our office.

If a methed-out skinhead comes in for a programming challenge, I lose today’s game.


Teaching Prisoners to Code: What Could Go Wrong?

22 Feb 2016 /

What could go wrong here? Criminal minds + coding skills = ???

One of my favorite Mr. Boffo cartoons shows a gang of robbers in a bank in the Old West . . . one of the robbers says to another, “Someday this will all be done by computer.”

What an inspiring program to solve a big and growing U.S. problem.

Posted by Code.org on Sunday, February 21, 2016


Kidneys for Coders

22 Dec 2015 /

Cartoon


The Ceiling Seems Very Low

10 Sep 2015 /

http://www.usatoday.com/story/tech/2015/09/10/codeorg-hadi-partovi-computer-science-back--school-kids-teachers-women-minorities/71905738/

I don’t know if this is good news or bad news. It would help to know what “trains” means but I read the article and it doesn’t say. Reporters need to be more inquisitive.

Can someone with no knowledge of computer science or programming be “trained” to teach computer science or programming? What would that entail? How long would it take?

Can someone who’s never played an instrument or listened to a piece of music be “trained” to teach a music class?

Can someone who’s never picked up a drawing pencil or visited a museum be “trained” to teach an art class?

Can someone who doesn’t speak Spanish be “trained” to teach a Spanish class?

The ceiling on any of these approaches seems very low compared to hiring actual programmers, musicians, artists and Spanish speakers . . .

Thus spoke The Programmer.


Hey Guys, I Wrote a Book!

27 Jul 2015 /

It’s called Thus Spoke the Programmer: A Fictional Memoir. (Don’t be put off by the title if you’re not a programmer. It’s guaranteed to delight both technical and non-technical readers alike. 🙂 )

If you’re interested in having a look at it, you have a couple of options:

  1. Leanpub, a PWYW (pay what you want) platform, which means if you want to read the book for free, you can download it and read it for free.
  2. Amazon, available in paperback or Kindle format (not free).

Next Page »