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

Teaching Computer Science: Inequality = Bad?

 

I’m volunteering a couple mornings a week in a high school computer science class . . .

Equality

“Why don’t schools and classes have sponsors?” I ask one of the teachers. “When my kid was in school, they were always complaining about not having enough money. So why couldn’t you, for example, come in and say, ‘Hey kids, before you come to 1st period, make sure you have a good breakfast at McDonald’s. I’m lovin’ it!’?

“And McDonald’s pays you 100 grand or whatever to say that.”

“My concern,” he says, “is that would lead to more inequality in education.”

I’m not sure he really thought that through. It seems more like a mechanical response to an abstract notion, i.e., “Inequality is bad.”

As a parent, I always supported inequality in education. I wanted my kid to get the best possible education, better than most other kids.

As a classroom volunteer, I want kids in my classes to get a better computer science education than kids in other classes where a computing professional is not present.

Does a teacher really think that students at his school should not be allowed to get a better education than students at other schools?

We Didn’t Even Have Indoor Plumbing

 

In October 2018, the Intergovernmental Panel on Climate Change (IPCC) released a special report on “the impacts of global warming of 1.5 degrees C above pre-industrial levels.”

“Pre-industrial levels” is defined in the report as the the period from 1850 to 1900.

Not explained in the report, unless I missed it, is why I should feel confident in the scientific precision of air and sea surface temperatures taken in the 19th century.

$15 Trillion for “Free” Healthcare

 

$300K = free healthcare for 60 people?! $50K per person?!

Multiply by 300 million Americans . . . check me on the math but isn’t that $15 trillion? For “free” healthcare?!?!?!

Here’s what it looks like if you write it out: $15,000,000,000,000.

Is this guy insane?!?!?!

And That’s the Truth: Believe Women

 
Sojourner Truth

[And That’s the Truth is a feature by our guest blogger, Sojourner Truth– PE]

Believe Women . . . I can’t help thinking about that poor boy Emmett Till.

And Norma McCorvey . . . lied about being raped so she could get an abortion. That’s before she became Jane Roe.

You never knowed a woman to tell a lie? To tell a lie to hurt someone?

Woman can do anything a man can do. Good or bad.

And that’s the Truth!

Spot the Fake News: Students Call For USC Professor To Be Fired

 
USC Seal

A professor at the University of Southern California has come under fire after sending a reply-all email last week to the student body stating “accusers sometimes lie.”

“If the day comes you are accused of some crime or tort of which you are not guilty, and you find your peers automatically believing your accuser, I expect you find yourself a stronger proponent of due process than you are now,” Professor James Moore wrote in the email. “Accusers sometimes lie.”

Nearly 100 students reportedly attended a rally called “Times Up for James Moore” on Monday in protest of Moore — who is tenured — demanding that he be fired.

Nearly 100 students! Not mentioned: USC has 44,000 students.

A more accurate way to frame this would be “Out of 44,000 USC students, 43,900 understand that a person whose political views are not a mirror image of their own can still be allowed to hold a job.”

In the Fake News Taxonomy, this falls under Misleading Content, i.e., misleading use of information to frame an issue/individual.

FIGHT ON!

EppsNet at the Movies: A Star is Born

 

OK, actually I haven’t seen A Star is Born and here’s why:

  1. When I go to the movies, I like to see something I’ve never seen before. I don’t care for sequels, prequels, reboots, spinoffs, adaptations of TV shows, video games, comic books or other movies.
  2. I don’t like love stories. I find them unrealistic. I read a lot and the books and authors I like mostly exclude the possibility of true love.
  3. What is worse than when you want to see a movie and someone spoils it by telling you how it ends? If you’re remaking A Star is Born for the fifth time, everyone already knows how it ends. You’ve spoiled your own movie.
 

A Star Is Born

A hard-drinking country music star falls in love with a singer whose career quickly takes off.

Director: Bradley Cooper
Cast: Lady Gaga, Bradley Cooper, Sam Elliott

IMDb rating: 7.6 (445763 votes)

To Make the Accusation is to Prove It. To Hear the Allegation is to Believe It.

 

