• Breaking News

    Saturday, February 3, 2018

    Sort Ask Programming

    Sort Ask Programming


    Sort

    Posted: 03 Feb 2018 09:28 PM PST

    Sorting interactive problem from atcoder

    The problem :: There are N balls labeled with the first N uppercase letters. The balls have pairwise distinct weights.

    You are allowed to ask at most Q queries. In each query, you can compare the weights of two balls (see Input/Output section for details).

    Sort the balls in the ascending order of their weights.

    Explanation of the problem: Given the value of N where N ranges from [1,26] and Q where Q is the maximum number of queries that one can make, sort a list of distinct uppercase alphabets in ascending order. N indicates that there are N characters starting from 'A'. Hence, N = 5 means that our final list must contain 'A', 'B', 'C', 'D' and 'E'.

    A single query is defined as printing out a string "? x y" where x and y represent the characters we want to check the relation between (e.g. "? A B"). The problem restricts the number of such queries to Q. Hence, we must determine the final order of the characters using at most Q queries.

    For each query, we get a binary answer '<' or '>' from stdin. '<' indicates that x comes before y in the final list. '>' means otherwise.

    Input example : N Q -> 3 10 (N is the total balls, Q is the query that we can ask about the relation of the ball) Output :? AB Input: > (means that B is bigger than A) Output :? CB Input : > (answer from stdin) Output: ?AC Input :< (means A is bigger than C) Output :!BAC (sorting in ascending)

    Constraints (N,Q)=(26,1000), (26,100), or (5,7).


    First im not quite sure how can i code "? x y"? Im picturing there will be array with For N ball.

    For example "ABC" but how can i code to ask randomly for query? Such as "?AB " then " ?CB " then " ?AC " from array ? Since there is constraint for Q(query) i mean how can i code something that only give output " ?AB" ," ?CB", "?AC " and not giving output such as ?BA ?BC ?CA (the reversed and repetition one)

    And also i am very very beginner havent learn anything abt merge sort etc and sort algorithm, is this knowledge require to code this problem? please give me hint how can i approach this problem?

    #include <cstdio> #include <string> using namespace std; int main(void){ int N,Q,i,j; scanf("%d%d", &N, &Q); string s; for(i=0;i<N;i++) s += (char)('A' + i); for(i=0;i<N;i++) for(j=0;j<N-1;j++){ printf("? %c %c\n", s[j], s[j+1]); fflush(stdout); char ans; scanf(" %c", &ans); if(ans == '>') swap(s[j], s[j+1]); } printf("! %s\n", s.c_str()); fflush(stdout); return 0; } 

    this is sample of the code that is seem accepted for the first case (26,1000), but i was confuse as there is no Q in this code? because when i tried to debug the code, it ask questions with total bigger than Q(constraint) ...

    my attempt using c but WA, i tried using bubble sort... but i know this completely wrong, thats all i know for algorithm..

    #include <stdio.h> #include <stdlib.h> int main() { int N, Q; scanf("%d %d", &N, &Q); char *s; s = calloc(N,sizeof(char)); int i; for (i=0; i<N; i++) { s[i] = (char)('A' + i); } s[N] = '\0'; char ans; char tmp; int j; int count = 0; for (i= 1; i < N; i++) { for (j = 0; j < N-i; j++) { printf("? %c %c\n", s[j], s[j+1]); fflush(stdout); scanf(" %c", &ans); if (ans == '>') { tmp = s[j+1]; s[j+1] = s[j]; s[j] = tmp; } count++; if (count > Q) break; } } setbuf(stdout, NULL); int b = strlen(s); printf("!"); for (i = 0; i <= b - 1; i++) { printf("%c", s[i]); fflush(stdout); } return 0; } 
    submitted by /u/Devinamuljono
    [link] [comments]

    Write an assignment statement that computes the remainder of the variable time when divided by 60 and stored in the variable minutes. (Assume all are of type int.)

    Posted: 03 Feb 2018 08:50 PM PST

    minutes = time / 60; IS THIS CORRECT?

    submitted by /u/unknownplayer44
    [link] [comments]

    [Java] Advice on Game of 15 Question

    Posted: 03 Feb 2018 08:47 PM PST

    Hey all,

    I am working on a problem and not sure how to go about it. We are writing two aspects of a program - a human part and a computer portion. The program works with a 4x4 2D array with numbers 1-15, and one blank spot.

    I completed the human portion, but I'm confused about how to approach the computer portion. First, I have to solve a relaxed version, in which I just have to way in which the program prints out how to get the blank square in the bottom right part of the arrow.

    The Game of 15 does not have to be solved, but I have to print out the way in which it would get the blank square to the bottom right (the star represents the blank spot). So for instance, if the array was like this:

    1 2 3 4

    5 * 6 7

    8 9 10 11

    12 13 14 15

    The program would print 'up, up, left, left' to get the blank square on the bottom right. I was given a method that gives me the point of the array in which it is blank. Thank you so much for any help!

    submitted by /u/50mac50
    [link] [comments]

    Could use some insight on these wrong problems.

    Posted: 03 Feb 2018 08:24 PM PST

    Which of the following is a literal? a. int b. main c. + d. 77 f. salary Me and my friends all agreed on int, but it keeps saying it is wrong.

    submitted by /u/unknownplayer44
    [link] [comments]

    Error when printing with printf in Java

    Posted: 03 Feb 2018 07:45 PM PST

    My code:

    public class Testing { public static void main(String args[]){ float total = 1853/5; double GradeAPlus = 2078.405 - total; System.out.printf("%.2f", GradeAPlus); } } 

    I'm trying to print the output with no decimal places after the number, but I'm getting an error when trying to print.

    submitted by /u/YasuoMainBTW
    [link] [comments]

    [C] Need help understanding how to solve a problem using qsort

    Posted: 03 Feb 2018 07:04 PM PST

    So this is for an assignment; the task was to ask the user a word and then find it within directories and captilize it. That part I have figured out.

    Then the program is supposed to give you a report BUT it needs to be sorted by most updated file first. Which as you can see is not what I have done:

    Please enter the word you want to replace: no Please enter the starting directory ('.' being the root i.e. "./folder"): ./test ------- Search Report -------- Updates Directory 1 ./test/New Text Document - Copy (2).txt 1 ./test/New Text Document - Copy.txt 0 ./test/New Text Document.txt 1 ./test/sub1/sub1 New Text Document - Copy.txt 0 ./test/sub1/sub1 Text Document.txt 1 ./test/sub1/sub3/sub3 New Text Document awkdjalksdjalksdjalksjdalksdjalksdjalksd.txt 3 ./test/sub2/sub2 New Text Document.txt 

    I did it by creating a counter variable and adding 1 to it whenever the word gets replaced and simply printing the path and counter as the program goes folder-by-folder.

    But it needs to be sorted; using qsort. So I believe I'll have to create an array first and then use qsort but I do not understand how to do that. What will the array hold? The path or the counter? Because I don't believe it can hold both. Also the part that does the sorting needs to be on a different .c file if that matters.

    Any help would be appreciated! Thank you!

    submitted by /u/notyourdaddy
    [link] [comments]

    Csharp Problems From a Beginner, Can you help?

    Posted: 03 Feb 2018 06:18 PM PST

    I've been coding for less than a week now, im working to making a block move...the code (from visual studio) is being rejected from an unexpected "{" when it is seen to work by others. here's from the code:
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour {

    public Rigidbody rb; public float forwardForce = 2000f; public float sidewaysForce = 500f; // Update is called once per frame void FixedUpdate () { rb.AddForce (0, 0, forwardForce * Time.deltaTime); If ( Input.GetKey("d")) { rb.AddForce ( sidewaysForce*Time.deltaTime, 0, 0 ); } } 

    }

    yes i am working with unity and would love some help, Thanks Guys! /r/FirstTime - SlowEngineering

    P.S. this is my first post so i'm sorry if i've done anything wrong

    submitted by /u/SlowEngineering
    [link] [comments]

    Recommend a book on Django?

    Posted: 03 Feb 2018 05:41 PM PST

    A year ago, I read "Getting MEAN With Mongo, Express, Angular, and Node" by Simon Holmes. This book went through the MEAN stack by creating an application from the UI all the way to user authentication. It really helped me learn MEAN because it allowed me to create something while understanding concepts.

    I'm now looking to learn Django. Is there a book that does something similar where it creates a simple web application using Django and explains things as you go along?

    submitted by /u/publicstaticvoid42
    [link] [comments]

    Best command line interface for C++ on windows?

    Posted: 03 Feb 2018 01:09 PM PST

    I'm pretty new to programming and im using cygwin with VS and I'm feeling kinda iffy about cygwin

    submitted by /u/euronforpresident
    [link] [comments]

    (Java) How to change global string value?

    Posted: 03 Feb 2018 04:52 PM PST

    Very noobish question and i cant google it.
    How to change global string value in class?

    class:

    public class NewClass {
    public static String str1 = "blabla");

    }

    Dialog:

    public class Dia extends javax.swing.JDialog {
    NewClass.str1 = "bleble";
    }

    Always gets me error that it cant find variable in class

    submitted by /u/Dzuzepipi
    [link] [comments]

    Need daily values for s&p 500

    Posted: 03 Feb 2018 03:02 PM PST

    I'm creating a csv of the daily open close and volume of all the stocks in the s&p 500. Currently I curl alphavantage for each and concatenate them. But there has to be a better way. I just need a way to get the data not necessarily a program.

    submitted by /u/ShipProtectMorty
    [link] [comments]

    In need of a database recommendation.

    Posted: 03 Feb 2018 10:28 AM PST

    I have 5TB of CSV files each containing lines like the following:

    company,title,location,name,count Oracle,Software Engineer,San Francisco,Bob,100 oracle,software engineer,san francisco,bob,100 oracle,,portland,bob,100 oracle,,Portland,bob,100 

    That's just an example. I need to be able to query this data like so:

    select * from table where company ilike 'oracle' order by count desc; select * from table where company ilike 'oracle' and title ilike 'software engineer' order by count desc; 

    In other words, show me all rows where company is Oracle (case insensitive), or show me all rows where company is Oracle (again case insensitive) and title is Software Engineer (also case insensitive).

    The data is not relational. Some of the data looks like this:

    disease1,disease2,count cancer,diabetes,5000 Cancer,Diabetes,50000 diabetes,cancer,5000 Diabetes,Cancer,50000 

    Again, I want all rows that match cancer (case insensitive), ordered by the count.

    I imported the data into a Postgres database using COPY, and that took about a day. I started creating indexes on the tables a couple of days ago, e.g.:

    CREATE INDEX disease_disease_trigram_idx ON disease_disease USING gin (disease1 gin_trgm_ops); 

    That table is ~115GB and the indexing has been running for over 24hours now. Considering I have 60 tables, some quite larger than this one, it's just not something I want to wait a month+ for. Just wondering, for this type of data, if there might be something better.

    submitted by /u/flippantantant
    [link] [comments]

    Have 2 great options, not sure which one to take..

    Posted: 03 Feb 2018 01:15 PM PST

    User Voting on Google Sheet

    Posted: 03 Feb 2018 11:59 AM PST

    Hello. Would it be possible to create something where users can vote (like reddit) on entries in a Google Sheet or database? I am using Wordpress to host it. I have very little programming knowledge. Thanky you.

    submitted by /u/King_Nidge
    [link] [comments]

    How to detect anomaly and recognize pattern using Markov Models

    Posted: 03 Feb 2018 10:57 AM PST

    I am using markov models for my project "Anomaly detection and Pattern Recognition using Markov Models". I need suggestions regarding language and packages which would suit my needs. I've started some work where I am building markovchains with sequential mood data. Right now I am working with R package "markovchain". Now I need to estimate future mood, identify a sequence of mood for someone.
    Can someone with experience with this help me.
    Thanks

    My Github Repo - https://github.com/sahilsharma011/prediction_anamoly_detection_cs_project

    submitted by /u/ss573
    [link] [comments]

    What to use for an application that needs: GUI and.EXE file? python/golang/javascript

    Posted: 03 Feb 2018 08:50 AM PST

    I have small application: 1. User input data into few input-boxes. 2. The application performs HTTP request with the given data. 3. The application generates files on disk based on HTTP response data.

    I have the whole thing (except GUI) already written in python and golang. I don't know javascript but for such a simple project i can learn some.

    I want to pack this into .exe with GUI. From my experience packing python project into .exe is not so simple and leads to problems. There is also a lot of GUI libraries, but they are aged and stable.

    With golang making, exe is really simple, but all GUI libraries that i found looks like in beta - testing.

    Now comes javascript with Electron, looks like the best approach for this but also approach i want to avoid at last.

    submitted by /u/bukens
    [link] [comments]

    Question about DB connection between mobile app and webpage

    Posted: 03 Feb 2018 08:32 AM PST

    I'm making a project that basically consists of an app that will be updating a DB and a webpage that will read the DB and present the data in graphics and some other things. The question is when the DB is updated by the app how can I notify the webpage? I thought of using a websockets server only to send an update notification to when the DB is updated, but I think it may be too overkill to use a websockets server only to notify changes. A friend suggested me to use MQTT I read a little about it and I like the fact that you can subscribe to topics but I don't know if there is a better tool to do what I want. I want to add that the webpage can also write to the DB and that I will have a lot of data in the DB.

    TL; DR: I'm doing a project where I need to connect a webpage and an app to a DB and I want them to know when the DB changes.

    Thanks to everyone I appreciate any response!

    submitted by /u/marcmadmax
    [link] [comments]

    Single Page Application on Angluar problem

    Posted: 03 Feb 2018 06:42 AM PST

    I'm currently making website in SPA architecture for my classes. I've encountered a problem. When I was coding routing I made html files with simple text just as a placeholder to check if routing works. Everyting worked fine. Now when I change something in my project (for eg. change text of heading) it doesn't change in browser. It looks like the browser have some kind of snapshot of my project in it. I tried deleting history cookies etc. and it worked, but is there any way around? I honestly don't feel like deleting history every time I want to run my project. tl;dr SPA website doesn't update to my project code

    submitted by /u/OwlyWood
    [link] [comments]

    Coding for primary school students

    Posted: 03 Feb 2018 12:43 AM PST

    Hi r/askProgramming,

    I am a primary school teacher and I currently have a few students in my class who enjoy using https://scratch.mit.edu/ to make games. I have one student in particular who has out grown scratch and would be quite capable of learning a language.

    I dont want to squander his ability and would love to point him to a language that he would be able to eventually use to build a game out of. What would be a good language and is there a great free online based program I can point him towards?

    I am hoping that he would be able to eventually take what I teach him now and use it during high school in unity. Any advice is great advice!!! Thank you

    submitted by /u/eeleyes
    [link] [comments]

    Store ENV variables on S3?

    Posted: 03 Feb 2018 05:46 AM PST

    I have these .env files that I use to configure a Rails app.

    The files are not versioned but I'm keen to encrypt them and push them them to Github with a tool like this: https://github.com/sobolevn/git-secret

    The things is that everyone tells not to push secrets to Github, so I was wondering what would be a good alternative.

    I thought about saving the files on a S3 bucket for instance and manage them somehow. Then pull them on the CI/CD process.

    I'm already using the aws cli in the process so it would be fairly easy to integrate.

    Given that we can secure the bucket and encrypt the files, do you see any downside of using S3 for this?

    submitted by /u/CodeMariachi
    [link] [comments]

    [EBNF Grammar] Correct order?

    Posted: 03 Feb 2018 05:33 AM PST

    Hello

    I'm currently doing more testing on my expression grammar in my parser to check if everything is alright, and I noticed this :

    2**(2**(-1**2)) 

    Evaluates to 4 with my current grammar, because it's derived like this:

    2**(2**((-1)**2)) -> 2**(2**1) -> 2**2 = 4 

    But, if I evaluate it in google, or in python I get 1.414... because they derive it like this :

     2**(2**(-(1**2))) 

    So, I think I should be in the wrong here, but is that it, or this expression is just really ambiguous by nature, and can be interpreted in 2 ways? My current grammar is this :

     <value> = <callable> | <const> | '(' <expr> ')' <prefix_expr> = <unary_operator> <prefix_expr> | <value> <cast_expr> = <prefix_expr> [<as_kw> <type>] // <as_kw> means "as". My current syntax for type casting is <expr> as <type> <expr> = <cast_expr> { <binary_operator> <cast_expr> } 

    I think that to get the "correct" result in that specific case I should change it to

     <value> = <callable> | <const> | '(' <expr> ')' <cast_expr> = <value> [<as_kw> <type>] <binary_expr> = <cast_expr> { <binary_operator> <cast_expr> } <expr> = <unary_operator> <expr> | <binary_expr> 

    But then other expressions will evaluate differently because unary operators will have precedence over everything. How can I fix this?

    EDIT: This post's accepted answer concludes that there is no general "correct" rule for this operation, and that brackets should always be used to get the desired result.*

    EDIT2: After looking at Python's grammar, I came up with this grammar, that solves the problem (I think?)

     <value> = <callable> | <const> | '(' <expr> ')' <cast_expr> = <value> [<as_kw> <type] <exp_expr> = <value> { ('*' '*') <prefix_exp> } <prefix_expr> = <unary_operator> <prefix_expr> | <exp_expr> <expr> = <prefix_expr> { <binary_operator> <prefix_expr> } 

    That leaves me with this order of operation:

    • cast expression
    • **
    • unary - ! +
    • * / %
    • + -
    • < > <= >=
    • == !=
    • &&
    • ||
    • =

    Which is, I think, correct ? It's nearly the same as C++'s order of precedence, (if you replace the scope resolution operator with the exponent operator) http://en.cppreference.com/w/cpp/language/operator_precedence

    Thanks a lot !

    submitted by /u/Kywim
    [link] [comments]

    No comments:

    Post a Comment