Friday (CodeJam): Foregone Solution
codingcompetitions.withgoogle.com/...
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use Math::BigInt; chomp( my $cases = <> ); for my $case (1 .. $cases) { chomp( my $n = <> ); (my $i = $n) =~ tr/4/3/; my $j = 'Math::BigInt'->new($n) - 'Math::BigInt'->new($i); say "Case #$case: $i $j"; }
brute force for me so far.
const readline = require('readline'); function foregone() { let argumentsArray = [], answerArray = []; let linecounter = 0, tests; const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.on('line', (line) => { linecounter++; if(linecounter === 1) tests = line; else { argumentsArray.push(line); if(linecounter > tests) rl.close(); } }).on('close', () => { for(let i=0; i< argumentsArray.length; i++) { answerArray.push(noFours(argumentsArray[i])); } for(let i=0; i<answerArray.length; i++) { console.log(`Case #${i+1}: ${answerArray[i][0]} ${answerArray[i][1]}`) } process.exit(0); }); function noFours(num) { let a = num - 1, b = num - a; while(a.toString().indexOf('4') !== -1 || b.toString().indexOf('4') !== -1 && a >= b) { a--, b++; } if(a.toString().indexOf('4') === -1 && b.toString().indexOf('4') === -1) return [a, b]; else return undefined } }
n_cases = int(input()) for i in range(1, n_cases + 1): check_amount = int(input()) unfound = True fours = [int(i) for i in str(check_amount)] others = ["1" if n == 4 else "0" for n in fours] n = int(''.join(others)) print("Case #{}: {} {}".format(i, n, check_amount - n))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Friday (CodeJam): Foregone Solution
codingcompetitions.withgoogle.com/...
brute force for me so far.