Simply to make the accusation is to prove it. To hear the allegation is to believe it. No motive for the perpetrator is necessary, no logic or rationale is required. Only a label is required. The label is the motive. The label is the evidence. The label is the logic. Why did Coleman Silk do this? Because he is an x, because he is a y, because he is both. First a racist and now a misogynist. It is too late in the century to call him a Communist, though that is the way it used to be done. . . . That explains everything.

— Philip Roth, The Human Stain

They Submitted Fake Papers to Peer-Reviewed Journals — Here’s What Happened Next

 

Three writers produced 20 intentionally outlandish academic papers and submitted them to the best peer-reviewed journals associated with fields of scholarship loosely known as “cultural studies” or “identity studies” (for example, gender studies) or “critical theory.” Seven of the papers were accepted for publication and seven more were still under review when the authors elected to end the experiment.

Their point would seem to be that scholarship in these fields is based less upon finding truth and more upon attending to social grievances. Just about anything can be published, so long as it falls within the moral orthodoxy and demonstrates an understanding of the existing literature.

The authors summarize their methodology as follows. (I’ve inserted the material in brackets from elsewhere in the article, which you should look at in its entirety because there’s too much good stuff to summarize.)

What if we write a paper saying we should train men like we do dogs—to prevent rape culture? Hence came the “Dog Park” paper [titled “Human reactions to rape culture and queer performativity at urban dog parks in Portland, Oregon”]. What if we write a paper claiming that when a guy privately masturbates while thinking about a woman (without her consent—in fact, without her ever finding out about it) that he’s committing sexual violence against her? That gave us the “Masturbation” paper. [Sample reviewer comment: “For example, the ambiguous statement ‘I think about you all the time’ said unprompted to a woman by a man is particularly insidious given the structural context of metasexual violence in the world.”] What if we argue that the reason superintelligent AI is potentially dangerous is because it is being programmed to be masculinist and imperialist using Mary Shelley’s Frankenstein and Lacanian psychoanalysis? That’s our “Feminist AI” paper [Purpose: To see if journals will publish dense and incoherent psychoanalytic and postmodern theory that problematizes whiteness, maleness, science, and reason as oppressive.]. What if we argued that “a fat body is a legitimately built body” as a foundation for introducing a category for fat bodybuilding into the sport of professional bodybuilding? [Purpose: To see if journals will accept arguments which are ludicrous and positively dangerous to health if they support cultural constructivist arguments around body positivity and fatphobia.] You can read how that went in Fat Studies.

At other times, we scoured the existing grievance studies literature to see where it was already going awry and then tried to magnify those problems. Feminist glaciology? Okay, we’ll copy it and write a feminist astronomy paper that argues feminist and queer astrology should be considered part of the science of astronomy, which we’ll brand as intrinsically sexist. Reviewers were very enthusiastic about that idea. Using a method like thematic analysis to spin favored interpretations of data? Fine, we wrote a paper about trans people in the workplace that does just that. Men use “male preserves” to enact dying “macho” masculinities discourses in a way society at large won’t accept? No problem. We published a paper best summarized as, “A gender scholar goes to Hooters to try to figure out why it exists.” “Defamiliarizing” common experiences, pretending to be mystified by them and then looking for social constructions to explain them? Sure, our “Dildos” paper did that to answer the questions, “Why don’t straight men tend to masturbate via anal penetration, and what might happen if they did?” Hint: according to our paper in Sexuality and Culture, a leading sexualities journal, they will be less transphobic and more feminist as a result.

We used other methods too, like, “I wonder if that ‘progressive stack’ in the news could be written into a paper that says white males in college shouldn’t be allowed to speak in class (or have their emails answered by the instructor), and, for good measure, be asked to sit on the floor in chains so they can ‘experience reparations.’” That was our “Progressive Stack” paper. The answer seems to be yes, and feminist philosophy titan Hypatia has been surprisingly warm to it. Another tough one for us was, “I wonder if they’d publish a feminist rewrite of a chapter from Adolf Hitler’s Mein Kampf.” [Purpose: To see if we could find “theory” to make anything grievance-related (in this case, part of Chapter 12 of Volume 1 of Mein Kampf with fashionable buzzwords switched in) acceptable to journals if we mixed and matched fashionable arguments.] The answer to that question also turns out to be “yes,” given that the feminist social work journal Affilia has just accepted it.

