Sure, I'd be happy to help you with that! What is it that you would like the program to produce? Can you provide an example of the desired output? Additionally, what programming language are you working with? This will help me guide you in
Just because someone wanted to see Perl...
If he can explain to his prof how it works, then he deserves to get credit for it.
EDIT: I’m humbled that >300k have scanned my post. I didn’t expect there to be that much interest in Perl anymore.
- #!/usr/bin/perl
- $hell = sub { $o=""; foreach(@{$_[0]}) { $o .= chr($_); } return $o; };
- $z = 0b100;
- $x = [0123];
- $x->[1] = 0x6d;
- $x->[2] = $$x[1] & ~$z;
- push @$x, @$x[1,2];
- $y = \$$x[$z];
- $x->[0b11]--;
- $$y -= $z;
- $x->[05] = (666>>$z)-($z<<1);
- while(--$z) { for(1..$z) { print $hell->($x); } print $/; }
I'm surprised no one has responded with pseudocode yet...
1. Print Smile Smile Smile
2. Print Smile Smile
3. Print Smile
4. TODO: Look into for loops
5. TODO: Look into exclamation points.
6. TODO: Look into printing a newline between steps.
Glad you asked, this is pretty easy in Haskell. Here’s my solution you should easily be able to expand on.
- -- This is a nice problem that we can write a very easy
- -- piece of Haskell code for to demonstrate its simplicity!
- -- First, we need Peano numbers so that we can count things.
- -- Always define your own, never trust the built-in integers!
- data Nat = Zero | Succ Nat
- deriving (Eq, Show)
- -- Now I will set the ground work for the rest of our program.
- -- This is a pretty obvious and self-explanatory data type.
- -- We will use it to create a stream of functors that ends in a Pure constructor.
- data Free
I like the other solutions, but they all require an operating system which is a bit of pain to install for something as simple as this.
I suggest:
section .text
global boot
bits 16
global sectors_to_load
boot:
xor bp, bp
mov ds, bp
mov ss, bp
mov bp, 0x7000
mov sp, bp ; better set up a stack for the function call
mov bx, smile ; load the address of our string
call bios_print_string
call bios_print_string
call bios_print_string
mov bx, new_line
call bios_print_string
call bios_print_string
mov bx, new_line
call bios_print
I don't see a Befunge solution yet, so here:
- v > v -1,k5<
- 4 :>#:"!elimS"^
- >1-:|^ _v
- ^ ,a@# $<
The function that prints "Smile!" is that little part in the upper-right-hand corner. I'm sure there's a more compact solution, but I don't think I hate myself as much as the guy who offered the Brainfuck solution. You can change the number of iterations by altering the 4 to something else, although if you want more than 15 iterations, you're going to have to do some Math.
*Edit* I realized it was printing "Smil!e"; I fixed it.
Brainfuck
Okay, this has no language specification? Then this is my submit:
- >+++++++++[<+++++++++>-]<++.>+++++[<+++++>-]<+.----.+++.-------.>++++++++[<-------->-]<----.>++++++
- +[<+++++++>-]<+.>+++++[<+++++>-]<+.----.+++.-------.>++++++++[<-------->-]<----.>+++++++[<+++++++>-
- ]<+.>+++++[<+++++>-]<+.----.+++.-------.>++++++++[<-------->-]<----.>++++[<------>-]<+.>++++++++[<+
- ++++++++>-]<+.>+++++[<+++++>-]<+.----.+++.-------.>++++++++[<-------->-]<----.>+++++++[<+++++++>-]<
- +.>+++++[<+++++>-]<+.----.+++.-------.>++++++++[<-------->-]<----.>++++[<------>-]<+.>++++++++[<+++
- ++++++>-]<+.>+++++[<+++++>-]<+.
Normally I don’t give answers to homework questions outright, but with such a tricky question as this, the least I can do is give you some pointers (preferably void*s) in the right direction. This exercise requires an extensive knowledge of x86 assembly and function pointers to solve correctly. As requested, there is a function that prints “Smile!” (no newline), which is called in such a way that the program’s output is:
Smile!Smile!Smile!
Smile!Smile!
Smile!
Extending this to work for additional lines is an exercise left to the reader.
- #include<stdio.h>
- #define while printf
- int doyourownhomework(){
Not sure if any solution in Whitespace has been posted. Anyway, here you have my go at this problem:
- begin
- end
Guaranteed to work with the Ruby interpreter from here. I’m not sure how strict the standard is implemented across interpreters and I didn’t check any other but the Ruby one.
For those still keen to understanding what’s inside, here’s the pseudocode outline (please ignore the row labels; they only ma
Kim Moser suggested:
Just write a program that outputs random sequences of letters and punctuation. If you let it run long enough, eventually it will output the desired sequence.
That sounds like a plan.
The C# System.Random.next() method will return a random number between 0 and 2,147,483,6467 (which is 2 to the power 31, minus one). The unicode value for the S is 83, so all we need to do is pick random numbers between 0 and 2.1 billion until 83 pops up, then move onto m…
It takes a few guesses to find the correct numbers, on testing between 77 billion and 107 billion numbers picked and discarded
Here is the answer in fish, please submit it as "I_Dont_care_about_the_class.fish", if the professor asks about where is the function, its on lines 7 and 8 but its not properly a function, as it always returns to (0,4), unfortunatly the fish documentation is off right now so I can't find the command for returning to an arbitraty location in the codebox
123>:?v~52*ol?v ;
1 ;
- ;
^ < ;
^ <;
>>0["Smile!"r>l?v]^;
^ o< ;
In JavaEE:
* Make a maven war project and add Hibernate, JaxB, deltaspike-data-JPA and RESTEasy as dependencies
* Make a simple entity "Message" containing a String atribute and "MessageList" One
* Annotate each class with @Entity @XmlRootElement
* Add an jaxb.index file on these classes package listing these two Entities
* Annotate your Attribute by @XmlElement @NotNull @Size(min=2, max=10)
* Make a MessageListDao interface annotted with DS @Repository @Path("/")
* Make a simple persistence.xml file mapping to your database
* Make an interface and a REST "MessageRESTService"
* Add a method to t
WAT?! U NO HAZ LOLCODE!?!?!?!?!?!
- HAI
- HOW DUZ I PRINTSMILE
- VISIBLE "SMILEZ!"!
- IF U SAY SO
- HOW DUZ I PRINTSMILEZ NUMBERZ
- I HAS A SMILEZLINE ITZ ""
- IM IN YR LOOP NERFIN YR NUMBERZ WHILE NUMBERZ BIGGR THAN 0
- SMILEZLINE R SMOOSH SMILEZLINE AN "SMILEZ!" MKAY
- IM OUTTA YR LOOP
- VISIBLE SMILEZLINE
- IF U SAY SO
- VISIBLE "O HAI! NOT MY WERK! LOL!:):)DIS WAY CUZ I LIEK SMOOSH:)"
- I HAS A COUNTER ITZ 3
- IM IN YR LOOP NERFIN YR COUNTER WHILE COUNTER BIGGR THAN 0
- PRINTSMILEZ COUNTER
- IM OUTTA YR LOOP
- VISIBLE ":)N DIS WAY CUZ QU
I'll have a go, although I can bet that your teacher doesn't expect to see a SQL solution..
just replace the "TOP 3" with your desired count :)
- CREATE FUNCTION dbo.NOT_MY_HOMEWORK(@HOW_MANY INT)
- RETURNS VARCHAR(2000)
- AS
- BEGIN
- DECLARE @COUNT INT = 0
- DECLARE @FROWNEDUPON VARCHAR(2000) = ''
- WHILE (@COUNT < @HOW_MANY)
- BEGIN
- SET @COUNT = @COUNT + 1
- SET @FROWNEDUPON = @FROWNEDUPON + 'Smile!'
- END
- RETURN @FROWNEDUPON
- END
- GO
- SET NOCOUNT ON;
- DECLARE @IMSOOOLAZY VARCHAR(2000)
- SELECT TOP 3
- N = IDENTITY(INT, 1, 1)
- INTO #TMP_NUMBERS
- FROM
- master.dbo.syscolumns a
All the solutions I’ve seen so far are unsatisfactory in that they take no advantage of the advances in the hottest field in Computer Science: Machine Learning. But this is your lucky day, and courtesy of Google’s release of the TensorFlow Open Source Library for Machine Intelligence, I am able to remedy this problem, but providing a truly intelligent (artificially!) solution:
- #!/usr/bin/env python3
- import tensorflow as tf
- sess = tf.InteractiveSession()
- n = 3
- # input will be a matrix containing elements 1 ... n^2
- inp = tf.reshape(tf.linspace(1.0, n*n, n*n), [n, n])
- # Generate a matrix with rows 1..n
- r
Got it, use the function as often as needed. What about a C++ version, I did full unit test and coverage test, also make it ran for 2000 times to prove the correctness from 1 line to 2000 lines. No error till now, it is very robust. Also, it crosses platforms, you can compile and run it on Unix/Linux, Windows, or MacOS. Your professor will be satisfied. Absolutely! And you are welcome!
- #include <iostream>
- void SomeoneElseWriteFunctionForMe(int depth)
- {
- if (depth > 0)
- {
- if (depth % 2 == 1)
- {
- SomeoneElseWriteFunctionForMe(-depth);
- }
- else
- {
How about some MEL?
[code]
proc iwannamakeprettypicturesnothomeworkyo(int $num)
{
for($i = 0; $i < $num; ++$i)
{
global int $mvy = 0;
textCurves -ch 0 -f "Party LET Italic" -t "Smile!";//creates text curves
xform -translation (5*$i) 0 0;
move -y $mvy;
planarSrf -ch 1 -d 3 -ko 0 -tol 0.01 -rn 0 -po 1 `ls -sl -l`;//planar geometry from curves
polyExtrudeFacet -con
Almost everybody seems to assume that the teatcher wants the smiles per lines to "count down" from three per line... but the wording "have the program use the function as often as needed" could indicate that the solution should scale.
So I have assumed that the goal is to end up with one line with one "smile!", preceded by longer lines, each one smile shorter than the previous line. Except the very first line, which may not be quite long enough, depending on the total number of smiles. Anyway, I really think that is what the teacher really wants in his heart of hearts!
BESIDES! The assignment cl
EDIT: Indicate the function to print 'Smile!'
In the Bourne Shell (ash or bash). The print function is 's' or 'd0 that'. With recursion:
- #! /bin/sh
- e(){ echo -n $1 ;};s(){ e S; e m;e i;e l;e e;e '!';};
- cd(){ if [ -n "$1" ];then shift;s;cd "$@" ; else echo "";fi;}
- d0(){ if [ -n "$1" ];then cd "$@";shift;d0 "$@";fi;}
- d0 your own homework
And in ANSI C (with recursion and abuse of the C pre-processor), same algorithm. The print function is 'e(S)' or 'do({"that", 0})'
- #include <unistd.h>
- #define T C Z
- #define X Z V
- #define R char
- #define V void
- #define C const
- #define U return
- #define Z static
- #define do d
- T R S[]
This outputs the smiles you requested
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- #pragma pack( push, 1)
- typedef struct fileHeader_
- {
- short Type;
- long Size;
- long Reserved;
- long Offset;
- } bmpFileHeader;
- typedef struct infoHeader_
- {
- long biSize;
- long biWidth;
- long biHeight;
- short biPlanes;
- short biBitCount;
- long biCompression;
- long biSizeImage;
- long biXPelsPerMeter;
- long biYPelsPerMeter;
- long biClrUsed;
- long biClrImportant;
- } infoHeader;
- #pragma pack( pop )
- char* g_buffer = NULL;
- int g_width = 0;
- int g_height = 0;
- int g_stride = 0;
- int g_bufferSize = 0;
- bmp
no need to loop or do anything complicated - since you're asking..
- print("Smile!Smile!Smile!\n");
- print("Smile!Smile!\n");
- print("Smile!\n")
I won’t do your homework for you. I will say this, though:
- Array indices start at 0 in C, not 1.
- You do not need to store the entire array of inputs to remember the min, max, and average values.
- If the
av_countoutput isn’t needed, you can dispense with arrays. - Consider how to calculate everything other than
av_countwithout requiring an array or second loop (including the indicesmin_pandmax_p). - If you do need to compute
av_count, you will need an array to remember all of the input values. - Your current code allocates it as a VLA; however, I would recommend against that.
- Learn about
malloc,calloc,
Here is the solution in the most glorious of all programming languages, TrumpScript:
- make democrats 1000000
- make republicans 1000001
- make America 1000003
- make terrorists "Smile!"
- make government ,republicans - democrats;
- make world ,America - democrats;
- make president ,America - America;
- make Trump president
- as long as ,Trump < world;:
- make Trump president
- tell ,world about * terrorists;
- make world ,world - government;
- Trump should be our only leader!
- America is great.
Though you must use functions, you actually don’t need them, you don’t need functions in TrumpScript. This is the best answer