-
C1.1 Life Cycle Phases
-
C1.2 Development Models
-
C1.3 Specifications, Requirements
/* | |
* A number is prime if it is not divisible by any number other than 1 and | |
* itself. 1 is not prime. Thus you can test whether a number greater than 1 is | |
* prime by checking whether it is divisible by any smaller number greater than | |
* one. | |
*/ | |
public class Primes { | |
public boolean isPrime(int n) { |
import java.util.Scanner; | |
public class TicTacToe { | |
public static void printBoard(int board) { | |
System.out.print("\033[2J\033[0;0H"); | |
int pieces = board >> 4; | |
for (int i = 0; i < 9; i++) { | |
System.out.print(" " + (i + "XO").charAt((pieces >> i & 1 | pieces >> i + 8 & 2) & 3) + " "); | |
if (i % 3 < 2) { |
import java.util.Scanner; | |
/** | |
* Make a chatbot. See [1] for some background on chatbots. But write your code | |
* here in a Codespace, not in Replit. | |
* | |
* [1] https://runestone.academy/ns/books/published/BHSawesome/Unit3-If-Statements/magpieindex.html | |
*/ | |
public class Chatbot { |
import java.util.Scanner; | |
public class Change0 { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.print("Item 1 price: "); | |
double price1 = input.nextDouble(); |
import java.nio.charset.StandardCharsets; | |
public class Xor { | |
// This is the cipher text, encoded as a hex string. If you translate every two | |
// characters of this string into a byte you will have an array of bytes which | |
// can be decoded by xor'ing the bytes with bits from the key, taking first the 8 | |
// least significant bits of the key for the 0th byte, the the next 8, and so on, | |
// looping back around to the least significant bits every four bytes. | |
private static final String CIPHERTEXT = |
I needed to generate some data for a test I was writing for my Intro to Programming class. So I asked GPT (3.5 originally) just to give me a list of fruits and their colors. It provided me with a great list which I started to paste into my code and convert to JSON when I realized, GPT should be able to do that for me. So I asked it to and it did a great job.
Then I wanted to add some more attributes to my fruit data so I asked it this:
Q. Can you please describe how your implementation differs from, and is similar to, a program that generates text with a Markov Chain?
A. Yes, of course!
A Markov Chain is a mathematical system that undergoes transitions from one state to another according to certain probabilistic rules. In the context of text generation, a Markov Chain can be used to model the probability of seeing a certain word (or character) given the previous word (or character). Then, the text generator can use the model to randomly sample a sequence of words (or
/* | |
* Regexp to match a single HTML tag. | |
*/ | |
const tagPattern = /^<(\w+)>$/; | |
/* | |
* Get or create a single element. If the query is in the form of a tag, e.g. | |
* '<p>' it creates an element of that type. Otherwise it queries the document | |
* using the argument as a selector. | |
*/ |
// Church numerals -- functions of two arguments, a function and a zero value. | |
// The nth Church numeral applies an n-fold compostion f to the zero value. | |
const Zero = (f, z) => z; | |
const One = (f, z) => f(z); | |
const Two = (f, z) => f(f(z)); | |
const Three = (f, z) => f(f(f(z))); | |
// etc. | |
/* |