The authors are Peter Boghossian, an assistant professor of philosophy at Portland State University, James Lindsay, a writer on atheism, and Helen Pluckrose, a writer who edits the online magazine Areo.

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 was recently found that ACM has many of such old bulks that just occupy space and are no longer needed. The director has decided that all such bulks must be disassembled to single pieces to save some space. Unfortunately, there is no documentation for the old bulks and nobody knows the exact number of pieces that form them. You are to write a computer program that takes the bulk description and computes the number of unit cubes.

Each bulk is described by its faces (sides). A special X-ray based machine was constructed that is able to localise all faces of the bulk in the space, even the inner faces, because the bulk can be partially hollow (it can contain empty spaces inside). But any bulk must be connected (i.e. it cannot drop into two pieces) and composed of whole unit cubes.

Input

There is a single positive integer T on the first line of input (equal to about 1000). It stands for the number of bulks to follow. Each bulk description begins with a line containing single positive integer F, 6 <= F <= 250, stating the number of faces. Then there are F lines, each containing one face description. All faces of the bulk are always listed, in any order. Any face may be divided into several distinct parts and described like if it was more faces. Faces do not overlap. Every face has one inner side and one outer side. No side can be “partially inner and partially outer”.

Each face is described on a single line. The line begins with an integer number P stating the number of points that determine the face, 4 <= P <= 200. Then there are 3 x P numbers, coordinates of the points. Each point is described by three coordinates X,Y,Z (0 <= X,Y,Z <= 1000) separated by spaces. The points are separated from each other and from the number P by two space characters. These additional spaces were added to make the input more human readable. The face can be constructed by connecting the points in the specified order, plus connecting the last point with the first one.

The face is always composed of “unit squares”, that means every edge runs either in XY or Z-axis direction. If we take any two neighbouring points X1,Y1,Z1 and X2,Y2,Z2, then the points will always differ in exactly one of the three coordinates. I.e. it is either X1 <> X2, or Y1 <> Y2, or Z1 <> Z2, other two coordinates are the same. Every face lies in an orthogonal plane, i.e. exactly one coordinate is always the same for all points of the face. The face outline will never touch nor cross itself.

Output

Your program must print a single line for every test case. The line must contain the sentence The bulk is composed of V units., where V is the volume of the bulk.

Example

Sample Input:

2
12
4  10 10 10  10 10 20  10 20 20  10 20 10
4  20 10 10  20 10 20  20 20 20  20 20 10
4  10 10 10  10 10 20  20 10 20  20 10 10
4  10 20 10  10 20 20  20 20 20  20 20 10
4  10 10 10  10 20 10  20 20 10  20 10 10
5  10 10 20  10 20 20  20 20 20  20 15 20  20 10 20
4  14 14 14  14 14 16  14 16 16  14 16 14
4  16 14 14  16 14 16  16 16 16  16 16 14
4  14 14 14  14 14 16  16 14 16  16 14 14
4  14 16 14  14 16 16  16 16 16  16 16 14
4  14 14 14  14 16 14  16 16 14  16 14 14
4  14 14 16  14 16 16  16 16 16  16 14 16
12
4  20 20 30  20 30 30  30 30 30  30 20 30
4  10 10 10  10 40 10  40 40 10  40 10 10
6  10 10 20  20 10 20  20 30 20  30 30 20  30 40 20  10 40 20
6  20 10 20  20 20 20  30 20 20  30 40 20  40 40 20  40 10 20
4  10 10 10  40 10 10  40 10 20  10 10 20
4  10 40 10  40 40 10  40 40 20  10 40 20
4  20 20 20  30 20 20  30 20 30  20 20 30
4  20 30 20  30 30 20  30 30 30  20 30 30
4  10 10 10  10 40 10  10 40 20  10 10 20
4  40 10 10  40 40 10  40 40 20  40 10 20
4  20 20 20  20 30 20  20 30 30  20 20 30
4  30 20 20  30 30 20  30 30 30  30 20 30

Sample Output:

The bulk is composed of 992 units.
The bulk is composed of 10000 units.

Warning: large Input/Output data, be careful with certain languages

Link to problem

Solution below . . .

Read more