You think you can actually program? I can bet my fortune that none of you can actually solve a first year CS problem. Prove me wrong, faggots.
Given a list of integers and it's size, extract and return an array of uncommon digits, meaning digits that only occur in one integer, but NOT the rest. Return 0 if no uncommon digits are found. The returned array must be sorted with even uncommon digits first, then odd, from least to greatest.
Input: {32965, -275721, 3028063}
Output: {0, 8, 1, 7, 9}
Input: {32965, -275721, 3028063, 10789}
Output: 0
>>59318905
>You think you can actually program?
No i don't.
>Prove me wrong, faggots
Why? You're right.
http://stackoverflow.com/questions/33094887
>>59318905
Didn't read lmao suk a dik
Homework?
not doing your homework for you loser
basic histogram tho cmon man
>>59318905
I'm not doing your homework, it also seems very trivial to me.
>>59318962
>>59318965
>>59318961
Not homework, faggots. Already solved it. Yeah, I bet it's trivial because your brain probably can't program this. Scrub.
Kek. Naive implementation as follows:
Loop from 0 to 9.
Convert the integer in the loop to a character.
Loop through each character of each integer given. Compare the 0-9 character against them. Raise a counter if it's equal. If the counter is 1 at the end of the comparison, print out the variable. Reset the counter to 0 at the end of the comparison. Continue the loop.
this is pretty easy, i don't even go to uni and i can solve this. if this was your homework and you're asking for help in a subtle way, change degrees
>loop
>extract
>sort
>returnint* extract(int* arr, int size) {
int digitCount[10] = {0};
int uncommonCount = 0;
int* retAry = 0;
int** extracted;
int tmp;
int i, j;
extracted = (int**)malloc(size * sizeof(int*));
for (i = 0; i < size; i++) {
*(extracted + i) = (int*)calloc(10, sizeof(int));
}
for (i = 0; i < size; i++) {
tmp = *(arr + i) < 0 ? -(*(arr + i)) : *(arr + i);
do {
*(*(extracted + i) + tmp % 10) = 1;
tmp /= 10;
} while (tmp != 0);
}
for (i = 0; i < 10; i++) {
for (j = 0; j < size; j++) {
digitCount[i] += *(*(extracted + j) + i);
}
if (digitCount[i] == 1) {
uncommonCount++;
}
}
retAry = (int*)malloc((uncommonCount + 1) * sizeof(int));
*retAry = uncommonCount;
if (uncommonCount != 0) {
for (i = 0, j = 1; i < 10; i+=2) {
if (digitCount[i] == 1) {
*(retAry + j) = i;
j++;
}
}
for (i = 1; i < 10; i+=2) {
if (digitCount[i] == 1) {
*(retAry + j) = i;
j++;
}
}
}
for (i = 0; i < userSize; i++) {
free(*(extracted + i));
}
free(extracted);
return retAry;
}
99% sure this is inefficient as shit, but it's a bruteforce approach
I only use javascript. I do a real world stuff not your CS bullshit.
>>59319479
>javascript
>real world stuff
aka my brain is pea sized and i can't deal with logic
>>59318905
Do your own homework.
>>59318905
I ain't doing your homework
>>59319343
It's funny because I have a basic idea of how to do this in Java, but was trying to think of how to do it in C, but man does it look like shit in C.
>>59318905
Nice homework
>>59318979
Lol, yeah right. Sad you can't solve a cs1 problem.
>>59318905
>return 0 if no uncommon digits are found
>>59318905
what you're forgetting here sonny jim is that 'first year CS problems' don't count for shit in the real world, neither does 95% of the rest you 'learn' paying 100k a year for a piece of paper.
yes, I would like fries with that
#include <stdlib.h>
int *unique_digits(int *arr, size_t len)
{
if (!arr || !len)
return NULL;
size_t digits[10];
int *final = malloc(10*sizeof(int));
int x;
for (x = *arr; len > 0; x = *(++ar)) {
unsigned char tmp = x % 10;
if (tmp > 9)
return NULL /* should never happen */
digits[tmp]++
}
unsigned char i;
unsigned char j = 0;
for (i = 0; i < 9; ++i)
if (digits[i] == 1)
final[j++] = i;
return final;
}
I haven't tested this, so it might not work
>>59318905
>inconsistent return type
uhh no
>>59320186
I forgot, put
len--;
after line 13
>>59320186
>>59320227
Also line 9 should have ++arr instead of ++ar
Fuck phoneposting
>>59318905
> anon-kun please do me my homework problems. p-please?
> I'm choking on bbc
>>59318905
Yes i can.
No I'm not doing your homework
>>59318905
>You think you can actually program?
No lol
I dropped out of computer engineering in the first year cause I was too lazy for all the maths and shit, I'm only here to look at pics of fancy or funny electronics and read brand war threads
>>59318905
>tfw had to read the problem 20 times and visit the stackoverflow link to even understand when the problem was asking
NEETdom hasn't been kind to me
>>59318905
Why -2 is not in ouput?
>>59320186
Nice try. But OP is for unique digits per integer.
>>59321992
He just has to add another loop like this:
unsigned char tmp;
for (; len >= 0; len--)
{
tmp=arr[len];
while( tmp >9 )
{
digits[tmp%10]++;
tmp/=10;
}
}
>>59318905
>tell people on 4chan they can't do something
>watch them do your work for you
>>59322146
missed last value, should be
unsigned char tmp;
for (; len >= 0; len--)
{
tmp=arr[len];
while( tmp >9 )
{
digits[tmp%10]++;
tmp/=10;
}
digits[tmp]++;
}
>>59322183
This.
>>59318905
Not OP and not asking for the solution, but is there a better way of separating the digits of the number other than bitshift and subtraction?
>>59322250
It's basic 4chan posting 101, don't ask a question, just assert the answer and see if you're called an idiot
>>59322296
modulo and integer division, duh
>>59318905
>he didn't say anything about performance
I could do it, but I doubt it'd be "elegant".
>>59322346
modulo and division are very expensive tho
>>59322183
This is true for basically any programming community. Some are insecure when it comes to coding or their own abilities, and to absolutely make sure they didn't turn into an idiot overnight, they will take the time to solve the most mundane problems.
Make any thread about fizzbuzz on any platform and prepare to have dozens of implementations in the comments
>>59322427
Do your bit level hacking if you're a speed freak then.
>>59322427
Division by a constant can be done by multiplying by the reciprocal and a shift/add fixup.
>>59318905
>The returned array must be sorted with even uncommon digits first, then odd, from least to greatest.
Why
>>59318905
How can you bet a fortune on something this simple.
Are you 5?
>>59322500
Just asking
considering it's homework they're usually pretty anal about this shit, and if I learned nothing in my last year it's that multiplication and especially division is some bullshit
>>59318905
>Return 0 if no uncommon digits are found.
So how do you distinguish for the case where 0 could be the only uncommon digit?
>>59322595
honestly, this. Much better to throw some sort of UniqueNumberNotFound exception or something of the like
>>59322595
>So how do you distinguish for the case where 0 could be the only uncommon digit?
You don't. It's not a real problem, it's OP's homework, and he's going to lose points if he doesn't add enough comments.
>>59322296
Bitshift is the cheapest.
Modulo is implemented as division which is multiple subtractions while bitshift is just a single operation.
>>59322595
Return 0 instead of [0]
>>59322631
Those are the same thing though
>>59322626
Sure, but in this case I imagine bitshifting to take require a few more operations and I'm wondering if overall the speed of shifting is outweighed by the extra steps the algorithm needs to take...
>>59322655
>using type-juggling """equality"""
>ever
>>59321948
This is what I was wondering about. Is it implying that only the absolute values should be considered?
>>59322766
-2 is not a digit retard
>>59322775
So then the assumption is the absolute value.
>>59322799
no, the assumption is it's a digit
>>59320862
its a bullshit contrived problem thats why
good luck failing 1st year OP
>>59318905int digit_in_number(int v, int dig)
{
for (v = abs(v); v > 0; v /= 10)
if (v%10 == dig)
return 1;
return 0;
}
int count(int *p, int n, int dig)
{
int i, j;
j = 0;
for (i = 0; i < n; i++)
if (digit_in_number(p[i], dig))
j++;
return j;
}
int filter_uncommon(int *to, int *from, int n)
{
int dig[] = { 0, 2, 4, 8, 1, 3, 5, 7, 9 };
int i, j;
j = 0;
for (i = 0; i < sizeof dig / sizeof *dig; i++)
if (count(from, n, dig[i]) == 1)
to[j++] = dig[i];
return j;
}
lemme know when you're ready to pay me, & I'll provide ya with the rest of the program
[email protected]
>>59322907
This code is garbage
>>59319343
OP here, thanks fucker
function uD(a) {
var count = Array(10).fill(0);
var units;
for (var i = 0; i < a.length; i++) {
var temp = Array(10).fill(0);
a[i] = Math.abs(a[i]);
while (a[i] >= 1) {
units = a[i] % 10;
if (temp[units] == 0) {
count[units] ++;
temp[units] ++;
}
a[i] = Math.floor(a[i] / 10);
}
}
var res = [];
for (var i = 0; i < 10; i += 2) {
if (count[i] == 1) res.push(i);
}
for (var i = 1; i < 10; i += 2) {
if (count[i] == 1) res.push(i);
}
return (res.length == 0) ? 0 : res;
}
Python monkey reporting in.def ops_homework(num_list):
freq = [d for s in [set(str(n)) for n in num_list] for d in s]
result = [d for d in range(0, 10) if freq.count(str(d)) == 1]
result.sort(key=lambda x: (x % 2, x))
return result or 0
>>59319343
>**
what in the world?
>>59323158
C has syntactical sugar for arrays, I don't know why he's trying to make it illegible.
>>59318905
43, nigger!
>>59318905
>braces to denote arrays
>>59318905
You think you can actually program? I bet you can't explain why you have used negative numbers in your question. Prove me wrong, faggot.
Protip: you can't
import string
args = [32965, -275721, 3028063]
unique = []
index = 0
for x in xrange(len(args)):
digits = list(str(args[x]))
todo = args[:]
todo.pop(x)
for num in todo:
for foo in str(num):
while foo in digits:
digits.remove(foo)
unique.extend(digits)
unique = list(set(unique))
unique = [x for x in unique if x in string.digits]
unique = [int(x) for x in unique]
output = ([x for x in unique if not bool(int(x) & 1)])
output += ([x for x in unique if bool(int(x) & 1)])
print output
>>59323157
This is better though.
>>59323158
int* v = int[ ] -> pointer at an array of int
int** v = int[ ][ ] -> pointer at an array of int* = pointer to an array of int arrays
>>59318905
Not the most concise solution, but probably the most obvious:#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int *uncommon_digits(size_t n, const int arr[static n], size_t *num_ret)
{
int digits[10] = {0};
for (size_t i = 0; i < n; ++i) {
bool taken[10] = {0};
for (int num = arr[i]; num != 0; num /= 10) {
int j = abs(num % 10);
if (!taken[j]) {
++digits[j];
taken[j] = true;
}
}
}
size_t total = 0;
for (size_t i = 0; i < 10; ++i)
if (digits[i] == 1)
++total;
if (total == 0) {
total = 1;
digits[0] = 1;
}
int *ret = malloc(sizeof *ret * total);
if (!ret)
return NULL;
size_t i = 0;
for (size_t j = 0; j < 10; j += 2)
if (digits[j] == 1)
ret[i++] = j;
for (size_t j = 1; j < 10; j += 2)
if (digits[j] == 1)
ret[i++] = j;
*num_ret = total;
return ret;
}
int main()
{
size_t n;
int *ret = uncommon_digits(3, (int[]){32965, -275721, 3028063}, &n);
for (size_t i = 0; i < n; ++i)
printf("%d\n", ret[i]);
free(ret);
putchar('\n');
ret = uncommon_digits(4, (int[]){32965, -275721, 3028063, 10789}, &n);
for (size_t i = 0; i < n; ++i)
printf("%d\n", ret[i]);
free(ret);
}
>>59323500
[...] = pointer to an array of pointers that points to array of int's
>>59323500
>pointer to an array of int arrays
This can be misleading.
It's possible for the pointers to be null or point to array of different sizes.
I love computers but code scares me. I have mad respect for programmers. I think I'm a pretty logical guy, and I look at this stuff and I couldn't even think where to begin. Its like hieroglyphics to me.
Returns an empty vec instead of 0 if no unique digits are found.#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdexcept>
#include <vector>
std::vector<int> get_digits(int n)
{
std::vector<int> ret;
n = std::abs(n);
while (n > 0) {
ret.push_back(n % 10);
n /= 10;
}
std::sort(ret.begin(), ret.end());
auto e = std::unique(ret.begin(), ret.end());
ret.erase(e, ret.end());
return ret;
}
std::vector<int> uncommon_digits(std::vector<int> vec)
{
std::vector<int> ret = { };
if (vec.empty()) return ret;
std::map<int, int> digit_map;
for (int n : vec) {
auto digits = get_digits(n);
for (int d : digits)
digit_map[d]++;
}
for (unsigned i = 0; i <= 9; i++) {
try {
if (digit_map.at(i) == 1) ret.push_back(i);
}
catch (std::out_of_range) { }
}
std::sort(ret.begin(), ret.end(),
[](const int &lhs, const int &rhs) {
if (lhs % 2 < rhs % 2) return true;
else if (lhs % 2 > rhs % 2) return false;
else return lhs < rhs;
});
return ret;
}
int main(int argc, char *argv[])
{
auto first_actual = uncommon_digits({ 32965, -275721, 3028063 });
std::cout << "{ ";
for (auto it = first_actual.begin(); it != first_actual.end(); it++) {
std::cout << *it;
if (it != first_actual.end() - 1) std::cout << ", ";
else std::cout << " }\n";
}
auto second_actual = uncommon_digits({ 32965, -275721, 3028063, 10789 });
if (second_actual.empty()) std::cout << "Empty vec\n";
return 0;
}
>>59323870
Which solution is yours?
>>59323890
This one: >>59323678
>>59323789
You never tried, it's not nearly as complicated as you think. You'd think the same thing looking at this message if you hadn't seen any writing in your life.
If anything, code is simpler than written language because there are no exceptions or irregularities. If something means one thing, it will always mean it (within that specific language, of course). English pronunciation is a complete illogical mess and is barely conveyed through writing, and is the bane of many asian learners.
>>59323691
>>59323765
You're right, tried to keep it simple but might cause problems in understanding.
also might add a int[][] is in memory just the same continous chunk of memory as int[] - you just let the compiler map 2 dimension to one while with an array of int* pointers the pointers can point anywhere, if they are used as different arrays they will likely be all over the memory space wich dampens performance
>>59318905
>Return 0 if no uncommon digits are found.
So I return the same whether 0 is the only uncommon and none is uncommon?
>>59323905
What objections do you have to it?
>>59324136
It's disgusting.
>>59318905
If I say that I can't do it you'll use it to say I'm not a "real" programmer
Obligatory Java solution.import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
String[] arr = sc.nextLine().split(", ");
String unique = "";
// iterate through all array items
for (int i = 0; i < arr.length; i++) {
// iterate through each character in the number
for (int j = 0; j < arr[i].length(); j++) {
String num = arr[i].charAt(j) + "";
if (isInt(num) && !inOtherInts(arr, num, i) && !unique.contains(num)) {
unique += num + ",";
}
}
}
ArrayList<Integer> outArray = sort(strToIntArr(unique));
for (int i : outArray) {
System.out.print(i + " ");
}
System.out.println();
}
}
public static int[] strToIntArr(String input) {
if (input.length() == 0) {
return new int[]{0};
}
String[] arr = input.split(",");
int[] out = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
out[i] = Integer.parseInt(arr[i]);
}
return out;
}
public static boolean inOtherInts(String[] arr, String target, int pos) {
for (int i = 0; i < arr.length; i++) {
if (i != pos && arr[i].contains(target)) {
return true;
}
}
return false;
}
public static ArrayList<Integer> sort(int[] arr) {
ArrayList<Integer> evens = new ArrayList<Integer>();
ArrayList<Integer> odds = new ArrayList<Integer>();
for (int i : arr) {
if (i % 2 == 0) {
evens.add(i);
} else {
odds.add(i);
}
}
Collections.sort(evens);
Collections.sort(odds);
ArrayList<Integer> out = new ArrayList<Integer>();
out.addAll(evens);
out.addAll(odds);
return out;
}
public static boolean isInt(String str) {
try {
Integer.parseInt(str);
} catch (NumberFormatException e) {
return false;
}
return true;
}
}
is my python script passable?from collections import Counter
i1 = [32965, -275721, 3028063]
i2 = [32965, -275721, 3028063, 10789]
def fc(input):
tc = []
for i in input:
for c in list(set((str(i)))):
if c != '-':
tc.append(int(c))
counted = Counter(tc)
a1 = []
a2 = []
for i in counted.most_common():
if i[1] == 1:
if i[0] % 2 == 0:
a1.append(i[0])
else:
a2.append(i[0])
final = sorted(a1)+sorted(a2)
return final if final else 0
if __name__ == '__main__':
print fc(i1)
print fc(i2)
break ints into strings, iterate through dropping each in a set. FIsh out your evens %2=0, sort and concat your even and odd arrays. *yawn*
>>59322992
everything is garbage to you ... you're on the same level as bacteria and fungus.
How did you guys learn to program? I want to know how everyone of you started or if you went to college and took classes
>>59318905
You're right, I'm no good at whiteboard wanking, but if you want a polished end-user application I'm your man.
CS fundamentals are a important… to a point. There's a threshold where if you don't have practical engineering experience, you're basically useless and will have a hard time getting a job. I've seen Stanford and MIT CS graduates that could talk theory all day long but couldn't program their way out of a paper bag (or, alternatively, grossly overengineered things which have had sane solutions for decades).
– Signed, a programmer making $140k w/two years of professional experience
+ ~5 years of tinkering on personal projects, no degree, and no crippling school debt
from sets import Set
inputs = [
[32965, -275721, 3028063],
[32965, -275721, 3028063, 10789]]
def g_is_gay(arr):
result = 0
##
# Selection
uniques = []
for index, number in enumerate(arr):
index_uniques = Set()
for n in str(abs(number)):
index_uniques.add(n)
# Check the other numbers in the list
for index_unique in index_uniques:
found = False
for i, n in enumerate(arr):
# Not self
if index != i:
if index_unique in str(n):
found = True
if not found:
uniques.append(index_unique)
##
# Presentation
evens = []
odds = []
for unique in sorted(uniques):
if int(unique) % 2 == 0:
evens.append(unique)
else:
odds.append(unique)
concat = evens+odds
if len(concat) != 0:
result = concat
return result
for input in inputs:
print(g_is_gay(input))
>>59323678
does array[x] ={0} flip all values to 0 now? When did this change, can I stop using memset?
>>59319343
casting malloc? What is this c++?
>>59319343tmp = *(arr + i) < 0 ? -(*(arr + i)) : *(arr + i);
man... are you for real? Please tell me you are just fucking with the kid and you don't submit code like this.
>>59318905
This would be really easy to solve in python.
Can anyone tell me why this prints out that ascii picture?echo "I<RA('1E<W3t`rYWdl&r()(Y29j&r{,3Rl7Ig}&r{,T31wo});r`26<F]F;==" | uudecode
>>59328270
uudecode can be used to encode or decode binary files as ASCII strings. When you give it no arguments it poops out your piped string after decoding it.
So someone encodes the ascii picture with uudecode, then does echo "<encoded_string>" and pipes it to uudecode which decodes the original ascii picture and poops it out on your terminal.
>>59318905
Do you have a fence I can paint too you fucking retard?
>>59318979
you fell for the uni meme? you know you can get a job in this field without a degree, right?
>>59327273
Step 1. Grab yourself by the shoulders
Step 2. Pull until your head is free from your ass
Step 3. ???
Step 4. Profit
>>59328270
why does this break my computer
>writing code in nano
lmao
>>59328565
all the functionality of notepad, all the usability of a terminal editor.
What more could you ask for?
>>59318905
man wordpress code is ugly
>>59319343
tfw you did his homework for him
>>59328579
A better text editor
>>59328579
vim with the nano interface would be a beast
>>59319801
Ayy I own that book
>>59328554
http://unix.stackexchange.com/questions/79684/fix-terminal-after-displaying-a-binary-file
https://www.cyberciti.biz/tips/bash-fix-the-display.html
>>59320126
>100k a year
Man you got ripped, no wonder you're salty
>>59328683
i had to power off
entire thing just froze
>>59328711
It was a fork bomb, I tricked you good
>>59328783
i thought so
>>59328794
at least it wasn't an obfuscated rm /
>nano
>program
>mac#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[]){
unsigned int found = 0;
for(unsigned int i = 1; i < (unsigned int)argc; i++){
for(unsigned int j = 0; j < (unsigned int)argc; j++){
if(i != j && !strcmp(argv[i], argv[j])) goto SKIP;
}
found++;
printf("Value %s is unique\n", argv[i]);
SKIP:asm("nop");
}
printf("Found %u matches\n", found);
return found;
}
>>59327273
I read books
>>59328783
What, really? How does piping something to echo end up executing anything?
>>59328832
you might have as well
i'm an incompetent fuck and my mind is foggy
>>59323157
I've been staring at this for minutes and I can't figure out how it works.
>>59320126
>>59328042
t. Max 'i can't reverse a binary tree' Howell
>>59319343
>single function called extract
This is very shit design desu.
>>59328248
>When you don't read the post, the post.
array of size 10. for each integer, if int is negative, multiply by -1, get digits 1 by 1 by x % 10; then x /= 10. increment number (as index) in the array. when all integers have been done, go through array (always size 10 therefore O(1)). Get array elements with count of 1.
O(m); m = complexity is number of digits in all the integers
Anyone who isn't a retard and has 30 minutes to learn how lists, loops and if works can do this.
>>59318905
So where is your fortune you fucking faggot? Oh wait you're a poor NEET who was looking for someone to do your homework for you, of course you don't have anything to bet. And the retards on this board fell for the bait anyway.
>>59322427
I don't give a fuck
>>59318905var input = [32965, -275721, 3028063];
var out = input.map((n)=>{
return Math.abs(n).toString().split('');
}).map(n=>{
return n.join(',')
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
}).join(',').split(',').sort((a,b)=>{
return a===b?a:0;
})
console.log(out);
AM I A BROGRAMMER NOW?
>>59323157
>freq = [d for s in [set(str(n)) for n in num_list] for d in s]
wat wat wat wat
>>59318905
-convert numbers to string, split them into separate lists
-check for dupes in the lists themselves, hard delete minus signs if they show up for whatever fucking reason
-check the lists against the other lists, adding ones that don't match any of the other lists' values to another list
-convert that list back to int
- % 2 = 0 then add to one list otherwise another
-sort()
-concat
done
you actually did his homework for him...
this is why everything sucks
<code>
'32965, -275721, 3028063'.split(', ').map((a) => a.split('')).map((a) => Array.from(new Set(a))).reduce((acc, val, idx) => {
val.forEach((v) => {
if (!acc.get(v)) {
acc.set(v, 1)
} else {
acc.set(v, acc.get(v) + 1)
}
})
return acc
}, new Map())
.forEach((k, v) => {
if (k === 1 && v !== '-') console.log(v)
})
</code>
>>59328447
>thinking the only valuable thing out of uni is the degree
lol
>homework threda
lmao
>Output: 0
That's not how you write the empty set. And don't give me that nullptr bullshit, an empty collection and a null reference are NOT the same thing.
Also, next time you want /g/ to do your homework for you just call it a "daily programmer challenge" and supply an anime girl image. You'll get results quicker.
>>59318905
>Given a list of integers and it's size, extract and return an array of uncommon digits, meaning digits that only occur in one integer, but NOT the rest. Return 0 if no uncommon digits are found. The returned array must be sorted with even uncommon digits first, then odd, from least to greatest.
I have no idea what you just said.
>>59328996
>>59330263
[set(str(n)) for n in num_list] creates a list of sets of unique digits in each number from num_list
[d for s in ... for d in s] iterates over each element of each set and creates a flat digit frequency list
>>59318905
Im not going to code this riiiihhnow because its before coffeee, but it look slike
i = [some bs list of integers, as input]
global vi
vi = [] #put your special nums here
while crunching != 0:
for x in i:
basically add an integer to x and then check to see if it is global vi
>>59318905
I am not doing your homework pleb
>>59318905
All of this is trivial except for getting the single digit out of the whole number. Why don't they just make that the question?
>return type depends on input
How about no.
>>59322467
>they're insecure!
Or maybe it's an interesting question and people want to do the exercise because exercises are fun?
I also want answers to >>59327273
I watched youtube videos when starting off with web dev
I've started learning c# (for web applications) with Microsoft Virtual Academy
>will I learn far too many things which are unnecessary in video tutorials?
My father told me to jump into an existing project on stack overflow and google something when I got stuck
Guile Scheme(import (srfi srfi-1) (srfi srfi-26))
(let* ((digits (map (compose string->list number->string abs) (read)))
(unique-digits (delete-duplicates (apply append digits)))
(count (compose length (cute filter identity <>))))
(display (filter (lambda (x) (= 1 (count (map (cute member x <>) digits))))
unique-digits)))
python2:from __future__ import print_function
integers = [32965, -275721, 3028063]
result = []
for idx in range(len(integers)):
tmp = integers[:]
del tmp[idx]
tmp = ''.join(map(str, tmp))
for integer in str(integers[idx]):
if integer == '-':
continue
if int(tmp.count(integer)) == 0:
if int(result.count(integer)) == 0:
result.append(integer)
result = map(int, result)
even = []
for i in result:
if i % 2 == 0:
even.append(i)
odd = []
for i in result:
if i % 2 != 0:
odd.append(i)
even.sort()
odd.sort()
result = even + odd
if result == []:
result = 0
print(result)
>>59331799
>[d for s in ... for d in s] iterates over each element of each set and creates a flat digit frequency list
how though? how are you using same set of variables on both sides of list comprehension.
'use strict';
const _ = require('lodash');
const uncommonDigits = (inArray = []) => {
const validDigits = '0123456789'.split('');
const digits = inArray
.map(d => d.toString().split(''))
.map(_.uniq)
.reduce((all, item) => all.concat(item), [])
.filter(i => _.includes(validDigits, i));
const counts = _.countBy(digits);
return Object.keys(counts)
.map(key => ({ key, val: counts[key]}))
.filter(i => i.val === 1)
.map(i => i.key);
}
const inputset1 = [32965, -275721, 3028063];
console.log(uncommonDigits(inputset1));
const inputset2 = [32965, -275721, 3028063, 10789];
console.log(uncommonDigits(inputset2));
def opIsAFag(intList):
digitCount = [0,0,0,0,0,0,0,0,0,0]
for i in xrange(10):
for number in map(str, intList):
digitCount[i] += number.count(str(i)) > 0
results = []
for d,i in enumerate(digitCount):
if i==1:
results += [d]
return results or 0
opIsAFag([32965, -275721, 3028063])
opIsAFag([32965, -275721, 3028063, 10789])
>convert to string
>compare it with numbers 0-9 with a counter for occuring more than once
there you go faggot i did your homework for you